From 3da15dd4edea3e00845ef2083e1fbdc32735705b Mon Sep 17 00:00:00 2001 From: Renze Nicolai Date: Sat, 4 Jun 2022 02:30:23 +0200 Subject: [PATCH 1/3] Add ADC reading --- components/mch2022-rp2040 | 2 +- main/CMakeLists.txt | 1 + main/adc_test.c | 76 +++++++++++++++++++++++++++++++++++++++ main/include/adc_test.h | 9 +++++ main/menus/dev.c | 7 +++- main/menus/start.c | 48 +++++++++++++++++++------ 6 files changed, 131 insertions(+), 12 deletions(-) create mode 100644 main/adc_test.c create mode 100644 main/include/adc_test.h diff --git a/components/mch2022-rp2040 b/components/mch2022-rp2040 index 2882f91..dce32a7 160000 --- a/components/mch2022-rp2040 +++ b/components/mch2022-rp2040 @@ -1 +1 @@ -Subproject commit 2882f91df13c6155062b6c94871fdf68e1c62675 +Subproject commit dce32a7f6128b8f405dc7a424595ab9619dd84d6 diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 02468fc..a381bbb 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -24,6 +24,7 @@ idf_component_register( "factory_test.c" "animation.c" "button_test.c" + "adc_test.c" INCLUDE_DIRS "." "include" "menus" diff --git a/main/adc_test.c b/main/adc_test.c new file mode 100644 index 0000000..c5db933 --- /dev/null +++ b/main/adc_test.c @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include +#include "ili9341.h" +#include "pax_gfx.h" +#include "rp2040.h" +#include "hardware.h" + +void test_adc(xQueueHandle buttonQueue, pax_buf_t* pax_buffer, ILI9341* ili9341) { + bool quit = false; + + RP2040* rp2040 = get_rp2040(); + const pax_font_t* font = pax_get_font("saira regular"); + + while (!quit) { + bool error = false; + + float vbat = 0; + if (rp2040_read_vbat(rp2040, &vbat) != ESP_OK) { + error = true; + } + + float vusb = 0; + if (rp2040_read_vusb(rp2040, &vusb) != ESP_OK) { + error = true; + } + + /*uint16_t raw_temperature = 0; + if (rp2040_read_temp(rp2040, &raw_temperature) != ESP_OK) { + error = true; + } + + uint8_t charging = 0; + if (rp2040_get_charging(rp2040, &charging) != ESP_OK) { + error = true; + }*/ + + //const float conversion_factor = 3.3f / (1 << 12); // 12-bit ADC with 3.3v vref + //float vtemperature = raw_temperature * conversion_factor; // Inside of RP2040 chip + //float temperature = 27 - (vtemperature - 0.706) / 0.001721; // From https://raspberrypi.github.io/pico-sdk-doxygen/group__hardware__adc.html + + + pax_noclip(pax_buffer); + pax_background(pax_buffer, 0x325aa8); + pax_draw_text(pax_buffer, 0xFFFFFFFF, font, 18, 0, 20*0, "Analog inputs"); + char buffer[64]; + snprintf(buffer, sizeof(buffer), "Battery voltage %f v", vbat); + pax_draw_text(pax_buffer, 0xFFFFFFFF, font, 18, 0, 20*1, buffer); + snprintf(buffer, sizeof(buffer), "USB voltage %f v", vusb); + pax_draw_text(pax_buffer, 0xFFFFFFFF, font, 18, 0, 20*2, buffer); + /*snprintf(buffer, sizeof(buffer), "Temperature %f *c", temperature); + pax_draw_text(pax_buffer, 0xFFFFFFFF, font, 18, 0, 20*3, buffer); + snprintf(buffer, sizeof(buffer), "Charging %02X", charging); + pax_draw_text(pax_buffer, 0xFFFFFFFF, font, 18, 0, 20*4, buffer);*/ + pax_draw_text(pax_buffer, 0xFFFFFFFF, font, 18, 0, 20*5, (error ? "ERROR" : "")); + ili9341_write(ili9341, pax_buffer->buf); + + rp2040_input_message_t buttonMessage = {0}; + if (xQueueReceive(buttonQueue, &buttonMessage, 250 / portTICK_PERIOD_MS) == pdTRUE) { + uint8_t pin = buttonMessage.input; + bool value = buttonMessage.state; + if (value) { + switch(pin) { + case RP2040_INPUT_BUTTON_HOME: + case RP2040_INPUT_BUTTON_BACK: + quit = true; + default: + break; + } + } + } + } +} + diff --git a/main/include/adc_test.h b/main/include/adc_test.h new file mode 100644 index 0000000..1a6e19d --- /dev/null +++ b/main/include/adc_test.h @@ -0,0 +1,9 @@ +#include +#include +#include +#include +#include +#include "ili9341.h" +#include "pax_gfx.h" + +void test_adc(xQueueHandle buttonQueue, pax_buf_t* pax_buffer, ILI9341* ili9341); diff --git a/main/menus/dev.c b/main/menus/dev.c index 2db34b2..25e6126 100644 --- a/main/menus/dev.c +++ b/main/menus/dev.c @@ -22,6 +22,7 @@ #include "fpga_test.h" #include "animation.h" #include "button_test.h" +#include "adc_test.h" extern const uint8_t dev_png_start[] asm("_binary_dev_png_start"); extern const uint8_t dev_png_end[] asm("_binary_dev_png_end"); @@ -34,7 +35,8 @@ typedef enum action { ACTION_FILE_BROWSER, ACTION_FILE_BROWSER_INT, ACTION_ANIMATION, - ACTION_BUTTON_TEST + ACTION_BUTTON_TEST, + ACTION_ADC_TEST } menu_dev_action_t; void render_dev_help(pax_buf_t* pax_buffer) { @@ -68,6 +70,7 @@ void menu_dev(xQueueHandle buttonQueue, pax_buf_t* pax_buffer, ILI9341* ili9341) menu_insert_item(menu, "File browser (internal)", NULL, (void*) ACTION_FILE_BROWSER_INT, -1); menu_insert_item(menu, "Animation", NULL, (void*) ACTION_ANIMATION, -1); menu_insert_item(menu, "Button test", NULL, (void*) ACTION_BUTTON_TEST, -1); + menu_insert_item(menu, "Analog inputs", NULL, (void*) ACTION_ADC_TEST, -1); bool render = true; menu_dev_action_t action = ACTION_NONE; @@ -130,6 +133,8 @@ void menu_dev(xQueueHandle buttonQueue, pax_buf_t* pax_buffer, ILI9341* ili9341) display_animation(pax_buffer, ili9341); } else if (action == ACTION_BUTTON_TEST) { test_buttons(buttonQueue, pax_buffer, ili9341); + } else if (action == ACTION_ADC_TEST) { + test_adc(buttonQueue, pax_buffer, ili9341); } else if (action == ACTION_BACK) { break; } diff --git a/main/menus/start.c b/main/menus/start.c index 4f1854b..fa6e54a 100644 --- a/main/menus/start.c +++ b/main/menus/start.c @@ -17,6 +17,8 @@ #include "settings.h" #include "dev.h" #include "bootscreen.h" +#include "hardware.h" +#include "math.h" extern const uint8_t home_png_start[] asm("_binary_home_png_start"); extern const uint8_t home_png_end[] asm("_binary_home_png_end"); @@ -41,17 +43,13 @@ typedef enum action { ACTION_SETTINGS } menu_start_action_t; -void render_start_help(pax_buf_t* pax_buffer, const char* version) { +void render_start_help(pax_buf_t* pax_buffer, const char* text) { const pax_font_t *font = pax_get_font("saira regular"); pax_background(pax_buffer, 0xFFFFFF); pax_noclip(pax_buffer); pax_draw_text(pax_buffer, 0xFF491d88, font, 18, 5, 240 - 18, "[A] accept"); - - char version_text[64]; - snprintf(version_text, sizeof(version_text), "v%s", version); - - pax_vec1_t version_size = pax_text_size(font, 18, version_text); - pax_draw_text(pax_buffer, 0xFF491d88, font, 18, 320 - 5 - version_size.x, 240 - 18, version_text); + pax_vec1_t version_size = pax_text_size(font, 18, text); + pax_draw_text(pax_buffer, 0xFF491d88, font, 18, 320 - 5 - version_size.x, 240 - 18, text); } void menu_start(xQueueHandle buttonQueue, pax_buf_t* pax_buffer, ILI9341* ili9341, const char* version) { @@ -88,12 +86,21 @@ void menu_start(xQueueHandle buttonQueue, pax_buf_t* pax_buffer, ILI9341* ili934 bool render = true; menu_start_action_t action = ACTION_NONE; + + uint8_t analogReadTimer = 0; + float battery_voltage = 0; + float usb_voltage = 0; + //uint8_t rp2040_usb = 0; - render_start_help(pax_buffer, version); + // Calculated: + uint8_t battery_percent = 0; + bool battery_charging = false; + + RP2040* rp2040 = get_rp2040(); while (1) { rp2040_input_message_t buttonMessage = {0}; - if (xQueueReceive(buttonQueue, &buttonMessage, 16 / portTICK_PERIOD_MS) == pdTRUE) { + if (xQueueReceive(buttonQueue, &buttonMessage, 100 / portTICK_PERIOD_MS) == pdTRUE) { uint8_t pin = buttonMessage.input; bool value = buttonMessage.state; switch(pin) { @@ -122,7 +129,29 @@ void menu_start(xQueueHandle buttonQueue, pax_buf_t* pax_buffer, ILI9341* ili934 } } + if (analogReadTimer > 0) { + analogReadTimer--; + } else { + analogReadTimer = 10; // No need to update these values really quickly + if (rp2040_read_vbat(rp2040, &battery_voltage) != ESP_OK) { + battery_voltage = 0; + } + if (rp2040_read_vusb(rp2040, &usb_voltage) != ESP_OK) { + usb_voltage = 0; + } + + battery_percent = ((battery_voltage - 3.7) * 100) / (4.1 - 3.7); + if (battery_percent > 100) battery_percent = 100; + + battery_charging = (usb_voltage > 4.0) && (battery_percent < 100); + + render = true; + } + if (render) { + char textBuffer[64]; + snprintf(textBuffer, sizeof(textBuffer), "B%1.1fv U%1.1fv %03u%%%c v%s", battery_voltage, usb_voltage, battery_percent, battery_charging ? '+' : ' ', version); + render_start_help(pax_buffer, textBuffer); menu_render(pax_buffer, menu, 0, 0, 320, 220, 0xFF491d88); ili9341_write(ili9341, pax_buffer->buf); render = false; @@ -141,7 +170,6 @@ void menu_start(xQueueHandle buttonQueue, pax_buf_t* pax_buffer, ILI9341* ili934 } action = ACTION_NONE; render = true; - render_start_help(pax_buffer, version); } } From fd5398e572eb2c945d4aff74bb5f9cc3ceeeb46c Mon Sep 17 00:00:00 2001 From: Renze Nicolai Date: Sat, 4 Jun 2022 02:33:03 +0200 Subject: [PATCH 2/3] Update RP2040 firmware --- resources/rp2040_firmware.bin | Bin 36076 -> 36380 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/resources/rp2040_firmware.bin b/resources/rp2040_firmware.bin index 285205d7fd59d9629728f79b478bd14ceb19332c..917aafd561508b01342925a80c0e991666144c85 100755 GIT binary patch delta 4119 zcmcgvdsLH07N7g&!Asx+d57Sa1OY*mg3oF-L>nGK!ADh~wjo<9K57G4%c?9fYW4Kt zLC5V16>HbFzS>=CptUX7xb@Z3$0pkL_}E%#Ex6sf{j_=rAt8Gw##VdwoSyw>bIxz> zow>i6xpQZ}JCh%px!t?Drt|WWjlfrL+N1aLWI>}L`dESJRwqn!LReEGvLo$ z5LPG^+g+sK$Dd>t`w?>iA;H&3H<}#v*f%4E2-noW%Q)aKXnC(^iJ1dR!PkGumyG3k zp91Y))5%=kV?PcN@w%IcMMJK>)l1u@g;CA^N`+VKv+Fe&Vg(JCO`l)m zB}mEj_V$rXaPn>DuDp7Z<#sI7vv!l;s`1|FV?BsgqIGp#)-Tl0)<38pC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z=-hXlt~mXVi#YxuUjcQIy&H-_sG<%kAEOFR9jdy38yYW*w&Lh7h)*HZ4^ zS=73#IC32}I2+;?`Qcr)>bxhzy^{GYs|DewB_QlC2jMjgeQ7IF%=zLH?4NBQ{1>K` BeBA&5 From 04e6eb8ba3d994704d9184c3630b1c5643408a62 Mon Sep 17 00:00:00 2001 From: Renze Nicolai Date: Sat, 4 Jun 2022 16:20:10 +0200 Subject: [PATCH 3/3] Green! --- main/button_test.c | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/main/button_test.c b/main/button_test.c index 3f67524..43b7a1b 100644 --- a/main/button_test.c +++ b/main/button_test.c @@ -22,6 +22,19 @@ void test_buttons(xQueueHandle buttonQueue, pax_buf_t* pax_buffer, ILI9341* ili9 bool btn_start = false; bool btn_accept = false; bool btn_back = false; + + bool btn_joy_down_green = false; + bool btn_joy_up_green = false; + bool btn_joy_left_green = false; + bool btn_joy_right_green = false; + bool btn_joy_press_green = false; + bool btn_home_green = false; + bool btn_menu_green = false; + bool btn_select_green = false; + bool btn_start_green = false; + bool btn_accept_green = false; + bool btn_back_green = false; + while (!quit) { rp2040_input_message_t buttonMessage = {0}; @@ -32,36 +45,47 @@ void test_buttons(xQueueHandle buttonQueue, pax_buf_t* pax_buffer, ILI9341* ili9 switch(pin) { case RP2040_INPUT_JOYSTICK_DOWN: btn_joy_down = value; + if (value) btn_joy_down_green = true; break; case RP2040_INPUT_JOYSTICK_UP: btn_joy_up = value; + if (value) btn_joy_up_green = true; break; case RP2040_INPUT_JOYSTICK_LEFT: btn_joy_left = value; + if (value) btn_joy_left_green = true; break; case RP2040_INPUT_JOYSTICK_RIGHT: btn_joy_right = value; + if (value) btn_joy_right_green = true; break; case RP2040_INPUT_JOYSTICK_PRESS: btn_joy_press = value; + if (value) btn_joy_press_green = true; break; case RP2040_INPUT_BUTTON_HOME: btn_home = value; + if (value) btn_home_green = true; break; case RP2040_INPUT_BUTTON_MENU: btn_menu = value; + if (value) btn_menu_green = true; break; case RP2040_INPUT_BUTTON_SELECT: btn_select = value; + if (value) btn_select_green = true; break; case RP2040_INPUT_BUTTON_START: btn_start = value; + if (value) btn_start_green = true; break; case RP2040_INPUT_BUTTON_ACCEPT: btn_accept = value; + if (value) btn_accept_green = true; break; case RP2040_INPUT_BUTTON_BACK: btn_back = value; + if (value) btn_back_green = true; default: break; } @@ -73,27 +97,27 @@ void test_buttons(xQueueHandle buttonQueue, pax_buf_t* pax_buffer, ILI9341* ili9 pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*0, "Press HOME + START to exit"); char buffer[64]; snprintf(buffer, sizeof(buffer), "JOY DOWN %s", btn_joy_down ? "PRESSED" : "released"); - pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*1, buffer); + pax_draw_text(pax_buffer, btn_joy_down_green ? 0xFF00FF00 : 0xFFFFFFFF, NULL, 18, 0, 20*1, buffer); snprintf(buffer, sizeof(buffer), "JOY UP %s", btn_joy_up ? "PRESSED" : "released"); - pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*2, buffer); + pax_draw_text(pax_buffer, btn_joy_up_green ? 0xFF00FF00 : 0xFFFFFFFF, NULL, 18, 0, 20*2, buffer); snprintf(buffer, sizeof(buffer), "JOY LEFT %s", btn_joy_left ? "PRESSED" : "released"); - pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*3, buffer); + pax_draw_text(pax_buffer, btn_joy_right_green ? 0xFF00FF00 : 0xFFFFFFFF, NULL, 18, 0, 20*3, buffer); snprintf(buffer, sizeof(buffer), "JOY RIGHT %s", btn_joy_right ? "PRESSED" : "released"); - pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*4, buffer); + pax_draw_text(pax_buffer, btn_joy_left_green ? 0xFF00FF00 : 0xFFFFFFFF, NULL, 18, 0, 20*4, buffer); snprintf(buffer, sizeof(buffer), "JOY PRESS %s", btn_joy_press ? "PRESSED" : "released"); - pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*5, buffer); + pax_draw_text(pax_buffer, btn_joy_press_green ? 0xFF00FF00 : 0xFFFFFFFF, NULL, 18, 0, 20*5, buffer); snprintf(buffer, sizeof(buffer), "BTN HOME %s", btn_home ? "PRESSED" : "released"); - pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*6, buffer); + pax_draw_text(pax_buffer, btn_home_green ? 0xFF00FF00 : 0xFFFFFFFF, NULL, 18, 0, 20*6, buffer); snprintf(buffer, sizeof(buffer), "BTN MENU %s", btn_menu ? "PRESSED" : "released"); - pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*7, buffer); + pax_draw_text(pax_buffer, btn_menu_green ? 0xFF00FF00 : 0xFFFFFFFF, NULL, 18, 0, 20*7, buffer); snprintf(buffer, sizeof(buffer), "BTN SELECT %s", btn_select ? "PRESSED" : "released"); - pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*8, buffer); + pax_draw_text(pax_buffer, btn_select_green ? 0xFF00FF00 : 0xFFFFFFFF, NULL, 18, 0, 20*8, buffer); snprintf(buffer, sizeof(buffer), "BTN START %s", btn_start ? "PRESSED" : "released"); - pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*9, buffer); + pax_draw_text(pax_buffer, btn_start_green ? 0xFF00FF00 : 0xFFFFFFFF, NULL, 18, 0, 20*9, buffer); snprintf(buffer, sizeof(buffer), "BTN A %s", btn_accept ? "PRESSED" : "released"); - pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*10, buffer); + pax_draw_text(pax_buffer, btn_accept_green ? 0xFF00FF00 : 0xFFFFFFFF, NULL, 18, 0, 20*10, buffer); snprintf(buffer, sizeof(buffer), "BTN B %s", btn_back ? "PRESSED" : "released"); - pax_draw_text(pax_buffer, 0xFFFFFFFF, NULL, 18, 0, 20*11, buffer); + pax_draw_text(pax_buffer, btn_back_green ? 0xFF00FF00 : 0xFFFFFFFF, NULL, 18, 0, 20*11, buffer); ili9341_write(ili9341, pax_buffer->buf); render = false; }