Skip to content

Commit 32311b7

Browse files
committed
i2c_api.c: fix style
1 parent e18a800 commit 32311b7

File tree

1 file changed

+39
-41
lines changed
  • targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52

1 file changed

+39
-41
lines changed

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/i2c_api.c

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ const PinMap *i2c_slave_scl_pinmap()
232232
/*****************************************************************************/
233233

234234
/* 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 };
236236

237237
/**
238238
* @brief Reconfigure TWI register.
@@ -254,14 +254,14 @@ void i2c_configure_twi_instance(i2c_t *obj)
254254
struct i2c_s *config = obj;
255255
#endif
256256

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+
};
265265

266266
int instance = config->instance;
267267

@@ -287,22 +287,21 @@ void i2c_configure_twi_instance(i2c_t *obj)
287287
/* Force resource release. This is necessary because mbed drivers don't
288288
* deinitialize on object destruction.
289289
*/
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.",
303302
__func__,
304303
err_code);
305-
}
304+
}
306305

307306
/* Reset shorts register. */
308307
nrf_twi_shorts_set(nordic_nrf5_twi_register[instance], 0);
@@ -505,7 +504,7 @@ int i2c_byte_read(i2c_t *obj, int last)
505504

506505
/* Block until timeout or data ready event has been signaled. */
507506
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))) {
509508
now_us = tick2us * lp_ticker_read();
510509
}
511510

@@ -544,7 +543,7 @@ int i2c_stop(i2c_t *obj)
544543
uint32_t now_us = start_us;
545544

546545
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))) {
548547
now_us = tick2us * lp_ticker_read();
549548
}
550549

@@ -640,7 +639,7 @@ static void i2c_configure_driver_instance(i2c_t *obj)
640639
/* Force resource release. This is necessary because mbed drivers don't
641640
* deinitialize on object destruction.
642641
*/
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])));
644643

645644
/* Configure driver with new settings. */
646645
nrfx_twi_config_t twi_config = {
@@ -709,9 +708,9 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
709708

710709
/* Initialize transaction. */
711710
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);
715714

716715
/* Set return value on success. */
717716
if (retval == NRF_SUCCESS) {
@@ -753,10 +752,10 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
753752

754753
/* Initialize transaction. */
755754
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);
760759

761760
/* Set return value on success. */
762761
if (retval == NRF_SUCCESS) {
@@ -792,8 +791,7 @@ static void nordic_nrf5_twi_event_handler(nrfx_twi_evt_t const *p_event, void *p
792791
struct i2c_s *config = &obj->i2c;
793792

794793
/* Translate event type from NRF driver values to mbed HAL values. */
795-
switch (p_event->type)
796-
{
794+
switch (p_event->type) {
797795
/* Transfer completed event. */
798796
case NRFX_TWI_EVT_DONE:
799797
config->event = I2C_EVENT_TRANSFER_COMPLETE;
@@ -874,17 +872,17 @@ void i2c_transfer_asynch(i2c_t *obj,
874872

875873
/* Configure TWI transfer. */
876874
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);
881879

882880
uint32_t flags = (stop) ? 0 : NRFX_TWI_FLAG_TX_NO_STOP;
883881

884882
/* Initiate TWI transfer using NRF driver. */
885883
ret_code_t result = nrfx_twi_xfer(&nordic_nrf5_instance[instance],
886-
&twi_config,
887-
flags);
884+
&twi_config,
885+
flags);
888886

889887
/* Signal error if event mask matches and event handler is set. */
890888
if ((result != NRF_SUCCESS) && (mask & I2C_EVENT_ERROR) && handler) {

0 commit comments

Comments
 (0)