Skip to content

Commit

Permalink
Update biu_nrf52.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaxin96 committed Jun 21, 2021
1 parent a3f4903 commit 50e5c4b
Showing 1 changed file with 55 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,20 +298,22 @@ static void resp_buf_read_one() {
return;
}

// determine whether data transfer is possible
// determine whether uart_get is possible
if (uart_available()) {
if (receive_a_pkt(&msg, BiuNrf52MsgTimeout)) {
dprintf("recv latency %dms, resp_buf size %d\n", TIMER_DIFF_16(timer_read(), last_send), (int)resp_buf.size());
resp_buf.get(last_send);
process_nrf_ack_msg(&msg);
dprintf("recv latency %dms\n", TIMER_DIFF_16(timer_read(), last_send));
} else {
dprint("Some thing wrong");
dprintf("Some thing wrong, resp_buf size %d\n", (int)resp_buf.size());
// Receive Wrong: consume this entry
resp_buf.get(last_send);
state.initialized = false;
state.is_connected = false;
state.configured = false;
}
} else {
dprintf("waiting_for_result: timeout, resp_buf size %d\n", (int)resp_buf.size());
dprintf("Uart get buffer is empty, resp_buf size %d\n", (int)resp_buf.size());
// Timed out: consume this entry
resp_buf.get(last_send);
}
Expand Down Expand Up @@ -357,6 +359,7 @@ static bool send_a_pkt(const char *cmd, uint8_t cmd_len, uint16_t timeout, bool
while (!resp_buf.enqueue(now)) {
resp_buf_read_one();
}
dprintf("Put a time into resp buf, resp_buf size %d\n", (int)resp_buf.size());
uint16_t later = timer_read();
if (TIMER_DIFF_16(later, now) > 0) {
dprintf("waited %dms for resp_buf\n", TIMER_DIFF_16(later, now));
Expand Down Expand Up @@ -597,53 +600,8 @@ void bluetooth_send_battery_level() {
}
}

bool bluetooth_init_pre(void) {

// set the ble state
state.initialized = false;
state.configured = false;
state.is_connected = false;

// start the uart data trans
uart_init(BIUNRF52UartBaud);

// hang up the reset pin
setPinOutput(BIUNRF52ResetPin);
writePinHigh(BIUNRF52ResetPin);

// set the adc read sw off
# ifdef BATTERY_LEVEL_SW_PIN
setPinOutput(BATTERY_LEVEL_SW_PIN);
writePinHigh(BATTERY_LEVEL_SW_PIN);
# endif

return true;
}


bool bluetooth_init(void) {

dprint("Start Init the Nrf!!!\n");
// performance a reset
writePinLow(BIUNRF52ResetPin);
wait_ms(100);
writePinHigh(BIUNRF52ResetPin);

struct queue_item item;

item.queue_type = QTAskNrf;
item.added = timer_read();
while (!send_buf.enqueue(item)) {
send_buf_send_one();
}
send_buf_send_one();
wait_ms(BiuNrf52MsgRecvTimeout); // Give it 1.5 second to initialize or some ack frame
// todo ack
resp_buf_read_one();

return state.initialized;
}

void connected(void) {
uprintf("biu ble connected\n");
// start adv with wl
Expand Down Expand Up @@ -712,6 +670,54 @@ void bluetooth_switch_one(uint8_t device_id) {
}


bool bluetooth_init_pre(void) {

// set the ble state
state.initialized = false;
state.configured = false;
state.is_connected = false;

// start the uart data trans
uart_init(BIUNRF52UartBaud);

// hang up the reset pin
setPinOutput(BIUNRF52ResetPin);
writePinHigh(BIUNRF52ResetPin);

// set the adc read sw off
# ifdef BATTERY_LEVEL_SW_PIN
setPinOutput(BATTERY_LEVEL_SW_PIN);
writePinHigh(BATTERY_LEVEL_SW_PIN);
# endif

return true;
}


bool bluetooth_init(void) {

dprint("Start Init the Nrf!!!\n");
// performance a reset
writePinLow(BIUNRF52ResetPin);
wait_ms(100);
writePinHigh(BIUNRF52ResetPin);

struct queue_item item;

item.queue_type = QTAskNrf;
item.added = timer_read();
while (!send_buf.enqueue(item)) {
send_buf_send_one();
}
send_buf_send_one();
wait_ms(BiuNrf52MsgRecvTimeout); // Give it 1.5 second to initialize or some ack frame
// todo ack
resp_buf_read_one();

return state.initialized;
}


bool biu_ble_enable_keyboard(void) {
char resbuf[128];

Expand Down

0 comments on commit 50e5c4b

Please sign in to comment.