From e12ae6f175bad51a0aa68f9babcc58c4329771ea Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Thu, 9 Feb 2023 00:38:56 +0100 Subject: [PATCH] Update old boards code to new software interfaces. --- old/beta/main.c | 70 ++++++++++++++++++++++++++++------------------- old/mosfet/main.c | 40 ++++++++++++++++++--------- 2 files changed, 69 insertions(+), 41 deletions(-) diff --git a/old/beta/main.c b/old/beta/main.c index b61a2a7..d3710a3 100644 --- a/old/beta/main.c +++ b/old/beta/main.c @@ -47,7 +47,7 @@ #include "extdrv/sdmmc.h" -#define MODULE_VERSION 0x01 +#define MODULE_VERSION 0x01 #define MODULE_NAME "Scialys uC" @@ -63,9 +63,9 @@ #define DEC_PERIOD 100 /* If temperature falls bellow FORCE_HEATER_TEMP value, we enter forced heater mode, until - * TARGET_FORCED_HEATER_TEMP is reached. + * TARGET_FORCED_HEATER_TEMP is reached. * When in forced heater mode, the heater is controlled to heat at FORCED_MODE_VALUE which - * is between 0 and 100. + * is between 0 and 100. */ #define FORCE_HEATER_TEMP 35 #define MAX_HEATER_TEMP 90 @@ -79,8 +79,8 @@ uint32_t forced_heater_mode = 0; uint32_t forced_heater_delay = 0; uint32_t forced_heater_time = 0; -#define FORCED_HEATER_DELAY (2 * 3600 * 1000 / DEC_PERIOD) /* Delay before automatic forced heating */ -#define FORCED_HEATER_DURATION (3 * 3600 * 1000 / DEC_PERIOD) /* Duration of automatic forced heating */ +#define FORCED_HEATER_DELAY (2 * 3600 * 1000 / DEC_PERIOD) /* Delay before automatic forced heating */ +#define FORCED_HEATER_DURATION (3 * 3600 * 1000 / DEC_PERIOD) /* Duration of automatic forced heating */ #define MANUAL_ACTIVATION_DURATION (3 * 3600 * 1000 / DEC_PERIOD) /* Three hours */ @@ -158,6 +158,17 @@ const struct pio charge_status_in_pin = LPC_GPIO_0_28; /* Outputs */ /* Led control data pin */ const struct pio ws2812_data_out_pin = LPC_GPIO_0_23; + +#define NB_LEDS 6 + +uint8_t ws2812_leds_data[NB_LEDS * 3]; +struct ws2812_conf led_strip = { + .nb_leds = NB_LEDS, + .led_data = ws2812_leds_data, + .inverted = 0, +}; + + /* AC output control (Mosfet / Triac) */ const struct pio ac_ctrl = LPC_GPIO_0_7; /* Fixme : Fan */ @@ -178,7 +189,7 @@ struct tmp101_sensor_config tmp101_sensor = { }; -#define FAN_ON (10 * 1000) +#define FAN_ON (10 * 1000) const struct lpc_timer_pwm_config fan_pwm_conf = { .nb_channels = 1, .period_chan = CHAN3, @@ -376,15 +387,15 @@ enum buttons { uint32_t manual_activation_request = 0; uint8_t button_pressed = 0; void manual_activation(uint32_t gpio) { - manual_activation_request = MANUAL_ACTIVATION_DURATION; + manual_activation_request = MANUAL_ACTIVATION_DURATION; button_pressed = BUTTON_OK; } void manual_up(uint32_t gpio) { - manual_activation_request = MANUAL_ACTIVATION_DURATION; + manual_activation_request = MANUAL_ACTIVATION_DURATION; button_pressed = BUTTON_UP; } void manual_down(uint32_t gpio) { - manual_activation_request = MANUAL_ACTIVATION_DURATION; + manual_activation_request = MANUAL_ACTIVATION_DURATION; button_pressed = BUTTON_DOWN; } void handle_dec_request(uint32_t curent_tick) { @@ -439,7 +450,7 @@ void display_char(uint8_t line, uint8_t col, uint8_t c) uint8_t* tile_data = (uint8_t*)(&font[tile]); ssd130x_buffer_set_tile(gddram, col, line, tile_data); } -#define OLED_LINE_CHAR_LENGTH (SSD130x_NB_COL / 8) +#define OLED_LINE_CHAR_LENGTH (SSD130x_NB_COL / 8) #define DISPLAY_LINE_LENGTH (OLED_LINE_CHAR_LENGTH + 1) int display_line(uint8_t line, uint8_t col, char* text) { @@ -484,7 +495,7 @@ int main(void) uint16_t isnail_solar_values[NB_VAL]; uint16_t isnail_home_values[NB_VAL]; uint8_t idx = 0; - uint32_t loop = 0; + uint8_t step = 0, loop = 0, retries = 10; char mode = heat; /* Debug info */ int ret = 0; @@ -530,7 +541,7 @@ int main(void) config_gpio(&charge_status_in_pin, 0, GPIO_DIR_IN, 1); /* WS2812B Leds on display board */ - ws2812_config(&ws2812_data_out_pin); + ws2812_config(&led_strip, &ws2812_data_out_pin); /* FAN Config */ timer_pwm_config(LPC_TIMER_32B0, &fan_pwm_conf); @@ -542,11 +553,11 @@ int main(void) status_led(green_only); - /* Configure and start display */ - ret = ssd130x_display_on(&display); - /* Erase screen */ - ssd130x_buffer_set(gddram, 0x00); - ret = ssd130x_display_full_screen(&display); + /* Configure and start display */ + ret = ssd130x_display_on(&display); + /* Erase screen */ + ssd130x_buffer_set(gddram, 0x00); + ret = ssd130x_display_full_screen(&display); /* RTC init */ ret = rtc_pcf85363a_config(&rtc_conf); @@ -563,15 +574,18 @@ int main(void) } /* microSD card init */ - ret = sdmmc_init(µ_sd); - if (ret == 0) { - msleep(1); - ret = sdmmc_init_wait_card_ready(µ_sd); - if (ret == 0) { - ret = sdmmc_init_end(µ_sd); + ret = sdmmc_reset(µ_sd); + uprintf(UART0, "uSD reset ret: %d\n", ret); + /* Init card, try it up to 10 times */ + do { + ret = sdmmc_init_single(µ_sd, &step, &retries); + uprintf(UART0, "uSD init (%d): step: %d, retries: %d, ret: %d, type: %d, bs: %d\n", + loop, step, retries, ret, micro_sd.card_type, micro_sd.block_size); + if (ret != 0) { + msleep(250); } - } - uprintf(UART0, "uSD init: %d, type: %d, bs: %d\n", ret, micro_sd.card_type, micro_sd.block_size); + loop++; + } while ((ret != 0) && (loop < 10)); ret = sdmmc_read_block(µ_sd, 0, mmc_data); uprintf(UART0, "uSD read: %s\n", mmc_data); @@ -788,9 +802,9 @@ int main(void) button_pressed = 0; } uprintf(UART0, "CMD: %d/%d, Fan: %d, ndec:%d, ninc:%d\n\n", command_val, act_cmd, fan_speed, n_dec, n_inc); - ws2812_set_pixel(0, (isnail_val_home / 2000), (isnail_val_solar / 2000), fan_speed); - ws2812_set_pixel(1, 0, 0, (user_potar >> 2)); - ws2812_send_frame(0); + ws2812_set_pixel(&led_strip, 0, (isnail_val_home / 2000), (isnail_val_solar / 2000), fan_speed); + ws2812_set_pixel(&led_strip, 1, 0, 0, (user_potar >> 2)); + ws2812_send_frame(&led_strip, 0); /* Erase screen (internal copy) */ ssd130x_buffer_set(gddram, 0x00); /* Update time and time display on internal memory */ diff --git a/old/mosfet/main.c b/old/mosfet/main.c index d69574c..f5b6727 100644 --- a/old/mosfet/main.c +++ b/old/mosfet/main.c @@ -156,6 +156,17 @@ const struct pio charge_status_in_pin = LPC_GPIO_0_28; /* Outputs */ /* Led control data pin */ const struct pio ws2812_data_out_pin = LPC_GPIO_0_23; + +#define NB_LEDS 6 + +uint8_t ws2812_leds_data[NB_LEDS * 3]; +struct ws2812_conf led_strip = { + .nb_leds = NB_LEDS, + .led_data = ws2812_leds_data, + .inverted = 0, +}; + + /* AC output control (Mosfet / Triac) */ const struct pio ac_ctrl = LPC_GPIO_0_7; const struct pio mos_shutdown = LPC_GPIO_0_6; @@ -503,7 +514,7 @@ int main(void) uint16_t isnail_solar_values[NB_VAL]; uint16_t isnail_home_values[NB_VAL]; uint8_t idx = 0; - uint32_t loop = 0; + uint8_t step = 0, loop = 0, retries = 10; char mode = heat; /* Debug info */ int ret = 0; @@ -551,7 +562,7 @@ int main(void) config_gpio(&charge_status_in_pin, 0, GPIO_DIR_IN, 1); /* WS2812B Leds on display board */ - ws2812_config(&ws2812_data_out_pin); + ws2812_config(&led_strip, &ws2812_data_out_pin); /* FAN Config */ timer_pwm_config(LPC_TIMER_32B0, &fan_pwm_conf); @@ -584,15 +595,18 @@ int main(void) } /* microSD card init */ - ret = sdmmc_init(µ_sd); - if (ret == 0) { - msleep(1); - ret = sdmmc_init_wait_card_ready(µ_sd); - if (ret == 0) { - ret = sdmmc_init_end(µ_sd); + ret = sdmmc_reset(µ_sd); + uprintf(UART0, "uSD reset ret: %d\n", ret); + /* Init card, try it up to 10 times */ + do { + ret = sdmmc_init_single(µ_sd, &step, &retries); + uprintf(UART0, "uSD init (%d): step: %d, retries: %d, ret: %d, type: %d, bs: %d\n", + loop, step, retries, ret, micro_sd.card_type, micro_sd.block_size); + if (ret != 0) { + msleep(250); } - } - uprintf(UART0, "uSD init: %d, type: %d, bs: %d\n", ret, micro_sd.card_type, micro_sd.block_size); + loop++; + } while ((ret != 0) && (loop < 10)); ret = sdmmc_read_block(µ_sd, 0, mmc_data); uprintf(UART0, "uSD read: %s\n", mmc_data); @@ -816,9 +830,9 @@ int main(void) } if (1) { - ws2812_set_pixel(0, (isnail_val_home / 2000), (isnail_val_solar / 2000), fan_speed); - ws2812_set_pixel(1, 0, 0, (user_potar >> 2)); - ws2812_send_frame(0); + ws2812_set_pixel(&led_strip, 0, (isnail_val_home / 2000), (isnail_val_solar / 2000), fan_speed); + ws2812_set_pixel(&led_strip, 1, 0, 0, (user_potar >> 2)); + ws2812_send_frame(&led_strip, 0); } if (1) { -- 2.43.0