Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 42b44c5fa9 | |||
| 570ed42cbc | |||
| 6504da47ac | |||
| 208d62eb69 | |||
| 3a79e48919 | |||
| 5adfd81788 | |||
| 9e26e00462 | |||
| 898433816a | |||
| 7e2b3cee98 | |||
| 2610a9e00e | |||
| 9eea6cac7c | |||
| 2a46c5d026 | |||
| d2045fa63f | |||
| 36e7163bb3 | |||
| 1054988b16 | |||
| 7c708654cd | |||
| 496db61308 | |||
| a64d13f4e0 | |||
| c1132d321d | |||
| b7fa8b3c7a | |||
| 3cbc906806 | |||
| 50811fa214 | |||
| 1efe5c509e | |||
| bace7d6aab | |||
| 2045117015 | |||
| 45129ab0e6 | |||
| a486d79200 | |||
| 9d4a3fb54e | |||
| 0827b776ce | |||
| 206a8b5c5b | |||
| dd566be7b5 | |||
| aec34a874f | |||
| 707ec44894 | |||
| 77e34ea969 |
Binary file not shown.
+16
-6
@@ -5,16 +5,26 @@
|
||||
|
||||
#include <driverlib/aon_batmon.h>
|
||||
#define MAX_BATTERY_CAPACITY 4200
|
||||
static uint8_t battery_percent = 100;
|
||||
static uint8_t battery_volt = 256;
|
||||
|
||||
static uint8_t headstage_battery_percent() {
|
||||
static uint8_t headstage_battery_volt1() {
|
||||
uint8_t internal_battery_percent;
|
||||
uint32_t internal_batt_sense = AONBatMonBatteryVoltageGet();
|
||||
internal_batt_sense = (internal_batt_sense * 125) >> 5;
|
||||
internal_batt_sense = (internal_batt_sense * 100) / MAX_BATTERY_CAPACITY;
|
||||
// internal_batt_sense = (internal_batt_sense * 100) / MAX_BATTERY_CAPACITY;
|
||||
internal_battery_percent = internal_batt_sense & 0xff;
|
||||
if (internal_battery_percent < battery_percent) battery_percent = internal_battery_percent;
|
||||
return battery_percent;
|
||||
battery_volt = internal_battery_percent;
|
||||
return battery_volt;
|
||||
}
|
||||
|
||||
#endif // HEADSTAGE_BATT_H
|
||||
static uint8_t headstage_battery_volt2() {
|
||||
uint8_t internal_battery_percent;
|
||||
uint32_t internal_batt_sense = AONBatMonBatteryVoltageGet();
|
||||
internal_batt_sense = (internal_batt_sense * 125) >> 5;
|
||||
// internal_batt_sense = (internal_batt_sense * 100) / MAX_BATTERY_CAPACITY;
|
||||
internal_battery_percent = (internal_batt_sense >> 8) & 0xff;
|
||||
battery_volt = internal_battery_percent;
|
||||
return battery_volt;
|
||||
}
|
||||
|
||||
#endif // HEADSTAGE_BATT_H
|
||||
+106
-19
@@ -773,11 +773,13 @@ static void headstage_update_vis_instruction(uint8_t vis_oper) {
|
||||
case VIS_RST:
|
||||
headstage_reset();
|
||||
headstage_state = UMC_STATE_HANDSHAKE;
|
||||
INSTRUCTION.channel_pointer=0;
|
||||
// try to pull PIN_RESET PIN to ground
|
||||
break;
|
||||
case VIS_STI:
|
||||
if (headstage_state == UMC_STATE_INTERRUPT) {
|
||||
if (headstage_state == UMC_STATE_INTERRUPT) { //This if cond. seems only for old version digital core
|
||||
headstage_state = UMC_STATE_INITIAL;
|
||||
INSTRUCTION.channel_pointer = 0;
|
||||
rearrange_channel_mux_table();
|
||||
UMC_STATE.config_type = CONFIG_AMP_MUX;
|
||||
headstage_led_spi_color(COLOR_BLACK);
|
||||
@@ -785,6 +787,7 @@ static void headstage_update_vis_instruction(uint8_t vis_oper) {
|
||||
headstage_spi_ask_transaction(4);
|
||||
} else {
|
||||
headstage_state = UMC_STATE_HANDSHAKE;
|
||||
INSTRUCTION.channel_pointer = 0;
|
||||
rearrange_channel_mux_table();
|
||||
headstage_pwm_start(headstage_system_pwm_handle);
|
||||
headstage_pwm_start(headstage_poly_r_pwm_handle);
|
||||
@@ -800,6 +803,7 @@ static void headstage_update_vis_instruction(uint8_t vis_oper) {
|
||||
case VIS_INT:
|
||||
headstage_reset();
|
||||
headstage_state = UMC_STATE_HANDSHAKE;
|
||||
INSTRUCTION.channel_pointer = 0;
|
||||
break;
|
||||
|
||||
case VIS_BLE_T:
|
||||
@@ -834,7 +838,8 @@ static void headstage_update_cis_instruction(uint8_t cis_oper) {
|
||||
case CIS_VOLT: {
|
||||
|
||||
cdr_buf[0] = CIS_VOLT | CHIP_ID;
|
||||
cdr_buf[1] = headstage_battery_percent();
|
||||
cdr_buf[1] = headstage_battery_volt1();
|
||||
cdr_buf[2] = headstage_battery_volt2();
|
||||
|
||||
SimpleProfile_SetParameter(BLE_CDR_BUFF_CHAR, BLE_CDR_BUFF_SIZE, cdr_buf);
|
||||
|
||||
@@ -875,37 +880,119 @@ static uint8_t headstage_debug_instruction(uint8_t* ins_buf) {
|
||||
|
||||
// todo: check data length extension with this function -> this function should be
|
||||
static void headstage_uni_umc_data_append_notify_buffer(uint8_t* dat_buf) {
|
||||
// check LSK data preamble ( 0b01100_0001 ) 58(01011000) 2c(00101100)
|
||||
// check LSK data preamble ( 9b01100_0001 ) header 58(0101xxxx)
|
||||
// if (channel == INSTRUCTION.last_enable_channel) : preamble + header + 10b data
|
||||
// else: 9b00000_0000 + header + 10b data
|
||||
// sometimes we lose the first bit , it means we only receive
|
||||
// 0110_0000_1010_1xxx_xxxx_xxxX_XXXX_XXXX and
|
||||
// 1100_0001_0101_xxxx_xxxx_xxXX_XXXX_XXXX
|
||||
if (((dat_buf[0] & 0xC1) != 0xC1) && (dat_buf[0] != 0x00)) {
|
||||
headstage_led_spi_color(COLOR_CYAN);
|
||||
headstage_uni_delay();
|
||||
headstage_led_spi_color(COLOR_CYAN);
|
||||
if ((dat_buf[1] & 0x28) == 0x28) {
|
||||
dat_buf[0] = (dat_buf[0] << 1) | ((dat_buf[1] >> 7) & 0x01);
|
||||
dat_buf[1] = (dat_buf[1] << 1) | ((dat_buf[2] >> 7) & 0x01);
|
||||
dat_buf[2] = (dat_buf[2] << 1) | ((dat_buf[3] >> 7) & 0x01);
|
||||
}
|
||||
//headstage_uni_delay();
|
||||
} else {
|
||||
if ((dat_buf[1] & 0x28) == 0x28) {
|
||||
dat_buf[0] = (dat_buf[0] << 1) | ((dat_buf[1] >> 7) & 0x01);
|
||||
dat_buf[1] = (dat_buf[1] << 1) | ((dat_buf[2] >> 7) & 0x01);
|
||||
dat_buf[2] = (dat_buf[2] << 1) | ((dat_buf[3] >> 7) & 0x01);
|
||||
if ((dat_buf[1] & 0x28) == 0x28) {
|
||||
dat_buf[0] = (dat_buf[0] << 1) | ((dat_buf[1] >> 7) & 0x01);
|
||||
dat_buf[1] = (dat_buf[1] << 1) | ((dat_buf[2] >> 7) & 0x01);
|
||||
dat_buf[2] = (dat_buf[2] << 1) | ((dat_buf[3] >> 7) & 0x01);
|
||||
}
|
||||
}
|
||||
//headstage_led_spi_color(COLOR_CYAN);
|
||||
uint8_t channel;
|
||||
uint8_t channel_pointer = INSTRUCTION.channel_pointer;
|
||||
uint8_t pramb;
|
||||
|
||||
switch (INSTRUCTION.enable_channel_number){
|
||||
case 1:
|
||||
pramb = 0;
|
||||
channel = reverse_channel[INSTRUCTION.channel_mux[channel_pointer]];
|
||||
break;
|
||||
case 2:
|
||||
if ((dat_buf[0] & 0xC1) == 0xC1) {
|
||||
channel = reverse_channel[INSTRUCTION.last_enable_channel];
|
||||
}
|
||||
//else if (dat_buf[0] == 0 && pramb == 0) {}
|
||||
else{
|
||||
if(channel_pointer==0 && INSTRUCTION.channel_mux[channel_pointer]==INSTRUCTION.last_enable_channel)
|
||||
{channel_pointer++;}
|
||||
|
||||
if ((INSTRUCTION.last_enable_channel%2) == 0)
|
||||
if (channel_pointer == INSTRUCTION.last_enable_channel)
|
||||
{channel = reverse_channel[INSTRUCTION.channel_mux[channel_pointer - 1]];}
|
||||
else
|
||||
{channel = reverse_channel[INSTRUCTION.channel_mux[channel_pointer + 1]];}
|
||||
else
|
||||
{channel = reverse_channel[INSTRUCTION.channel_mux[channel_pointer]];}
|
||||
}
|
||||
channel_pointer++;
|
||||
INSTRUCTION.channel_pointer = channel_pointer % (INSTRUCTION.last_enable_channel+1);
|
||||
break;
|
||||
//case 3:
|
||||
// if ((dat_buf[0] & 0xC1) == 0xC1) {
|
||||
// channel = reverse_channel[INSTRUCTION.last_enable_channel];
|
||||
// }
|
||||
// else {
|
||||
|
||||
// channel = reverse_channel[INSTRUCTION.channel_mux[channel_pointer]];
|
||||
// }
|
||||
// channel_pointer++;
|
||||
// INSTRUCTION.channel_pointer = channel_pointer % (INSTRUCTION.enable_channel_number);
|
||||
// break;
|
||||
default: // for enable_channel_num >4
|
||||
//expectation on preamble
|
||||
if (INSTRUCTION.channel_mux[channel_pointer] == INSTRUCTION.last_enable_channel){
|
||||
pramb=1;
|
||||
}
|
||||
else {
|
||||
pramb=0;
|
||||
}
|
||||
|
||||
uint8_t channel;
|
||||
uint8_t channel_pointer = INSTRUCTION.channel_pointer;
|
||||
|
||||
if ((INSTRUCTION.enable_channel_number == 1) || (dat_buf[0] == 0xc1)) {
|
||||
if ((dat_buf[0] & 0xC1) == 0xC1) {
|
||||
channel = reverse_channel[INSTRUCTION.last_enable_channel];
|
||||
} else {
|
||||
//uint8_t channel_pointer = (INSTRUCTION.channel_pointer + 1) % INSTRUCTION.last_enable_channel;
|
||||
channel = reverse_channel[INSTRUCTION.channel_mux[channel_pointer]];
|
||||
channel_pointer++;
|
||||
INSTRUCTION.channel_pointer = channel_pointer % INSTRUCTION.enable_channel_number;
|
||||
}
|
||||
else{
|
||||
if(channel_pointer==0 && INSTRUCTION.channel_mux[channel_pointer]==INSTRUCTION.last_enable_channel)
|
||||
{channel_pointer++;}
|
||||
|
||||
channel = reverse_channel[INSTRUCTION.channel_mux[channel_pointer]];
|
||||
}
|
||||
//else {
|
||||
// channel = reverse_channel[13];
|
||||
// //headstage_led_spi_color(COLOR_RED);
|
||||
//}
|
||||
|
||||
//if (channel <= INSTRUCTION.last_enable_channel){
|
||||
channel_pointer++;
|
||||
INSTRUCTION.channel_pointer = channel_pointer % (INSTRUCTION.last_enable_channel+1);
|
||||
//}
|
||||
break;
|
||||
}
|
||||
|
||||
//left shift the data buffer by 1 bit according to header position
|
||||
/*if (((dat_buf[0] & 0xC1) != 0xC1) && (dat_buf[0] != 0x00)) {
|
||||
// headstage_uni_delay();
|
||||
} else {
|
||||
*/
|
||||
|
||||
//if (channel < (INSTRUCTION.last_enable_channel+1)){
|
||||
uint8_t data_size = headstage_notify_append_data(channel, dat_buf);
|
||||
if (data_size >= BLE_NOT_BUFF_SIZE) {
|
||||
headstage_notify_flip_buffer();
|
||||
headstage_notify_send();
|
||||
}
|
||||
}
|
||||
//}
|
||||
/*else if (channel > INSTRUCTION.last_enable_channel){
|
||||
headstage_led_spi_color(COLOR_RED);
|
||||
channel_pointer = channel_pointer+2; //This line may not work for complex channel arrangement
|
||||
}*/
|
||||
//else{
|
||||
/* DO nothing */
|
||||
//}
|
||||
|
||||
// uint16_t data_value = (uint16_t)(((dat_buf[1] & 0x0F) << 6) | ((dat_buf[2] & 0xFC) >> 2));
|
||||
headstage_spi_lsk_transaction(3);
|
||||
}
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
|
||||
#ifndef VERSION_DATE
|
||||
#define VERSION_DATE
|
||||
|
||||
#define VERSION_DATE_YEAR 20
|
||||
#define VERSION_DATE_MONTH 2
|
||||
#define VERSION_DATE_DAY 14
|
||||
#define VERSION_DATE_HOUR 18
|
||||
#define VERSION_DATE_MINUTE 30
|
||||
|
||||
#endif
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>uni</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
+6
-4
@@ -408,8 +408,7 @@ static void SimpleBLEPeripheral_init(void) {
|
||||
GATT_RegisterForMsgs(self);
|
||||
|
||||
headstage_led_spi_color(COLOR_GREEN);
|
||||
HCI_LE_ReadMaxDataLenCmd();
|
||||
|
||||
// HCI_LE_ReadMaxDataLenCmd(); //YiChin said this command is not necessary
|
||||
HCI_LE_WriteSuggestedDefaultDataLenCmd(251, 2120); // this is used for data length extension
|
||||
|
||||
|
||||
@@ -511,7 +510,7 @@ static void headstage_init_device_info() {
|
||||
for (unsigned int i = 0; i < sizeof(DEVICE_NAME) - 1; i++) {
|
||||
*p++ = DEVICE_NAME[i];
|
||||
}
|
||||
*p++ = 15;
|
||||
*p++ = 16;
|
||||
*p++ = GAP_ADTYPE_MANUFACTURER_SPECIFIC;
|
||||
// unsafe_memcpy(p, "BPHS", 4);
|
||||
*p++ = 'B';
|
||||
@@ -527,7 +526,8 @@ static void headstage_init_device_info() {
|
||||
*p++ = 'B';
|
||||
*p++ = 'A';
|
||||
*p++ = 'T';
|
||||
*p++ = headstage_battery_percent();
|
||||
*p++ = headstage_battery_volt1();
|
||||
*p++ = headstage_battery_volt2();
|
||||
|
||||
|
||||
GGS_SetParameter(GGS_DEVICE_NAME_ATT, sizeof(DEVICE_NAME), DEVICE_NAME);
|
||||
@@ -847,6 +847,7 @@ static void SimpleBLEPeripheral_processStateChangeEvt(gaprole_States_t newState)
|
||||
case GAPROLE_WAITING:
|
||||
// Device is started but not advertising, is in waiting period before advertising again
|
||||
SimpleBLEPeripheral_freeAttRsp(bleNotConnected);
|
||||
headstage_led_spi_color(COLOR_GREEN);
|
||||
break;
|
||||
|
||||
case GAPROLE_WAITING_AFTER_TIMEOUT:
|
||||
@@ -862,6 +863,7 @@ static void SimpleBLEPeripheral_processStateChangeEvt(gaprole_States_t newState)
|
||||
break;
|
||||
case GAPROLE_INIT: // Waiting to be started
|
||||
case GAPROLE_ADVERTISING: // Currently Advertising
|
||||
headstage_led_spi_color(COLOR_GREEN);
|
||||
case GAPROLE_CONNECTED_ADV: // In a connection and advertising
|
||||
default:
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user