Skip to content

Commit

Permalink
Partial E-Paper refresh and More time handling
Browse files Browse the repository at this point in the history
  • Loading branch information
atc1441 committed Feb 13, 2022
1 parent 8aa383e commit 27f6e53
Show file tree
Hide file tree
Showing 26 changed files with 440 additions and 114 deletions.
Binary file modified Firmware/ATC_Paper.bin
Binary file not shown.
25 changes: 19 additions & 6 deletions Firmware/src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ RAM uint8_t battery_level;
RAM uint16_t battery_mv;
RAM int16_t temperature;

RAM uint8_t count_epd_refresh = 60;

// Settings
extern settings_struct settings;

Expand All @@ -30,7 +32,7 @@ _attribute_ram_code_ void user_init_normal(void)
init_nfc();

// epd_display_tiff((uint8_t *)bart_tif, sizeof(bart_tif));
// epd_display(3334533);
// epd_display(3334533);
}

_attribute_ram_code_ void user_init_deepRetn(void)
Expand All @@ -40,9 +42,8 @@ _attribute_ram_code_ void user_init_deepRetn(void)
blc_ll_recoverDeepRetention();
}

_attribute_ram_code_ void main_loop()
_attribute_ram_code_ void main_loop(void)
{
set_led_color(0);
blt_sdk_main_loop();
handler_time();

Expand All @@ -56,14 +57,26 @@ _attribute_ram_code_ void main_loop()
ble_send_temp(temperature);
}

if (time_reached_period(Timer_CH_2, 600))
if (time_reached_period(Timer_CH_2, 60))
{
epd_display(get_time(), battery_mv, temperature);
count_epd_refresh++;
if (count_epd_refresh > 60)
{
count_epd_refresh = 0;
epd_display(get_time(), battery_mv, temperature, 1);
}
else
{
epd_display(get_time(), battery_mv, temperature, 0);
}
}

