[{"data":1,"prerenderedAt":214},["ShallowReactive",2],{"example-page-fmradio":3},{"id":4,"info":5,"parts":6,"wired":31,"refs":32,"nets":33,"moreNets":207,"code":208},"fmradio","Small FM receiver: an STM32F411 (Cortex-M4, Zephyr firmware, source firmware\u002Ffmradio) controls the RDA5807M tuner module over I²C and shows frequency, RDS station name, program type, radio text, signal strength (dBµV + bar), stereo and volume on the ST7735 TFT. Button SW1 = seek down, SW2 = seek up, SW3 = quieter, SW4 = louder (hold to repeat). Five stations between 88.4 and 104.6 MHz with their own programs: classical, jazz, pop, news, rock. ▶ Sound plays headphones J1. Delete antenna ANT1 for 25 dB less reception; weak stations get noisy. The station list can be changed in a parameter of U2.",[7,10,13,16,19,21,23,25,27,29],[8,9],"capacitor",5,[11,12],"button",4,[14,15],"resistor",3,[17,18],"antenna_wire",1,[20,18],"headphone",[22,18],"ldo",[24,18],"liion_cell",[26,18],"rda5807m",[28,18],"st7735_tft",[30,18],"stm32f411",false,{"ANT1":17,"BT1":24,"C1":8,"C2":8,"C3":8,"C4":8,"C5":8,"DS1":28,"J1":20,"R3":14,"SW1":11,"SW2":11,"SW3":11,"SW4":11,"U1":30,"U2":26,"U4":22,"R1":14,"R2":14},[34,76,96,106,111,116,123,130,135,141,147,153,159,166,172,179,186,193,200],{"name":35,"pins":36},"0",[37,40,43,46,48,50,52,54,57,60,62,64,66,68,70,72,74],[38,39],"ANT1","Earth",[41,42],"BT1","−",[44,45],"C1","2",[47,45],"C2",[49,45],"C3",[51,45],"C4",[53,45],"C5",[55,56],"DS1","GND",[58,59],"J1","⏚",[61,45],"R3",[63,45],"SW1",[65,45],"SW2",[67,45],"SW3",[69,45],"SW4",[71,56],"U1",[73,56],"U2",[75,56],"U4",{"name":77,"pins":78},"3V3",[79,81,82,83,85,87,89,91,93,94],[47,80],"1",[49,80],[51,80],[55,84],"VCC",[55,86],"LED",[88,80],"R1",[90,80],"R2",[71,92],"VDD",[73,84],[75,95],"OUT",{"name":97,"pins":98},"VBAT",[99,101,102,104],[41,100],"+",[44,80],[75,103],"IN",[75,105],"EN",{"name":107,"pins":108},"VCAP1",[109,110],[53,80],[71,107],{"name":112,"pins":113},"ANT",[114,115],[38,112],[73,112],{"name":117,"pins":118},"AUD_L",[119,121],[58,120],"L",[73,122],"LOUT",{"name":124,"pins":125},"AUD_R",[126,128],[58,127],"R",[73,129],"ROUT",{"name":131,"pins":132},"BOOT0",[133,134],[61,80],[71,131],{"name":136,"pins":137},"BTN_SEEK_DN",[138,139],[63,80],[71,140],"PC0",{"name":142,"pins":143},"BTN_SEEK_UP",[144,145],[65,80],[71,146],"PC1",{"name":148,"pins":149},"BTN_VOL_DN",[150,151],[67,80],[71,152],"PC2",{"name":154,"pins":155},"BTN_VOL_UP",[156,157],[69,80],[71,158],"PC3",{"name":160,"pins":161},"MOSI",[162,164],[55,163],"SDA\u002FMOSI",[71,165],"PA7",{"name":167,"pins":168},"SCK",[169,170],[55,167],[71,171],"PA5",{"name":173,"pins":174},"SCL",[175,176,178],[90,45],[71,177],"PB8",[73,173],{"name":180,"pins":181},"SDA",[182,183,185],[88,45],[71,184],"PB9",[73,180],{"name":187,"pins":188},"TFT_CS",[189,191],[55,190],"CS",[71,192],"PB6",{"name":194,"pins":195},"TFT_DC",[196,198],[55,197],"DC",[71,199],"PA8",{"name":201,"pins":202},"TFT_RES",[203,205],[55,204],"RES",[71,206],"PA9",0,{"file":209,"lang":210,"text":211,"lines":212,"more":213},"src\u002Fmain.c","c","\u002F*\n * FM radio - Zephyr firmware for an STM32F411 + RDA5807M FM tuner + ST7735S TFT (Circuit Lab).\n * Board target nucleo_f411re (96 MHz Cortex-M4F).\n *\n * Hardware:\n *   ST7735S 128x160 TFT on SPI1: SCK PA5, MOSI PA7, CS PB6, D\u002FC PA8, RES PA9\n *   RDA5807M module (RRD-102) on I2C1 400 kHz: SCL PB8, SDA PB9 (4.7 k pull-ups)\n *   Buttons to GND (internal pull-ups): PC0 seek down, PC1 seek up, PC2 volume -, PC3 volume +\n *   Console: USART2 TX PA2\n *\n * The RDA5807M is driven through its sequential I2C interface (address 0x10): writes\n * start at register 02h, reads at 0Ah (status, RSSI, RDS blocks A..D).\n * Display: frequency, RDS station name (group 0A), programme type, radiotext (group 2A),\n * signal strength (RSSI dBuV + bars), stereo indicator and volume.\n *\u002F\n#include \u003Czephyr\u002Fkernel.h>\n#include \u003Czephyr\u002Fversion.h>\n#include \u003Czephyr\u002Fdrivers\u002Fgpio.h>\n#include \u003Czephyr\u002Fdrivers\u002Fspi.h>\n#include \u003Czephyr\u002Fdrivers\u002Fi2c.h>\n#include \u003Czephyr\u002Fsys\u002Fprintk.h>\n#include \u003Cstring.h>\n#include \u003Cstdio.h>\n#include \u003Cstdarg.h>\n\nextern const uint8_t font5x7[95][5];\n\n#define PIN_DC     8            \u002F* PA8 *\u002F\n#define PIN_RES    9            \u002F* PA9 *\u002F\n\nstatic const struct device *const gpioa = DEVICE_DT_GET(DT_NODELABEL(gpioa));\nstatic const struct device *const gpioc = DEVICE_DT_GET(DT_NODELABEL(gpioc));\nstatic const struct device *const spi = DEVICE_DT_GET(DT_NODELABEL(spi1));\nstatic const struct device *const i2c = DEVICE_DT_GET(DT_NODELABEL(i2c1));\nstatic const struct spi_config cfg = {\n\t.frequency = 6000000,\n\t.operation = SPI_OP_MODE_MASTER | SPI_TRANSFER_MSB | SPI_WORD_SET(8),\n\t.cs = { .gpio = { .port = DEVICE_DT_GET(DT_NODELABEL(gpiob)), .pin = 6, .dt_flags = GPIO_ACTIVE_LOW }, .delay = 0, .cs_is_gpio = true },\n};\n\n\u002F* ------------------------------------------------------------------ display *\u002F\n#define W 128\n#define H 160\n#define RGB(r, g, b) ((((r) & 0xF8) \u003C\u003C 8) | (((g) & 0xFC) \u003C\u003C 3) | ((b) >> 3))\n#define C_BLACK  0x0000\n#define C_WHITE  0xFFFF\n#define C_GREY   RGB(140, 140, 140)\n#define C_DKGREY RGB(50, 50, 50)\n#define C_BAR    RGB(20, 60, 160)\n#define C_BG     RGB(6, 10, 24)\n#define C_YELLOW RGB(255, 210, 0)\n#define C_GREEN  RGB(60, 230, 90)\n#define C_CYAN   RGB(90, 220, 255)\n#define C_RED    RGB(255, 70, 70)\n#define C_ORANGE RGB(255, 150, 40)\n\nstatic void spi_out(const uint8_t *b, size_t n)\n{\n\tconst struct spi_buf sb = {.buf = (void *)b, .len = n};\n\tconst struct spi_buf_set ss = {&sb, 1};\n\tspi_write(spi, &cfg, &ss);\n}\nstatic void cmd(uint8_t c, const uint8_t *p, size_t n)\n{\n\tgpio_pin_set_raw(gpioa, PIN_DC, 0);\n\tspi_out(&c, 1);\n\tif (n) { gpio_pin_set_raw(gpioa, PIN_DC, 1); spi_out(p, n); }\n}\nstatic void window(int x, int y, int w, int h)\n{\n\tuint8_t ca[4] = {0, x, 0, x + w - 1}, ra[4] = {0, y, 0, y + h - 1};\n\tcmd(0x2A, ca, 4);\n\tcmd(0x2B, ra, 4);\n\tcmd(0x2C, NULL, 0);\n\tgpio_pin_set_raw(gpioa, PIN_DC, 1);\n}\n\nstatic uint8_t px[W * 24 * 2];\n\nstatic void fill(int x, int y, int w, int h, uint16_t c)\n{\n\twindow(x, y, w, h);\n\tint rows = sizeof(px) \u002F 2 \u002F w;\n\tfor (int i = 0; i \u003C w * rows; i++) { px[2 * i] = c >> 8; px[2 * i + 1] = c & 0xFF; }\n\twhile (h > 0) { int n = MIN(h, rows); spi_out(px, n * w * 2); h -= n; }\n}\n\n\u002F* text box: w x h pixels at (x, y), font scaled by s, aligned 0 left \u002F 1 centre \u002F 2 right *\u002F\nstatic void text(int x, int y, int w, int h, int s, uint16_t fg, uint16_t bg, int align, const char *str)\n{\n\tint len = strlen(str), tw = len * 6 * s - s;\n\tint ox = align == 1 ? (w - tw) \u002F 2 : align == 2 ? w - tw : 1;\n\tint oy = (h - 7 * s) \u002F 2;\n\tfor (int yy = 0; yy \u003C h; yy++) {\n\t\tfor (int xx = 0; xx \u003C w; xx++) {\n\t\t\tbool on = false;\n\t\t\tint gx = xx - ox, gy = yy - oy;\n\t\t\tif (gx >= 0 && gy >= 0 && gy \u003C 7 * s) {\n\t\t\t\tint cx = gx \u002F (6 * s), col = (gx % (6 * s)) \u002F s;\n\t\t\t\tif (cx \u003C len && col \u003C 5) {\n\t\t\t\t\tchar ch = str[cx];\n\t\t\t\t\tif (ch >= 32 && ch \u003C 127) on = (font5x7[ch - 32][col] >> (gy \u002F s)) & 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tuint16_t c = on ? fg : bg;\n\t\t\tsize_t o = (yy * w + xx) * 2;\n\t\t\tpx[o] = c >> 8; px[o + 1] = c & 0xFF;\n\t\t}\n\t}\n\twindow(x, y, w, h);\n\tspi_out(px, w * h * 2);\n}\n\n\u002F* horizontal bar graph: n of max segments lit *\u002F\nstatic void bar(int x, int y, int w, int h, int n, int max, uint16_t on, uint16_t off)\n{\n\tint seg = w \u002F max;\n\tfor (int yy = 0; yy \u003C h; yy++)\n\t\tfor (int xx = 0; xx \u003C w; xx++) {\n\t\t\tint i = xx \u002F seg;",426,true,1796304401137]