mirror of
https://github.com/RoCry/blozi-etag.git
synced 2026-05-12 03:44:46 +08:00
Deep sleep update and MTU increase
This commit is contained in:
Binary file not shown.
@@ -34,9 +34,12 @@ void user_init_normal(void)
|
||||
random_generator_init(); // must
|
||||
init_ble();
|
||||
init_flash();
|
||||
init_nfc();
|
||||
init_led();
|
||||
battery_mv = get_battery_mv();
|
||||
battery_level = get_battery_level(battery_mv);
|
||||
epd_display_tiff((uint8_t *)bart_tif, sizeof(bart_tif));
|
||||
//epd_display(3334533);
|
||||
}
|
||||
|
||||
_attribute_ram_code_ void user_init_deepRetn(void)
|
||||
@@ -71,13 +74,15 @@ _attribute_ram_code_ void main_loop()
|
||||
// Uncomment this line to periodically have the display refreshed with the current time.
|
||||
// epd_display(current_unix_time);
|
||||
}
|
||||
|
||||
if (epd_state_handler()) // if epd_update is ongoing enable gpio wakeup to put the display to sleep as fast as possible
|
||||
{
|
||||
cpu_set_gpio_wakeup(EPD_BUSY, 1, 1);
|
||||
bls_pm_setWakeupSource(PM_WAKEUP_PAD);
|
||||
bls_pm_setSuspendMask(SUSPEND_DISABLE);
|
||||
}
|
||||
else
|
||||
{
|
||||
blt_pm_proc();
|
||||
}
|
||||
deinit_nfc();
|
||||
deinit_led();
|
||||
gpio_shutdown(GPIO_ALL);
|
||||
blt_pm_proc();
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ extern "C" {
|
||||
|
||||
#define CLOCK_SYS_CLOCK_HZ 24000000
|
||||
|
||||
#define ADVERTISING_INTERVAL 300
|
||||
#define ADVERTISING_INTERVAL 2000
|
||||
|
||||
#define RAM _attribute_data_retention_ // short version, this is needed to keep the values in ram after sleep
|
||||
|
||||
|
||||
@@ -13,61 +13,85 @@
|
||||
#include "cmd_parser.h"
|
||||
#include "flash.h"
|
||||
|
||||
RAM uint8_t ble_connected = 0;
|
||||
RAM uint8_t ble_connected = 0;
|
||||
|
||||
RAM uint8_t ota_started = 0;
|
||||
extern uint8_t my_tempVal[2];
|
||||
extern uint8_t my_batVal[1];
|
||||
|
||||
RAM uint8_t blt_rxfifo_b[64 * 8] = {0};
|
||||
RAM my_fifo_t blt_rxfifo = { 64, 8, 0, 0, blt_rxfifo_b,};
|
||||
|
||||
RAM uint8_t blt_txfifo_b[40 * 16] = {0};
|
||||
RAM my_fifo_t blt_txfifo = { 40, 16, 0, 0, blt_txfifo_b,};
|
||||
|
||||
RAM uint8_t ble_name[] = {11, 0x09, 'E', 'S', 'L', '_', '0', '0', '0', '0', '0', '0'};
|
||||
|
||||
RAM uint8_t advertising_data[] = {
|
||||
/*Description*/16, 0x16, 0x1a, 0x18,
|
||||
/*MAC*/0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
/*Temp*/0xaa, 0xaa,
|
||||
/*Humi*/0xbb,
|
||||
/*BatL*/0xcc,
|
||||
/*BatM*/0xdd, 0xdd,
|
||||
/*Counter*/0x00
|
||||
RAM uint8_t blt_rxfifo_b[64 * 8] = {0};
|
||||
RAM my_fifo_t blt_rxfifo = {
|
||||
64,
|
||||
8,
|
||||
0,
|
||||
0,
|
||||
blt_rxfifo_b,
|
||||
};
|
||||
|
||||
RAM uint8_t blt_txfifo_b[40 * 16] = {0};
|
||||
RAM my_fifo_t blt_txfifo = {
|
||||
40,
|
||||
16,
|
||||
0,
|
||||
0,
|
||||
blt_txfifo_b,
|
||||
};
|
||||
|
||||
RAM uint8_t ble_name[] = {11, 0x09, 'E', 'S', 'L', '_', '0', '0', '0', '0', '0', '0'};
|
||||
|
||||
RAM uint8_t advertising_data[] = {
|
||||
/*Description*/ 16, 0x16, 0x1a, 0x18,
|
||||
/*MAC*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
/*Temp*/ 0xaa, 0xaa,
|
||||
/*Humi*/ 0xbb,
|
||||
/*BatL*/ 0xcc,
|
||||
/*BatM*/ 0xdd, 0xdd,
|
||||
/*Counter*/ 0x00};
|
||||
|
||||
uint8_t mac_public[6];
|
||||
|
||||
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_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)
|
||||
void ble_disconnect_callback(uint8_t e, uint8_t *p, int n)
|
||||
{
|
||||
ble_connected = 0;
|
||||
ota_started = 0;
|
||||
printf("BLE disconnected\r\n");
|
||||
}
|
||||
|
||||
_attribute_ram_code_ void user_set_rf_power (uint8_t e, uint8_t *p, int n)
|
||||
_attribute_ram_code_ void user_set_rf_power(uint8_t e, uint8_t *p, int n)
|
||||
{
|
||||
rf_set_power_level_index (RF_POWER_P3p01dBm);
|
||||
rf_set_power_level_index(RF_POWER_P3p01dBm);
|
||||
}
|
||||
|
||||
void ble_connect_callback(uint8_t e, uint8_t *p, int n)
|
||||
{
|
||||
ble_connected = 1;
|
||||
bls_l2cap_requestConnParamUpdate(15, 15, 0, 1000); //1S
|
||||
ota_started = 0;
|
||||
ble_set_connection_speed(200);
|
||||
printf("BLE connected\r\n");
|
||||
}
|
||||
|
||||
int otaWritePre(void * p)
|
||||
{
|
||||
void ble_set_connection_speed(uint16_t speed)
|
||||
{
|
||||
bls_l2cap_requestConnParamUpdate(speed, speed + 2, 0, 2000);
|
||||
}
|
||||
|
||||
int otaWritePre(void *p)
|
||||
{
|
||||
if (ota_started == 0)
|
||||
{
|
||||
ota_started = 1;
|
||||
ble_set_connection_speed(6);
|
||||
}
|
||||
return custom_otaWrite(p);
|
||||
}
|
||||
|
||||
int RxTxWrite(void * p)
|
||||
int RxTxWrite(void *p)
|
||||
{
|
||||
cmd_parser(p);
|
||||
return 0;
|
||||
@@ -75,89 +99,95 @@ int RxTxWrite(void * p)
|
||||
|
||||
_attribute_ram_code_ void blt_pm_proc(void)
|
||||
{
|
||||
bls_pm_setSuspendMask (SUSPEND_ADV | DEEPSLEEP_RETENTION_ADV | SUSPEND_CONN | DEEPSLEEP_RETENTION_CONN);
|
||||
bls_pm_setSuspendMask(SUSPEND_ADV | DEEPSLEEP_RETENTION_ADV | SUSPEND_CONN | DEEPSLEEP_RETENTION_CONN);
|
||||
}
|
||||
|
||||
void init_ble(){
|
||||
////////////////// BLE stack initialization ////////////////////////////////////
|
||||
uint8_t mac_random_static[6];
|
||||
void init_ble()
|
||||
{
|
||||
////////////////// BLE stack initialization ////////////////////////////////////
|
||||
uint8_t mac_random_static[6];
|
||||
blc_initMacAddress(CFG_ADR_MAC, mac_public, mac_random_static);
|
||||
|
||||
//Set the BLE Name to the last three MACs the first ones are always the same
|
||||
const char* hex_ascii = {"0123456789ABCDEF"};
|
||||
ble_name[6] = hex_ascii[mac_public[2]>>4];
|
||||
ble_name[7] = hex_ascii[mac_public[2] &0x0f];
|
||||
ble_name[8] = hex_ascii[mac_public[1]>>4];
|
||||
ble_name[9] = hex_ascii[mac_public[1] &0x0f];
|
||||
ble_name[10] = hex_ascii[mac_public[0]>>4];
|
||||
ble_name[11] = hex_ascii[mac_public[0] &0x0f];
|
||||
|
||||
|
||||
// Set the BLE Name to the last three MACs the first ones are always the same
|
||||
const char *hex_ascii = {"0123456789ABCDEF"};
|
||||
ble_name[6] = hex_ascii[mac_public[2] >> 4];
|
||||
ble_name[7] = hex_ascii[mac_public[2] & 0x0f];
|
||||
ble_name[8] = hex_ascii[mac_public[1] >> 4];
|
||||
ble_name[9] = hex_ascii[mac_public[1] & 0x0f];
|
||||
ble_name[10] = hex_ascii[mac_public[0] >> 4];
|
||||
ble_name[11] = hex_ascii[mac_public[0] & 0x0f];
|
||||
|
||||
advertising_data[4] = mac_public[5];
|
||||
advertising_data[5] = mac_public[4];
|
||||
advertising_data[6] = mac_public[3];
|
||||
advertising_data[7] = mac_public[2];
|
||||
advertising_data[8] = mac_public[1];
|
||||
advertising_data[9] = mac_public[0];
|
||||
|
||||
////// Controller Initialization //////////
|
||||
blc_ll_initBasicMCU(); //must
|
||||
blc_ll_initStandby_module(mac_public); //must
|
||||
blc_ll_initAdvertising_module(mac_public); //adv module: must for BLE slave,
|
||||
blc_ll_initConnection_module(); //connection module must for BLE slave/master
|
||||
blc_ll_initSlaveRole_module(); //slave module: must for BLE slave,
|
||||
blc_ll_initPowerManagement_module(); //pm module: optional
|
||||
|
||||
////// Host Initialization //////////
|
||||
|
||||
////// Controller Initialization //////////
|
||||
blc_ll_initBasicMCU(); // must
|
||||
blc_ll_initStandby_module(mac_public); // must
|
||||
blc_ll_initAdvertising_module(mac_public); // adv module: must for BLE slave,
|
||||
blc_ll_initConnection_module(); // connection module must for BLE slave/master
|
||||
blc_ll_initSlaveRole_module(); // slave module: must for BLE slave,
|
||||
blc_ll_initPowerManagement_module(); // pm module: optional
|
||||
|
||||
////// Host Initialization //////////
|
||||
blc_gap_peripheral_init();
|
||||
extern void my_att_init();
|
||||
my_att_init (); //gatt initialization
|
||||
blc_l2cap_register_handler (blc_l2cap_packet_receive);
|
||||
my_att_init(); // gatt initialization
|
||||
blc_l2cap_register_handler(blc_l2cap_packet_receive);
|
||||
blc_smp_setSecurityLevel(No_Security);
|
||||
|
||||
///////////////////// USER application initialization ///////////////////
|
||||
bls_ll_setScanRspData( (uint8_t *)ble_name, sizeof(ble_name));
|
||||
bls_ll_setAdvParam( ADVERTISING_INTERVAL, ADVERTISING_INTERVAL+50, ADV_TYPE_CONNECTABLE_UNDIRECTED, OWN_ADDRESS_PUBLIC, 0, NULL, BLT_ENABLE_ADV_ALL, ADV_FP_NONE);
|
||||
|
||||
///////////////////// USER application initialization ///////////////////
|
||||
bls_ll_setScanRspData((uint8_t *)ble_name, sizeof(ble_name));
|
||||
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);
|
||||
user_set_rf_power(0, 0, 0);
|
||||
bls_app_registerEventCallback (BLT_EV_FLAG_SUSPEND_EXIT, &user_set_rf_power);
|
||||
bls_app_registerEventCallback (BLT_EV_FLAG_CONNECT, &ble_connect_callback);
|
||||
bls_app_registerEventCallback (BLT_EV_FLAG_TERMINATE, &ble_disconnect_callback);
|
||||
|
||||
///////////////////// Power Management initialization///////////////////
|
||||
bls_app_registerEventCallback(BLT_EV_FLAG_SUSPEND_EXIT, &user_set_rf_power);
|
||||
bls_app_registerEventCallback(BLT_EV_FLAG_CONNECT, &ble_connect_callback);
|
||||
bls_app_registerEventCallback(BLT_EV_FLAG_TERMINATE, &ble_disconnect_callback);
|
||||
|
||||
///////////////////// Power Management initialization///////////////////
|
||||
blc_ll_initPowerManagement_module();
|
||||
bls_pm_setSuspendMask (SUSPEND_ADV | DEEPSLEEP_RETENTION_ADV | SUSPEND_CONN | DEEPSLEEP_RETENTION_CONN);
|
||||
bls_pm_setSuspendMask(SUSPEND_ADV | DEEPSLEEP_RETENTION_ADV | SUSPEND_CONN | DEEPSLEEP_RETENTION_CONN);
|
||||
blc_pm_setDeepsleepRetentionThreshold(95, 95);
|
||||
blc_pm_setDeepsleepRetentionEarlyWakeupTiming(240);
|
||||
blc_pm_setDeepsleepRetentionType(DEEPSLEEP_MODE_RET_SRAM_LOW32K);
|
||||
blc_att_setRxMtuSize(250);
|
||||
}
|
||||
|
||||
bool ble_get_connected(){
|
||||
bool ble_get_connected()
|
||||
{
|
||||
return ble_connected;
|
||||
}
|
||||
|
||||
void set_adv_data(int16_t temp, uint16_t humi, uint8_t battery_level, uint16_t battery_mv){
|
||||
advertising_data[10] = temp>>8;
|
||||
advertising_data[11] = temp&0xff;
|
||||
|
||||
advertising_data[12] = humi&0xff;
|
||||
|
||||
advertising_data[13] = battery_level;
|
||||
|
||||
advertising_data[14] = battery_mv>>8;
|
||||
advertising_data[15] = battery_mv&0xff;
|
||||
|
||||
advertising_data[16]++;
|
||||
|
||||
bls_ll_setAdvData( (uint8_t *)advertising_data, sizeof(advertising_data));
|
||||
void set_adv_data(int16_t temp, uint16_t humi, uint8_t battery_level, uint16_t battery_mv)
|
||||
{
|
||||
advertising_data[10] = temp >> 8;
|
||||
advertising_data[11] = temp & 0xff;
|
||||
|
||||
advertising_data[12] = humi & 0xff;
|
||||
|
||||
advertising_data[13] = battery_level;
|
||||
|
||||
advertising_data[14] = battery_mv >> 8;
|
||||
advertising_data[15] = battery_mv & 0xff;
|
||||
|
||||
advertising_data[16]++;
|
||||
|
||||
bls_ll_setAdvData((uint8_t *)advertising_data, sizeof(advertising_data));
|
||||
}
|
||||
|
||||
void ble_send_temp(uint16_t temp){
|
||||
void ble_send_temp(uint16_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){
|
||||
void ble_send_battery(uint8_t value)
|
||||
{
|
||||
my_batVal[0] = value;
|
||||
bls_att_pushNotifyData(BATT_LEVEL_INPUT_DP_H, (uint8_t *)my_batVal, 1);
|
||||
}
|
||||
|
||||
@@ -11,4 +11,5 @@ void ble_send_battery(uint8_t value);
|
||||
void blt_pm_proc(void);
|
||||
|
||||
int RxTxWrite(void * p);
|
||||
int otaWritePre(void * p);
|
||||
int otaWritePre(void * p);
|
||||
void ble_set_connection_speed(uint16_t speed);
|
||||
|
||||
@@ -92,82 +92,46 @@ _attribute_ram_code_ void EPD_LoadImage(unsigned char *image, int size)
|
||||
|
||||
_attribute_ram_code_ void init_epd()
|
||||
{
|
||||
// reset pin configuration
|
||||
gpio_set_func(EPD_RESET, AS_GPIO);
|
||||
gpio_set_output_en(EPD_RESET, 1);
|
||||
gpio_set_input_en(EPD_RESET, 0);
|
||||
gpio_write(EPD_RESET, 0);
|
||||
// BS1 pin configuration
|
||||
// EPD power supply control pin configuration
|
||||
gpio_set_func(EPD_ENABLE, AS_GPIO);
|
||||
gpio_set_output_en(EPD_ENABLE, 1);
|
||||
gpio_set_input_en(EPD_ENABLE, 0);
|
||||
gpio_write(EPD_ENABLE, 1);
|
||||
// EPD Data/Command control pin configuration
|
||||
gpio_setup_up_down_resistor(EPD_RESET, PM_PIN_PULLUP_1M);
|
||||
|
||||
gpio_set_func(EPD_DC, AS_GPIO);
|
||||
gpio_set_output_en(EPD_DC, 1);
|
||||
gpio_set_input_en(EPD_DC, 0);
|
||||
gpio_write(EPD_DC, 0);
|
||||
// EPD Busy Status pin configuratioin
|
||||
gpio_setup_up_down_resistor(EPD_DC, PM_PIN_PULLUP_1M);
|
||||
|
||||
gpio_set_func(EPD_BUSY, AS_GPIO);
|
||||
gpio_set_output_en(EPD_BUSY, 0);
|
||||
gpio_set_input_en(EPD_BUSY, 1);
|
||||
gpio_setup_up_down_resistor(EPD_BUSY, PM_PIN_PULLUP_1M);
|
||||
|
||||
// cs pin configuration
|
||||
gpio_set_func(EPD_CS, AS_GPIO);
|
||||
gpio_set_output_en(EPD_CS, 1);
|
||||
gpio_set_input_en(EPD_CS, 0);
|
||||
gpio_write(EPD_CS, 1);
|
||||
// clk pin configuration
|
||||
gpio_setup_up_down_resistor(EPD_CS, PM_PIN_PULLUP_1M);
|
||||
|
||||
gpio_set_func(EPD_CLK, AS_GPIO);
|
||||
gpio_set_output_en(EPD_CLK, 1);
|
||||
gpio_set_input_en(EPD_CLK, 0);
|
||||
gpio_write(EPD_CLK, 0);
|
||||
// DO pin configuration
|
||||
gpio_setup_up_down_resistor(EPD_CLK, PM_PIN_PULLUP_1M);
|
||||
|
||||
gpio_set_func(EPD_MOSI, AS_GPIO);
|
||||
gpio_set_output_en(EPD_MOSI, 1);
|
||||
gpio_set_input_en(EPD_MOSI, 0);
|
||||
gpio_write(EPD_MOSI, 1);
|
||||
gpio_setup_up_down_resistor(EPD_MOSI, PM_PIN_PULLUP_1M);
|
||||
|
||||
// gpio_set_func(EPD_ENABLE, AS_GPIO);
|
||||
gpio_set_output_en(EPD_ENABLE, 0);
|
||||
gpio_set_input_en(EPD_ENABLE, 1);
|
||||
// gpio_shutdown(EPD_ENABLE);
|
||||
gpio_setup_up_down_resistor(EPD_ENABLE, PM_PIN_PULLUP_1M);
|
||||
}
|
||||
|
||||
_attribute_ram_code_ void deinit_epd(void)
|
||||
{
|
||||
// GPIO_AllTurnOff();
|
||||
gpio_set_func(EPD_RESET, AS_GPIO);
|
||||
gpio_setup_up_down_resistor(EPD_RESET, PM_PIN_PULLUP_10K);
|
||||
gpio_set_output_en(EPD_RESET, 0);
|
||||
gpio_set_input_en(EPD_RESET, 1);
|
||||
gpio_setup_up_down_resistor(EPD_RESET, PM_PIN_PULLUP_10K);
|
||||
// EPD power supply control pin configuration
|
||||
gpio_set_func(EPD_ENABLE, AS_GPIO);
|
||||
gpio_setup_up_down_resistor(EPD_ENABLE, PM_PIN_PULLDOWN_100K);
|
||||
gpio_set_output_en(EPD_ENABLE, 0);
|
||||
gpio_set_input_en(EPD_ENABLE, 1);
|
||||
gpio_setup_up_down_resistor(EPD_ENABLE, PM_PIN_PULLDOWN_100K);
|
||||
// EPD Data/Command control pin configuration
|
||||
gpio_set_func(EPD_DC, AS_GPIO);
|
||||
gpio_set_output_en(EPD_DC, 0);
|
||||
gpio_set_input_en(EPD_DC, 1);
|
||||
gpio_setup_up_down_resistor(EPD_DC, PM_PIN_PULLUP_1M);
|
||||
// EPD Busy Status pin configuratioin
|
||||
gpio_set_func(EPD_BUSY, AS_GPIO);
|
||||
gpio_set_output_en(EPD_BUSY, 0);
|
||||
gpio_set_input_en(EPD_BUSY, 1);
|
||||
gpio_setup_up_down_resistor(EPD_BUSY, PM_PIN_PULLDOWN_100K); // turn off pull-up resistor
|
||||
// Turn off all SPI IOs
|
||||
gpio_set_func(EPD_CS, AS_GPIO);
|
||||
gpio_set_output_en(EPD_CS, 0);
|
||||
gpio_set_input_en(EPD_CS, 1);
|
||||
gpio_setup_up_down_resistor(EPD_CS, PM_PIN_PULLUP_1M);
|
||||
gpio_set_func(EPD_CLK, AS_GPIO);
|
||||
gpio_set_output_en(EPD_CLK, 0);
|
||||
gpio_set_input_en(EPD_CLK, 1);
|
||||
gpio_setup_up_down_resistor(EPD_CLK, PM_PIN_PULLDOWN_100K);
|
||||
gpio_set_func(EPD_MOSI, AS_GPIO);
|
||||
gpio_set_output_en(EPD_MOSI, 0);
|
||||
gpio_set_input_en(EPD_MOSI, 1);
|
||||
gpio_setup_up_down_resistor(EPD_MOSI, PM_PIN_PULLDOWN_100K);
|
||||
gpio_shutdown(EPD_RESET);
|
||||
gpio_shutdown(EPD_DC);
|
||||
gpio_shutdown(EPD_CS);
|
||||
gpio_shutdown(EPD_CLK);
|
||||
gpio_shutdown(EPD_MOSI);
|
||||
gpio_shutdown(EPD_BUSY);
|
||||
}
|
||||
|
||||
_attribute_ram_code_ void EPD_Display(unsigned char *image, int size)
|
||||
@@ -212,13 +176,11 @@ _attribute_ram_code_ void EPD_Display(unsigned char *image, int size)
|
||||
// trigger display refresh
|
||||
EPD_WriteCmd(0x12);
|
||||
|
||||
deinit_epd();
|
||||
epd_update_state = 1;
|
||||
}
|
||||
|
||||
_attribute_ram_code_ void epd_set_sleep()
|
||||
{
|
||||
init_epd();
|
||||
// Vcom and data interval setting
|
||||
EPD_WriteCmd(0x50);
|
||||
EPD_WriteData(0xf7);
|
||||
@@ -267,26 +229,29 @@ _attribute_ram_code_ void FixBuffer(uint8_t *pSrc, uint8_t *pDst)
|
||||
|
||||
_attribute_ram_code_ void TIFFDraw(TIFFDRAW *pDraw)
|
||||
{
|
||||
uint8_t uc=0, ucSrcMask, ucDstMask, *s, *d;
|
||||
int x, y;
|
||||
uint8_t uc = 0, ucSrcMask, ucDstMask, *s, *d;
|
||||
int x, y;
|
||||
|
||||
s = pDraw->pPixels;
|
||||
y = pDraw->y; // current line
|
||||
d = &epd_buffer[(249*16)+(y/8)]; // rotated 90 deg clockwise
|
||||
ucDstMask = 0x80 >> (y & 7); // destination mask
|
||||
ucSrcMask = 0; // src mask
|
||||
for (x=0; x<pDraw->iWidth; x++) {
|
||||
// Slower to draw this way, but it allows us to use a single buffer
|
||||
// instead of drawing and then converting the pixels to be the EPD format
|
||||
if (ucSrcMask == 0) { // load next source byte
|
||||
ucSrcMask = 0x80;
|
||||
uc = *s++;
|
||||
}
|
||||
if (!(uc & ucSrcMask)) { // black pixel
|
||||
d[-(x*16)] &= ~ucDstMask;
|
||||
}
|
||||
ucSrcMask >>= 1;
|
||||
}
|
||||
s = pDraw->pPixels;
|
||||
y = pDraw->y; // current line
|
||||
d = &epd_buffer[(249 * 16) + (y / 8)]; // rotated 90 deg clockwise
|
||||
ucDstMask = 0x80 >> (y & 7); // destination mask
|
||||
ucSrcMask = 0; // src mask
|
||||
for (x = 0; x < pDraw->iWidth; x++)
|
||||
{
|
||||
// Slower to draw this way, but it allows us to use a single buffer
|
||||
// instead of drawing and then converting the pixels to be the EPD format
|
||||
if (ucSrcMask == 0)
|
||||
{ // load next source byte
|
||||
ucSrcMask = 0x80;
|
||||
uc = *s++;
|
||||
}
|
||||
if (!(uc & ucSrcMask))
|
||||
{ // black pixel
|
||||
d[-(x * 16)] &= ~ucDstMask;
|
||||
}
|
||||
ucSrcMask >>= 1;
|
||||
}
|
||||
} /* TIFFDraw() */
|
||||
|
||||
_attribute_ram_code_ void epd_display_tiff(uint8_t *pData, int iSize)
|
||||
@@ -308,7 +273,7 @@ _attribute_ram_code_ void epd_display(uint32_t time_is)
|
||||
obdFill(&obd, 0, 0); // fill with white
|
||||
|
||||
char buff[25];
|
||||
sprintf(buff,"%02d:%02d:%02d",((time_is/60)/60)%24,(time_is/60)%60,time_is%60);
|
||||
sprintf(buff, "%02d:%02d:%02d", ((time_is / 60) / 60) % 24, (time_is / 60) % 60, time_is % 60);
|
||||
obdWriteStringCustom(&obd, (GFXfont *)&DSEG14_Classic_Mini_Regular_40, 10, 45, (char *)buff, 1);
|
||||
obdWriteStringCustom(&obd, (GFXfont *)&Roboto_Black_80, 0, 120, (char *)"Time", 1);
|
||||
FixBuffer(epd_temp, epd_buffer);
|
||||
|
||||
@@ -8,49 +8,55 @@
|
||||
|
||||
extern uint8_t *epd_temp;
|
||||
|
||||
#define ASSERT_MIN_LEN(val, min_len) \
|
||||
if (val < min_len) { \
|
||||
return 0; \
|
||||
#define ASSERT_MIN_LEN(val, min_len) \
|
||||
if (val < min_len) \
|
||||
{ \
|
||||
return 0; \
|
||||
}
|
||||
|
||||
unsigned char image[epd_buffer_size];
|
||||
unsigned int byte_pos = 0;
|
||||
|
||||
int epd_ble_handle_write(void * p) {
|
||||
rf_packet_att_write_t *req = (rf_packet_att_write_t*) p;
|
||||
int epd_ble_handle_write(void *p)
|
||||
{
|
||||
rf_packet_att_write_t *req = (rf_packet_att_write_t *)p;
|
||||
uint8_t *payload = &req->value;
|
||||
unsigned int payload_len = req->l2capLen - 3;
|
||||
|
||||
ASSERT_MIN_LEN(payload_len, 1);
|
||||
|
||||
switch (payload[0]) {
|
||||
// Clear EPD display.
|
||||
case 0x00:
|
||||
ASSERT_MIN_LEN(payload_len, 2);
|
||||
memset(image, payload[1], sizeof(image));
|
||||
return 0;
|
||||
// Push buffer to display.
|
||||
case 0x01:
|
||||
EPD_Display(image, epd_buffer_size);
|
||||
return 0;
|
||||
// Set byte_pos.
|
||||
case 0x02:
|
||||
ASSERT_MIN_LEN(payload_len, 3);
|
||||
byte_pos = payload[1] << 8 | payload[2];
|
||||
return 0;
|
||||
// Write data to image buffer.
|
||||
case 0x03:
|
||||
if (byte_pos + payload_len - 1 >= sizeof(image)+1) {
|
||||
return 0;
|
||||
}
|
||||
memcpy(image + byte_pos, payload + 1, payload_len - 1);
|
||||
byte_pos += payload_len - 1;
|
||||
return 0;
|
||||
case 0x04: // decode & display a TIFF image
|
||||
epd_display_tiff(image, byte_pos);
|
||||
return 0;
|
||||
default:
|
||||
switch (payload[0])
|
||||
{
|
||||
// Clear EPD display.
|
||||
case 0x00:
|
||||
ASSERT_MIN_LEN(payload_len, 2);
|
||||
memset(image, payload[1], sizeof(image));
|
||||
ble_set_connection_speed(40);
|
||||
return 0;
|
||||
// Push buffer to display.
|
||||
case 0x01:
|
||||
ble_set_connection_speed(200);
|
||||
EPD_Display(image, epd_buffer_size);
|
||||
return 0;
|
||||
// Set byte_pos.
|
||||
case 0x02:
|
||||
ASSERT_MIN_LEN(payload_len, 3);
|
||||
byte_pos = payload[1] << 8 | payload[2];
|
||||
return 0;
|
||||
// Write data to image buffer.
|
||||
case 0x03:
|
||||
if (byte_pos + payload_len - 1 >= sizeof(image) + 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
memcpy(image + byte_pos, payload + 1, payload_len - 1);
|
||||
byte_pos += payload_len - 1;
|
||||
return 0;
|
||||
case 0x04: // decode & display a TIFF image
|
||||
epd_display_tiff(image, byte_pos);
|
||||
return 0;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -10,17 +10,20 @@ void init_led()
|
||||
{
|
||||
gpio_set_func(LED_BLUE, AS_GPIO);
|
||||
gpio_set_output_en(LED_BLUE, 1);
|
||||
gpio_write(LED_BLUE, 1);
|
||||
gpio_setup_up_down_resistor(LED_BLUE, PM_PIN_PULLUP_10K);
|
||||
|
||||
gpio_set_func(LED_RED, AS_GPIO);
|
||||
gpio_set_output_en(LED_RED, 1);
|
||||
gpio_write(LED_RED, 1);
|
||||
gpio_setup_up_down_resistor(LED_RED, PM_PIN_PULLUP_10K);
|
||||
|
||||
gpio_set_func(LED_GREEN, AS_GPIO);
|
||||
gpio_set_output_en(LED_GREEN, 1);
|
||||
gpio_write(LED_GREEN, 1);
|
||||
gpio_setup_up_down_resistor(LED_GREEN, PM_PIN_PULLUP_10K);
|
||||
}
|
||||
|
||||
void set_led_color(uint8_t color)
|
||||
{
|
||||
init_led();
|
||||
switch (color)
|
||||
{
|
||||
case 1:
|
||||
@@ -45,25 +48,3 @@ void set_led_color(uint8_t color)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void deinit_led()
|
||||
{
|
||||
// LED_BLUE();
|
||||
gpio_set_func(LED_BLUE, AS_GPIO);
|
||||
gpio_setup_up_down_resistor(LED_BLUE, PM_PIN_PULLUP_1M);
|
||||
gpio_set_output_en(LED_BLUE, 0);
|
||||
gpio_set_input_en(LED_BLUE, 1);
|
||||
gpio_setup_up_down_resistor(LED_BLUE, PM_PIN_PULLUP_1M);
|
||||
// LED_RED();
|
||||
gpio_set_func(LED_RED, AS_GPIO);
|
||||
gpio_setup_up_down_resistor(LED_RED, PM_PIN_PULLUP_1M);
|
||||
gpio_set_output_en(LED_RED, 0);
|
||||
gpio_set_input_en(LED_RED, 1);
|
||||
gpio_setup_up_down_resistor(LED_RED, PM_PIN_PULLUP_1M);
|
||||
// LED_GREEN();
|
||||
gpio_set_func(LED_GREEN, AS_GPIO);
|
||||
gpio_setup_up_down_resistor(LED_GREEN, PM_PIN_PULLUP_1M);
|
||||
gpio_set_output_en(LED_GREEN, 0);
|
||||
gpio_set_input_en(LED_GREEN, 1);
|
||||
gpio_setup_up_down_resistor(LED_GREEN, PM_PIN_PULLUP_1M);
|
||||
}
|
||||
@@ -2,4 +2,3 @@
|
||||
|
||||
void init_led();
|
||||
void set_led_color(uint8_t color);
|
||||
void deinit_led();
|
||||
@@ -39,9 +39,6 @@ _attribute_ram_code_ int main (void) //must run in ramcode
|
||||
|
||||
init_uart();
|
||||
init_i2c();
|
||||
init_nfc();
|
||||
init_led();
|
||||
deinit_epd();// DeInit EPD GPIOs for low power
|
||||
|
||||
if( deepRetWakeUp ){
|
||||
user_init_deepRetn ();
|
||||
|
||||
@@ -8,40 +8,13 @@
|
||||
|
||||
_attribute_ram_code_ void init_nfc()
|
||||
{
|
||||
gpio_set_func(NFC_SDA, AS_GPIO);
|
||||
gpio_set_output_en(NFC_SDA, 1);
|
||||
gpio_write(NFC_SDA, 1);
|
||||
gpio_set_func(NFC_SCL, AS_GPIO);
|
||||
gpio_set_output_en(NFC_SCL, 1);
|
||||
gpio_write(NFC_SCL, 1);
|
||||
gpio_set_func(NFC_CS, AS_GPIO);
|
||||
gpio_set_output_en(NFC_CS, 1);
|
||||
gpio_write(NFC_CS, 1);
|
||||
gpio_set_func(NFC_IRQ, AS_GPIO);
|
||||
gpio_set_input_en(NFC_IRQ, 1);
|
||||
gpio_set_output_en(NFC_IRQ, 0);
|
||||
}
|
||||
gpio_set_input_en(NFC_CS, 0);
|
||||
gpio_setup_up_down_resistor(NFC_CS, PM_PIN_PULLUP_10K);
|
||||
|
||||
_attribute_ram_code_ void deinit_nfc()
|
||||
{
|
||||
// NFC_SDA
|
||||
gpio_set_func(NFC_SDA, AS_GPIO);
|
||||
gpio_set_output_en(NFC_SDA, 0);
|
||||
gpio_set_input_en(NFC_SDA, 1);
|
||||
gpio_setup_up_down_resistor(NFC_SDA, PM_PIN_PULLDOWN_100K);
|
||||
// NFC_SCL
|
||||
gpio_set_func(NFC_SCL, AS_GPIO);
|
||||
gpio_set_output_en(NFC_SCL, 0);
|
||||
gpio_set_input_en(NFC_SCL, 1);
|
||||
gpio_setup_up_down_resistor(NFC_SCL, PM_PIN_PULLDOWN_100K);
|
||||
// NFC_CS
|
||||
gpio_set_func(NFC_CS, AS_GPIO);
|
||||
gpio_set_output_en(NFC_CS, 0);
|
||||
gpio_set_input_en(NFC_CS, 1);
|
||||
gpio_setup_up_down_resistor(NFC_CS, PM_PIN_PULLUP_1M);
|
||||
// NFC_IRQ
|
||||
gpio_set_func(NFC_IRQ, AS_GPIO);
|
||||
gpio_set_output_en(NFC_IRQ, 0);
|
||||
gpio_set_input_en(NFC_IRQ, 1);
|
||||
gpio_setup_up_down_resistor(NFC_IRQ, PM_PIN_PULLDOWN_100K); // turn off pull-up resistor
|
||||
}
|
||||
gpio_set_output_en(NFC_IRQ, 1);
|
||||
gpio_set_input_en(NFC_IRQ, 0);
|
||||
gpio_setup_up_down_resistor(NFC_IRQ, PM_PIN_PULLUP_10K);
|
||||
}
|
||||
|
||||
@@ -3,4 +3,3 @@
|
||||
#include "main.h"
|
||||
|
||||
void init_nfc();
|
||||
void deinit_nfc();
|
||||
Reference in New Issue
Block a user