Skip to content

Commit 64f5828

Browse files
committed
Even more SAO stuff
1 parent f7bb420 commit 64f5828

File tree

2 files changed

+58
-6
lines changed

2 files changed

+58
-6
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.5)
22
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
33

44
set(PROJECT_NAME "MCH2022")
5-
set(PROJECT_VER "2.0.8")
5+
set(PROJECT_VER "2.0.9")
66

77
project(${PROJECT_NAME})
88

main/menus/sao.c

+57-5
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void program_ssd1306() {
135135
.reserved = 0};
136136

137137
sao_driver_basic_io_data_t data_basic_io = {
138-
.io1_function = SAO_DRIVER_BASIC_IO_FUNC_LED_RED, .io2_function = SAO_DRIVER_BASIC_IO_FUNC_LED_BLUE, .reserved = 0};
138+
.io1_function = SAO_DRIVER_BASIC_IO_FUNC_LED_BLUE, .io2_function = SAO_DRIVER_BASIC_IO_FUNC_LED_RED, .reserved = 0};
139139

140140
sao_format("OLED display", SAO_DRIVER_SSD1306_NAME, (uint8_t*) &data_ssd1306, sizeof(data_ssd1306), SAO_DRIVER_STORAGE_NAME, (uint8_t*) &data_storage,
141141
sizeof(data_storage), SAO_DRIVER_BASIC_IO_NAME, (uint8_t*) &data_basic_io, sizeof(sao_driver_basic_io_data_t), false);
@@ -162,6 +162,20 @@ void program_ntag() {
162162
sizeof(data_storage), SAO_DRIVER_BASIC_IO_NAME, (uint8_t*) &data_basic_io, sizeof(sao_driver_basic_io_data_t), false);
163163
}
164164

