@@ -232,7 +232,7 @@ const PinMap *i2c_slave_scl_pinmap()
232
232
/*****************************************************************************/
233
233
234
234
/* Global array for easy register selection for each instance. */
235
- static NRF_TWI_Type * nordic_nrf5_twi_register [2 ] = { NRF_TWI0 , NRF_TWI1 };
235
+ static NRF_TWI_Type * nordic_nrf5_twi_register [2 ] = { NRF_TWI0 , NRF_TWI1 };
236
236
237
237
/**
238
238
* @brief Reconfigure TWI register.
@@ -254,14 +254,14 @@ void i2c_configure_twi_instance(i2c_t *obj)
254
254
struct i2c_s * config = obj ;
255
255
#endif
256
256
257
- static nrfx_irq_handler_t const irq_handlers [NRFX_TWI_ENABLED_COUNT ] = {
258
- #if NRFX_CHECK (NRFX_TWI0_ENABLED )
259
- nrfx_twi_0_irq_handler ,
260
- #endif
261
- #if NRFX_CHECK (NRFX_TWI1_ENABLED )
262
- nrfx_twi_1_irq_handler ,
263
- #endif
264
- };
257
+ static nrfx_irq_handler_t const irq_handlers [NRFX_TWI_ENABLED_COUNT ] = {
258
+ #if NRFX_CHECK (NRFX_TWI0_ENABLED )
259
+ nrfx_twi_0_irq_handler ,
260
+ #endif
261
+ #if NRFX_CHECK (NRFX_TWI1_ENABLED )
262
+ nrfx_twi_1_irq_handler ,
263
+ #endif
264
+ };
265
265
266
266
int instance = config -> instance ;
267
267
@@ -287,22 +287,21 @@ void i2c_configure_twi_instance(i2c_t *obj)
287
287
/* Force resource release. This is necessary because mbed drivers don't
288
288
* deinitialize on object destruction.
289
289
*/
290
- NRFX_IRQ_DISABLE ((nrfx_get_irq_number ((void const * )nordic_nrf5_twi_register [instance ])));
291
- /* Release and re-initialize the irq handlers.
292
- * observation: based on call flow, this is called only during i2c_reset and i2c_byte_write
293
- * The nrfx_prs_acquire is normally called in nrfx_twi_init which is part of the i2c_configure_driver_instance,
294
- * not i2c_configure_twi_intance. Hence I think the release and acquire is not doing any useful work here.
295
- * Keeping for reference and should clean up after testing if found not useful.
296
- */
297
-
298
- nrfx_prs_release (nordic_nrf5_twi_register [instance ]);
299
- if (nrfx_prs_acquire (nordic_nrf5_twi_register [instance ],
300
- irq_handlers [instance ]) != NRFX_SUCCESS )
301
- {
302
- DEBUG_PRINTF ("Function: %s, nrfx_prs_acquire error code: %s." ,
290
+ NRFX_IRQ_DISABLE ((nrfx_get_irq_number ((void const * )nordic_nrf5_twi_register [instance ])));
291
+ /* Release and re-initialize the irq handlers.
292
+ * observation: based on call flow, this is called only during i2c_reset and i2c_byte_write
293
+ * The nrfx_prs_acquire is normally called in nrfx_twi_init which is part of the i2c_configure_driver_instance,
294
+ * not i2c_configure_twi_intance. Hence I think the release and acquire is not doing any useful work here.
295
+ * Keeping for reference and should clean up after testing if found not useful.
296
+ */
297
+
298
+ nrfx_prs_release (nordic_nrf5_twi_register [instance ]);
299
+ if (nrfx_prs_acquire (nordic_nrf5_twi_register [instance ],
300
+ irq_handlers [instance ]) != NRFX_SUCCESS ) {
301
+ DEBUG_PRINTF ("Function: %s, nrfx_prs_acquire error code: %s." ,
303
302
__func__ ,
304
303
err_code );
305
- }
304
+ }
306
305
307
306
/* Reset shorts register. */
308
307
nrf_twi_shorts_set (nordic_nrf5_twi_register [instance ], 0 );
@@ -505,7 +504,7 @@ int i2c_byte_read(i2c_t *obj, int last)
505
504
506
505
/* Block until timeout or data ready event has been signaled. */
507
506
while (((now_us - start_us ) < timeout ) &&
508
- !(nrf_twi_event_check (nordic_nrf5_twi_register [instance ], NRF_TWI_EVENT_RXDREADY ))) {
507
+ !(nrf_twi_event_check (nordic_nrf5_twi_register [instance ], NRF_TWI_EVENT_RXDREADY ))) {
509
508
now_us = tick2us * lp_ticker_read ();
510
509
}
511
510
@@ -544,7 +543,7 @@ int i2c_stop(i2c_t *obj)
544
543
uint32_t now_us = start_us ;
545
544
546
545
while (((now_us - start_us ) < MAXIMUM_TIMEOUT_US ) &&
547
- !(nrf_twi_event_check (nordic_nrf5_twi_register [instance ], NRF_TWI_EVENT_STOPPED ))) {
546
+ !(nrf_twi_event_check (nordic_nrf5_twi_register [instance ], NRF_TWI_EVENT_STOPPED ))) {
548
547
now_us = tick2us * lp_ticker_read ();
549
548
}
550
549
@@ -640,7 +639,7 @@ static void i2c_configure_driver_instance(i2c_t *obj)
640
639
/* Force resource release. This is necessary because mbed drivers don't
641
640
* deinitialize on object destruction.
642
641
*/
643
- NRFX_IRQ_DISABLE ((nrfx_get_irq_number ((void const * )nordic_nrf5_twi_register [instance ])));
642
+ NRFX_IRQ_DISABLE ((nrfx_get_irq_number ((void const * )nordic_nrf5_twi_register [instance ])));
644
643
645
644
/* Configure driver with new settings. */
646
645
nrfx_twi_config_t twi_config = {
@@ -709,9 +708,9 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
709
708
710
709
/* Initialize transaction. */
711
710
ret_code_t retval = nrfx_twi_rx (& nordic_nrf5_instance [instance ],
712
- address >> 1 ,
713
- (uint8_t * ) data ,
714
- length );
711
+ address >> 1 ,
712
+ (uint8_t * ) data ,
713
+ length );
715
714
716
715
/* Set return value on success. */
717
716
if (retval == NRF_SUCCESS ) {
@@ -753,10 +752,10 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
753
752
754
753
/* Initialize transaction. */
755
754
ret_code_t retval = nrfx_twi_tx (& nordic_nrf5_instance [instance ],
756
- address >> 1 ,
757
- (const uint8_t * ) data ,
758
- length ,
759
- !stop );
755
+ address >> 1 ,
756
+ (const uint8_t * ) data ,
757
+ length ,
758
+ !stop );
760
759
761
760
/* Set return value on success. */
762
761
if (retval == NRF_SUCCESS ) {
@@ -792,8 +791,7 @@ static void nordic_nrf5_twi_event_handler(nrfx_twi_evt_t const *p_event, void *p
792
791
struct i2c_s * config = & obj -> i2c ;
793
792
794
793
/* Translate event type from NRF driver values to mbed HAL values. */
795
- switch (p_event -> type )
796
- {
794
+ switch (p_event -> type ) {
797
795
/* Transfer completed event. */
798
796
case NRFX_TWI_EVT_DONE :
799
797
config -> event = I2C_EVENT_TRANSFER_COMPLETE ;
@@ -874,17 +872,17 @@ void i2c_transfer_asynch(i2c_t *obj,
874
872
875
873
/* Configure TWI transfer. */
876
874
const nrfx_twi_xfer_desc_t twi_config = NRFX_TWI_XFER_DESC_TXRX (address >> 1 ,
877
- (uint8_t * ) tx ,
878
- tx_length ,
879
- rx ,
880
- rx_length );
875
+ (uint8_t * ) tx ,
876
+ tx_length ,
877
+ rx ,
878
+ rx_length );
881
879
882
880
uint32_t flags = (stop ) ? 0 : NRFX_TWI_FLAG_TX_NO_STOP ;
883
881
884
882
/* Initiate TWI transfer using NRF driver. */
885
883
ret_code_t result = nrfx_twi_xfer (& nordic_nrf5_instance [instance ],
886
- & twi_config ,
887
- flags );
884
+ & twi_config ,
885
+ flags );
888
886
889
887
/* Signal error if event mask matches and event handler is set. */
890
888
if ((result != NRF_SUCCESS ) && (mask & I2C_EVENT_ERROR ) && handler ) {
0 commit comments