Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 09f640a461 | |||
| bd5db061cf | |||
| 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 | |||
| f4dbf99294 |
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
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
|
||||
+146
-22
@@ -702,6 +702,7 @@ static void headstage_init() {
|
||||
}
|
||||
|
||||
static void headstage_update_ris_instruction(uint8_t ins_len, uint8_t* instruction) {
|
||||
uint8_t fled;
|
||||
switch ((instruction[0] & 0xE0)) {
|
||||
case RIS_DIR: {
|
||||
uint8_t amp_lbf = (instruction[0] & 0b00000111);
|
||||
@@ -740,10 +741,43 @@ static void headstage_update_ris_instruction(uint8_t ins_len, uint8_t* instructi
|
||||
INSTRUCTION.sti_times = sti_times;
|
||||
INSTRUCTION.sti_freq = sti_freq;
|
||||
INSTRUCTION.mode = mode;
|
||||
if (instruction[3] & 0b10000000) INSTRUCTION.channel_table[amp_channel_table[cha] - 1] = TRUE;
|
||||
if (instruction[3] & 0b01000000) INSTRUCTION.channel_table[amp_channel_table[chb] - 1] = TRUE;
|
||||
if (instruction[3] & 0b00100000) INSTRUCTION.channel_table[amp_channel_table[chc] - 1] = TRUE;
|
||||
if (instruction[3] & 0b00010000) INSTRUCTION.channel_table[amp_channel_table[chd] - 1] = TRUE;
|
||||
if (instruction[3] & 0b10000000) {
|
||||
INSTRUCTION.channel_table[amp_channel_table[cha] - 1] = TRUE;
|
||||
for (fled=0; fled < amp_channel_table[cha]; fled++)
|
||||
{
|
||||
headstage_led_spi_color(COLOR_RED);
|
||||
CPUdelay(16000*500); //100ms
|
||||
headstage_led_spi_color(COLOR_GREEN);
|
||||
}
|
||||
}
|
||||
|
||||
if (instruction[3] & 0b01000000) {
|
||||
INSTRUCTION.channel_table[amp_channel_table[chb] - 1] = TRUE;
|
||||
for (fled=0; fled < amp_channel_table[chb]; fled++)
|
||||
{
|
||||
headstage_led_spi_color(COLOR_BLUE);
|
||||
CPUdelay(16000*500); //100ms
|
||||
headstage_led_spi_color(COLOR_GREEN);
|
||||
}
|
||||
}
|
||||
if (instruction[3] & 0b00100000) {
|
||||
INSTRUCTION.channel_table[amp_channel_table[chc] - 1] = TRUE;
|
||||
for (fled=0; fled < amp_channel_table[chc]; fled++)
|
||||
{
|
||||
headstage_led_spi_color(COLOR_RED);
|
||||
CPUdelay(16000*500); //100ms
|
||||
headstage_led_spi_color(COLOR_GREEN);
|
||||
}
|
||||
}
|
||||
if (instruction[3] & 0b00010000) {
|
||||
INSTRUCTION.channel_table[amp_channel_table[chd] - 1] = TRUE;
|
||||
for (fled=0; fled < amp_channel_table[chd]; fled++)
|
||||
{
|
||||
headstage_led_spi_color(COLOR_BLUE);
|
||||
CPUdelay(16000*500); //100ms
|
||||
headstage_led_spi_color(COLOR_GREEN);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -773,11 +807,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 +821,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 +837,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 +872,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,35 +914,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;
|
||||
//if ((dat_buf[0] & 0xC1) == 0xC1) {
|
||||
// channel = reverse_channel[INSTRUCTION.last_enable_channel];
|
||||
//}
|
||||
//else{
|
||||
if(channel_pointer==0 && INSTRUCTION.channel_mux[channel_pointer]==INSTRUCTION.last_enable_channel)
|
||||
{channel_pointer++;}
|
||||
|
||||
if ((INSTRUCTION.enable_channel_number == 1) || (dat_buf[0] == 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]];
|
||||
INSTRUCTION.channel_pointer = 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);
|
||||
}
|
||||
@@ -920,6 +1043,7 @@ static uint8_t build_umn_ins_config(uint8_t config_type, uint32_t* value) {
|
||||
if (channel_pointer < INSTRUCTION.enable_channel_number) {
|
||||
return CONFIG_AMP_MUX;
|
||||
} else {
|
||||
INSTRUCTION.channel_pointer = 0;
|
||||
return CONFIG_AMP_GAIN;
|
||||
}
|
||||
}
|
||||
|
||||
+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