165+
void program_tilde_butterfly() {
166+
sao_driver_neopixel_data_t data_neopixel = {.length = 5, .color_order = SAO_DRIVER_NEOPIXEL_COLOR_ORDER_GRB, .reserved = 0};
167+
168+
sao_driver_storage_data_t data_storage = {.flags = 0,
169+
.address = 0x50,
170+
.size_exp = 11, // 2 kbit (2^11)
171+
.page_size_exp = 4, // 16 bytes (2^4)
172+
.data_offset = 4, // 4 pages (64 bytes)
173+
.reserved = 0};
174+
175+
sao_format("[~] MCH butterfly", SAO_DRIVER_NEOPIXEL_NAME, (uint8_t*) &data_neopixel, sizeof(data_neopixel), SAO_DRIVER_STORAGE_NAME,
176+
(uint8_t*) &data_storage, sizeof(data_storage), NULL, NULL, 0, true);
177+
}
178+
165179
typedef enum action {
166180
ACTION_NONE = 0,
167181
ACTION_BACK,
@@ -173,7 +187,8 @@ typedef enum action {
173187
ACTION_DISKETTE,
174188
ACTION_SSD1306,
175189
ACTION_NTAG,
176-
ACTION_SMALL
190+
ACTION_SMALL,
191+
ACTION_BUTTERFLY
177192
} menu_dev_action_t;
178193

179194
static void menu_sao_format(xQueueHandle button_queue) {
@@ -199,6 +214,7 @@ static void menu_sao_format(xQueueHandle button_queue) {
199214
menu_insert_item(menu, "SSD1306", NULL, (void*) ACTION_SSD1306, -1);
200215
menu_insert_item(menu, "NTAG", NULL, (void*) ACTION_NTAG, -1);
201216
menu_insert_item(menu, "Generic 2kb EEPROM", NULL, (void*) ACTION_SMALL, -1);
217+
menu_insert_item(menu, "Tilde butterfly", NULL, (void*) ACTION_BUTTERFLY, -1);
202218

203219
bool render = true;
204220
menu_dev_action_t action = ACTION_NONE;
@@ -268,6 +284,9 @@ static void menu_sao_format(xQueueHandle button_queue) {
268284
} else if (action == ACTION_SMALL) {
269285
program_small();
270286
break;
287+
} else if (action == ACTION_BUTTERFLY) {
288+
program_tilde_butterfly();
289+
break;
271290
} else if (action == ACTION_BACK) {
272291
break;
273292
}
@@ -340,6 +359,11 @@ static const char* neopixelColorOrderToString(uint8_t color_order) {
340359
return neopixel_color_order_strings[color_order];
341360
}
342361

362+
static bool neopixelColorHasWhite(uint8_t color_order) {
363+
if (color_order > SAO_DRIVER_NEOPIXEL_COLOR_ORDER_WRGB) return true;
364+
return false;
365+
}
366+
343367
static const char* ntagInterruptToString(uint8_t interrupt_pin) {
344368
if (interrupt_pin == 0) return "none";
345369
if (interrupt_pin == 1) return "IO1";
@@ -371,15 +395,22 @@ static bool basicioFunctionIsLED(uint8_t function) {
371395
return false;
372396
}
373397

374-
bool io1_is_led = false;
375-
bool io2_is_led = false;
398+
bool io1_is_led = false;
399+
bool io2_is_led = false;
400+
uint8_t neopixel_length = 0;
401+
bool neopixel_white = false;
376402

377403
static void render_sao_status(pax_buf_t* pax_buffer, SAO* sao) {
378404
char stringbuf[256] = {0};
379405
const pax_font_t* font = pax_font_saira_regular;
380406
pax_background(pax_buffer, 0xFFFFFF);
381407
pax_noclip(pax_buffer);
382408

409+
io1_is_led = false;
410+
io2_is_led = false;
411+
neopixel_length = 0;
412+
neopixel_white = false;
413+
383414
if (sao->type == SAO_BINARY) {
384415
bool can_start_app = false;
385416
render_header(pax_buffer, 0, 0, pax_buffer->width, 34, 18, 0xFF491d88, 0xFF43b5a0, NULL, sao->name);
@@ -394,9 +425,11 @@ static void render_sao_status(pax_buf_t* pax_buffer, SAO* sao) {
394425
} else if (strncmp(sao->drivers[driver_index].name, SAO_DRIVER_NEOPIXEL_NAME, strlen(SAO_DRIVER_NEOPIXEL_NAME)) == 0) {
395426
sao_driver_neopixel_data_t* data = (sao_driver_neopixel_data_t*) sao->drivers[driver_index].data;
396427
snprintf(stringbuf, sizeof(stringbuf) - 1, "%u Neopixel LEDs (%s)", data->length, neopixelColorOrderToString(data->color_order));
428+
neopixel_length = data->length;
429+
neopixel_white = neopixelColorHasWhite(data->color_order);
397430
} else if (strncmp(sao->drivers[driver_index].name, SAO_DRIVER_SSD1306_NAME, strlen(SAO_DRIVER_SSD1306_NAME)) == 0) {
398431
sao_driver_ssd1306_data_t* data = (sao_driver_ssd1306_data_t*) sao->drivers[driver_index].data;
399-
snprintf(stringbuf, sizeof(stringbuf) - 1, "SSD1306 128x%u OLED display @0x%02x", data->height, data->address);
432+
snprintf(stringbuf, sizeof(stringbuf) - 1, "SSD1306 128x%u OLED @0x%02x", data->height, data->address);
400433
} else if (strncmp(sao->drivers[driver_index].name, SAO_DRIVER_NTAG_NAME, strlen(SAO_DRIVER_NTAG_NAME)) == 0) {
401434
sao_driver_ntag_data_t* data = (sao_driver_ntag_data_t*) sao->drivers[driver_index].data;
402435
snprintf(stringbuf, sizeof(stringbuf) - 1, "NTAG NFC tag @0x%02x %ukb int=%s", data->address, intPow(2, data->size_exp) / 1024,
@@ -447,18 +480,33 @@ static bool connect_to_wifi() {
447480

448481
void reset_sao_io() {
449482
RP2040* rp2040 = get_rp2040();
483+
// rp2040_set_ws2812_mode(rp2040, 0); // FIXME: fix bug in RP2040 firmware first, then add this line
450484
rp2040_set_gpio_value(rp2040, 0, false);
451485
rp2040_set_gpio_value(rp2040, 1, false);
452486
rp2040_set_gpio_dir(rp2040, 0, false);
453487
rp2040_set_gpio_dir(rp2040, 1, false);
454488
}
455489

456490
void set_sao_io(uint8_t pin, bool value) {
491+
printf("Set IO: %u to %u\n", pin, value);
457492
RP2040* rp2040 = get_rp2040();
458493
rp2040_set_gpio_dir(rp2040, pin, true);
459494
rp2040_set_gpio_value(rp2040, pin, value);
460495
}
461496

497+
void set_sao_neopixel(uint32_t color) {
498+
if (neopixel_length > 0) {
499+
printf("Set neopixels to %08X\n", color);
500+
RP2040* rp2040 = get_rp2040();
501+
rp2040_set_ws2812_length(rp2040, neopixel_length);
502+
rp2040_set_ws2812_mode(rp2040, neopixel_white ? 2 : 1);
503+
for (uint8_t i = 0; i < neopixel_length; i++) {
504+
rp2040_set_ws2812_data(rp2040, i, color);
505+
}
506+
rp2040_ws2812_trigger(rp2040);
507+
}
508+
}
509+
462510
void menu_sao(xQueueHandle button_queue) {
463511
rp2040_input_message_t buttonMessage = {0};
464512
while (xQueueReceive(button_queue, &buttonMessage, 0) == pdTRUE) {
@@ -527,21 +575,25 @@ void menu_sao(xQueueHandle button_queue) {
527575
if (io1_is_led) {
528576
set_sao_io(0, true);
529577
}
578+
set_sao_neopixel(0xFF000000);
530579
break;
531580
case RP2040_INPUT_JOYSTICK_DOWN:
532581
if (io1_is_led) {
533582
set_sao_io(0, false);
534583
}
584+
set_sao_neopixel(0x00FF0000);
535585
break;
536586
case RP2040_INPUT_JOYSTICK_RIGHT:
537587
if (io2_is_led) {
538588
set_sao_io(1, true);
539589
}
590+
set_sao_neopixel(0x0000FF00);
540591
break;
541592
case RP2040_INPUT_JOYSTICK_LEFT:
542593
if (io2_is_led) {
543594
set_sao_io(1, false);
544595
}
596+
set_sao_neopixel(0x000000FF);
545597
break;
546598
case RP2040_INPUT_BUTTON_START:
547599
menu_sao_format(button_queue);

0 commit comments

Comments
 (0)