if (time_reached_period(Timer_CH_0, 10))
{
set_led_color(2);
if (ble_get_connected())
set_led_color(3);
else
set_led_color(2);
WaitMs(1);
set_led_color(0);
}
Expand Down
2 changes: 1 addition & 1 deletion Firmware/src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
void user_init_normal(void);
void user_init_deepRetn(void);
void set_time(uint32_t time_now);
void main_loop();
void main_loop(void);
2 changes: 1 addition & 1 deletion Firmware/src/app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern "C" {

#define CLOCK_SYS_CLOCK_HZ 24000000

#define ADVERTISING_INTERVAL 2000
#define ADVERTISING_INTERVAL 1600

#define RAM _attribute_data_retention_ // short version, this is needed to keep the values in ram after sleep

Expand Down
6 changes: 3 additions & 3 deletions Firmware/src/battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ _attribute_ram_code_ uint16_t get_adc_reading(ADC_InputPchTypeDef p_ain, ADC_Inp
return adc_reading_temp;
}

_attribute_ram_code_ uint16_t get_battery_mv()
_attribute_ram_code_ uint16_t get_battery_mv(void)
{
/*gpio_set_output_en(GPIO_PB7, 1);
gpio_set_input_en(GPIO_PB7, 0);
Expand All @@ -100,7 +100,7 @@ _attribute_ram_code_ uint8_t get_battery_level(uint16_t battery_mv)
return battery_level;
}

void adc_temp_init()
_attribute_ram_code_ void adc_temp_init(void)
{
adc_set_chn_enable_and_max_state_cnt(ADC_MISC_CHN, 2);
adc_set_state_length(240, 0, 10); //set R_max_mc,R_max_c,R_max_s
Expand All @@ -125,7 +125,7 @@ void adc_temp_init()

}

_attribute_ram_code_ uint16_t get_temperature_c()
_attribute_ram_code_ uint16_t get_temperature_c(void)
{
analog_write(0x07, analog_read(0x07) & (~BIT(4)));
adc_init();
Expand Down
4 changes: 2 additions & 2 deletions Firmware/src/battery.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

#include <stdint.h>

uint16_t get_battery_mv();
uint16_t get_battery_mv(void);
uint8_t get_battery_level(uint16_t battery_mv);
uint16_t get_temperature_c();
uint16_t get_temperature_c(void);
24 changes: 12 additions & 12 deletions Firmware/src/ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ RAM uint8_t advertising_data[] = {

uint8_t mac_public[6];

void app_switch_to_indirect_adv(uint8_t e, uint8_t *p, int n)
_attribute_ram_code_ void app_switch_to_indirect_adv(uint8_t e, uint8_t *p, int n)
{
bls_ll_setAdvParam(ADVERTISING_INTERVAL, ADVERTISING_INTERVAL + 50, ADV_TYPE_CONNECTABLE_UNDIRECTED, OWN_ADDRESS_PUBLIC, 0, NULL, BLT_ENABLE_ADV_ALL, ADV_FP_NONE);
bls_ll_setAdvEnable(1);
}

void ble_disconnect_callback(uint8_t e, uint8_t *p, int n)
_attribute_ram_code_ void ble_disconnect_callback(uint8_t e, uint8_t *p, int n)
{
ble_connected = 0;
ota_started = 0;
Expand All @@ -67,20 +67,20 @@ _attribute_ram_code_ void user_set_rf_power(uint8_t e, uint8_t *p, int n)
rf_set_power_level_index(RF_POWER_P3p01dBm);
}

void ble_connect_callback(uint8_t e, uint8_t *p, int n)
_attribute_ram_code_ void ble_connect_callback(uint8_t e, uint8_t *p, int n)
{
ble_connected = 1;
ota_started = 0;
ble_set_connection_speed(200);
printf("BLE connected\r\n");
}

void ble_set_connection_speed(uint16_t speed)
_attribute_ram_code_ void ble_set_connection_speed(uint16_t speed)
{
bls_l2cap_requestConnParamUpdate(speed, speed + 2, 0, 2000);
}

int otaWritePre(void *p)
_attribute_ram_code_ int otaWritePre(void *p)
{
if (ota_started == 0)
{
Expand All @@ -90,7 +90,7 @@ int otaWritePre(void *p)
return custom_otaWrite(p);
}

int RxTxWrite(void *p)
_attribute_ram_code_ int RxTxWrite(void *p)
{
cmd_parser(p);
return 0;
Expand All @@ -101,7 +101,7 @@ _attribute_ram_code_ void blt_pm_proc(void)
bls_pm_setSuspendMask(SUSPEND_ADV | DEEPSLEEP_RETENTION_ADV | SUSPEND_CONN | DEEPSLEEP_RETENTION_CONN);
}

void init_ble()
void init_ble(void)
{
////////////////// BLE stack initialization ////////////////////////////////////
uint8_t mac_random_static[6];
Expand Down Expand Up @@ -156,17 +156,17 @@ void init_ble()
blc_att_setRxMtuSize(250);
}

bool ble_get_connected()
_attribute_ram_code_ bool ble_get_connected(void)
{
return ble_connected;
}

bool ble_get_ota_started()
_attribute_ram_code_ bool ble_get_ota_started(void)
{
return ota_started;
}

void set_adv_data(int16_t temp, uint8_t battery_level, uint16_t battery_mv)
_attribute_ram_code_ void set_adv_data(int16_t temp, uint8_t battery_level, uint16_t battery_mv)
{
advertising_data[10] = temp >> 8;
advertising_data[11] = temp & 0xff;
Expand All @@ -181,14 +181,14 @@ void set_adv_data(int16_t temp, uint8_t battery_level, uint16_t battery_mv)
bls_ll_setAdvData((uint8_t *)advertising_data, sizeof(advertising_data));
}

void ble_send_temp(int16_t temp)
_attribute_ram_code_ void ble_send_temp(int16_t temp)
{
my_tempVal[0] = temp & 0xFF;
my_tempVal[1] = temp >> 8;
bls_att_pushNotifyData(TEMP_LEVEL_INPUT_DP_H, my_tempVal, 2);
}

void ble_send_battery(uint8_t value)
_attribute_ram_code_ void ble_send_battery(uint8_t value)
{
my_batVal[0] = value;
bls_att_pushNotifyData(BATT_LEVEL_INPUT_DP_H, (uint8_t *)my_batVal, 1);
Expand Down
10 changes: 5 additions & 5 deletions Firmware/src/ble.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#include <stdbool.h>
#include <stdint.h>

void init_ble();
void init_ble(void);
void set_adv_data(int16_t temp, uint8_t battery_level, uint16_t battery_mv);
bool ble_get_connected();
bool ble_get_ota_started();
bool ble_get_connected(void);
bool ble_get_ota_started(void);
void ble_send_temp(int16_t temp);
void ble_send_battery(uint8_t value);
void blt_pm_proc(void);

int RxTxWrite(void * p);
int otaWritePre(void * p);
int RxTxWrite(void *p);
int otaWritePre(void *p);
void ble_set_connection_speed(uint16_t speed);
Loading

0 comments on commit 27f6e53

Please sign in to comment.