8000 nrf5/hal: Adding untested implementation of twi read. Lacking sensors… · pcurry/circuitpython@2c61b7f · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c61b7f

Browse files
committed
nrf5/hal: Adding untested implementation of twi read. Lacking sensors to test with :)
1 parent 4a631a0 commit 2c61b7f

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

nrf5/hal/hal_twi.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,37 @@ void hal_twi_master_tx(NRF_TWI_Type * p_instance,
9393
void hal_twi_master_rx(NRF_TWI_Type * p_instance,
9494
uint8_t addr,
9595
uint16_t transfer_size,
96-
const uint8_t * rx_data) {
96+
uint8_t * rx_data,
97+
bool stop) {
98+
99+
uint16_t number_of_rxd_bytes = 0;
100+
101+
p_instance->ADDRESS = addr;
102+
103+
p_instance->EVENTS_RXDREADY = 0;
104+
105+
p_instance->TASKS_STARTRX = 1;
106+
107+
while (number_of_rxd_bytes < transfer_size) {
108+
// wait for the transaction complete
109+
while (p_instance->EVENTS_RXDREADY == 0) {
110+
;
111+
}
112+
113+
rx_data[number_of_rxd_bytes] = p_instance->RXD;
114+
p_instance->EVENTS_RXDREADY = 0;
97115

116+
number_of_rxd_bytes++;
117+
}
118+
119+
if (stop) {
120+
p_instance->EVENTS_STOPPED = 0;
121+
p_instance->TASKS_STOP = 1;
122+
123+
while (p_instance->EVENTS_STOPPED == 0) {
124+
;
125+
}
126+
}
98127
}
99128

100129
void hal_twi_slave_init(NRF_TWI_Type * p_instance, hal_twi_init_t const * p_twi_init) {

nrf5/hal/hal_twi.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ void hal_twi_master_tx(NRF_TWI_Type * p_instance,
108108
void hal_twi_master_rx(NRF_TWI_Type * p_instance,
109109
uint8_t addr,
110110
uint16_t transfer_size,
111-
const uint8_t * rx_data);
111+
uint8_t * rx_data,
112+
bool stop);
112113

113114

114115
void hal_twi_slave_init(NRF_TWI_Type * p_instance, hal_twi_init_t const * p_twi_init);

0 commit comments

Comments
 (0)
0