#include "extdrv/sdmmc.h"
-#define MODULE_VERSION 0x01
+#define MODULE_VERSION 0x01
#define MODULE_NAME "Scialys uC"
#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
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 */
/* 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 */
};
-#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,
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) {
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)
{
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;
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);
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);
}
/* 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);
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 */
/* 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;
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;
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);
}
/* 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);
}
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) {