Skip to content

Instantly share code, notes, and snippets.

View cpq's full-sized avatar
🎭
Купатися чи не купатись?

Sergey Lyubka cpq

🎭
Купатися чи не купатись?
View GitHub Profile
@cpq
cpq / rt1060.sh
Last active December 4, 2023 14:00
Flashing rt1060-evk via vcon SWD
#!/bin/bash
# SWD commands to call rt1060 flash boot rom functions
DEVCALL="curl -su :$VCON_API_KEY https://dash.vcon.io/api/v3/devices/13"
# SWD exec: se COMMANDS. Hex addresses are without leading 0x
se() { $DEVCALL/rpc/swd.exec -d "{\"req\": \"$*\"}" | jq -cr .resp ; }
rm() { se rm,$1 | cut -d, -f2 ; }
dump() { $DEVCALL/rpc/swd.read -d "{\"addr\":$1, \"size\": $2}" | jq -r .data | xxd -r -p | hexdump -C ; }
hex() { node -p "($*).toString(16)"; }
@cpq
cpq / stm32.md
Last active September 26, 2023 09:56
STM32 naming

STM32 naming scheme

Example MCU: STM32 H743ZI

Example Type Description
H Type F: mainstream, L: low power, H: high performance, W: wireless
7 Core 0: M0, 1: M3, 2: M3, 3: M4, 4: M4, 7: M7
23 Line speed, peripherals, silicon process, …
Z Pin count F: 20, G: 28, K: 32, T: 36, S: 44, C: 48, R: 64,66, V: 100, Z: 144, I: 176
// Copyright (c) Cesanta Software Limited
// All rights reserved
// SPDX-License-Identifier: MIT
// Usage example (Arduino):
// char buf[100];
// struct slip slip = {.buf = buf, .size = sizeof(buf) - 1};
// ...
// unsigned char c = Serial.read();
// size_t len = slip_recv(c, &slip);
@cpq
cpq / queue2.c
Created February 15, 2023 09:26
#include <sttdef.h>
// Single producer, single consumer non-blocking queue
//
// Producer:
// void *buf;
// while (mg_queue_space(q, &buf, len) == 0) WAIT(); // Wait for free space
// memcpy(buf, data, len); // Copy data to the queue
// mg_queue_add(q, len); // Advance q->head
//
@cpq
cpq / queue1.c
Created February 14, 2023 16:18
// Single producer, single consumer non-blocking queue
//
// Producer:
// void *buf;
// while (mg_queue_space(q, &buf, len) == 0) WAIT(); // Wait for free space
// memcpy(buf, data, len); // Copy data to the queue
// mg_queue_add(q, len); // Advance q->head
//
// Consumer:
// void *buf;
<!DOCTYPE html>
<html lang="en">
<head>
<title>modal</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.1.0/css/bootstrap.min.css" />
</head>
<body></body>
@cpq
cpq / ant1.ant
Created January 8, 2022 22:58
language yada yada
// Blink LED
2 = pin // pin = 2
0 = on // on = 0
pin 2 G // gpio.mode(pin, OUTPUT)
1000 { !on = on pin on W } T
'mqtt://broker.hivemq.com:1883' M = c
c 'elk/rx' {
'topic' $1 'message' $2 '{%Q:%Q, %Q:%Q}' c P // mqtt.publish
} S // mqtt.subscribe(c, topic, func)
@cpq
cpq / split.html
Last active November 20, 2021 17:28
HTML split pane layout example
<html>
<head>
<style>
* { box-sizing: border-box; }
body, html { padding: 0; margin: 0; }
.main { height: 100vh; }
.content { padding: 1em; }
.split { display: flex; flex-grow: 1; flex-shrink: 1; width: 100%; height: 100%; box-sizing: border-box; }
.split>* { flex-grow: 1; flex-shrink: 1; width: 100%; height: 100%; overflow: auto; -webkit-overflow-scrolling: touch; }
// This file contains two sketches for the end-user networking API that implements
// a simple WS service: WS message with JSON input {"pin": 12, "val": 0}, and JSON response {"status": true}
// WS handler, streaming API (think AVR)
// We don't buffer an incoming WS message. Instead, we feed
// TCP stack, and user handler, byte-by-byte.
// Some important values from the parsed HTTP header gets stored
// and passed to the user handler.
void ws_handler(struct conn *c, int event, size_t content_len, size_t receided_so_far, uint8_t byte) {
if (event == EVENT_INCOMING_BYTE) {
@cpq
cpq / cnip.h
Last active June 4, 2021 10:46
CNIP API suggestion
// The stack has two API: low level and high level
// Low level: used to hook it up to a hardware, to send/receive MAC frames
// High level: used to implement network apps, like HTTP/MQTT client/servers.
// Low level
// A device code does something like this:
//
// void cnip_mac_out(char *buf, size_t len) {
// bitbang_to_ethernet(buf, len); // Push outgoing frame to the network
// }