Skip to content

Commit dbbe290

Browse files
author
Tim Hutt
committed
Tabs -> Spaces
1 parent 8aaee5a commit dbbe290

File tree

1 file changed

+49
-49
lines changed
  • libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822

1 file changed

+49
-49
lines changed

libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/twi_master.c

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ static bool twi_master_write(uint8_t * data, uint8_t data_length, bool issue_sto
3131
return false;
3232
}
3333

34-
twi->TXD = *data++;
35-
twi->TASKS_STARTTX = 1;
34+
twi->TXD = *data++;
35+
twi->TASKS_STARTTX = 1;
3636

3737
/** @snippet [TWI HW master write] */
3838
while (true)
3939
{
40-
while (twi->EVENTS_TXDSENT == 0 && twi->EVENTS_ERROR == 0 && (--timeout))
40+
while (twi->EVENTS_TXDSENT == 0 && twi->EVENTS_ERROR == 0 && (--timeout))
4141
{
4242
// Do nothing.
4343
}
@@ -47,33 +47,33 @@ static bool twi_master_write(uint8_t * data, uint8_t data_length, bool issue_sto
4747
// Recover the peripheral as indicated by PAN 56: "TWI: TWI module lock-up." found at
4848
// Product Anomaly Notification document found at
4949
// https://www.nordicsemi.com/eng/Products/Bluetooth-R-low-energy/nRF51822/#Downloads
50-
twi->EVENTS_ERROR = 0;
51-
twi->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
52-
twi->POWER = 0;
50+
twi->EVENTS_ERROR = 0;
51+
twi->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
52+
twi->POWER = 0;
5353
nrf_delay_us(5);
54-
twi->POWER = 1;
55-
twi->ENABLE = TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos;
54+
twi->POWER = 1;
55+
twi->ENABLE = TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos;
5656

57-
(void)twi_master_init_and_clear(twi);
57+
(void)twi_master_init_and_clear(twi);
5858

5959
return false;
6060
}
61-
twi->EVENTS_TXDSENT = 0;
61+
twi->EVENTS_TXDSENT = 0;
6262
if (--data_length == 0)
6363
{
6464
break;
6565
}
6666

67-
twi->TXD = *data++;
67+
twi->TXD = *data++;
6868
}
6969
/** @snippet [TWI HW master write] */
7070

7171
if (issue_stop_condition)
7272
{
73-
twi->EVENTS_STOPPED = 0;
74-
twi->TASKS_STOP = 1;
73+
twi->EVENTS_STOPPED = 0;
74+
twi->TASKS_STOP = 1;
7575
/* Wait until stop sequence is sent */
76-
while(twi->EVENTS_STOPPED == 0)
76+
while(twi->EVENTS_STOPPED == 0)
7777
{
7878
// Do nothing.
7979
}
@@ -95,39 +95,39 @@ static bool twi_master_read(uint8_t * data, uint8_t data_length, bool issue_stop
9595
}
9696
else if (data_length == 1)
9797
{
98-
NRF_PPI->CH[0].TEP = (uint32_t)&twi->TASKS_STOP;
98+
NRF_PPI->CH[0].TEP = (uint32_t)&twi->TASKS_STOP;
9999
}
100100
else
101101
{
102-
NRF_PPI->CH[0].TEP = (uint32_t)&twi->TASKS_SUSPEND;
102+
NRF_PPI->CH[0].TEP = (uint32_t)&twi->TASKS_SUSPEND;
103103
}
104104

105105
NRF_PPI->CHENSET = PPI_CHENSET_CH0_Msk;
106-
twi->EVENTS_RXDREADY = 0;
107-
twi->TASKS_STARTRX = 1;
106+
twi->EVENTS_RXDREADY = 0;
107+
twi->TASKS_STARTRX = 1;
108108

109109
/** @snippet [TWI HW master read] */
110110
while (true)
111111
{
112-
while (twi->EVENTS_RXDREADY == 0 && NRF_TWI1->EVENTS_ERROR == 0 && (--timeout))
112+
while (twi->EVENTS_RXDREADY == 0 && NRF_TWI1->EVENTS_ERROR == 0 && (--timeout))
113113
{
114114
// Do nothing.
115115
}
116-
twi->EVENTS_RXDREADY = 0;
116+
twi->EVENTS_RXDREADY = 0;
117117

118-
if (timeout == 0 || twi->EVENTS_ERROR != 0)
118+
if (timeout == 0 || twi->EVENTS_ERROR != 0)
119119
{
120120
// Recover the peripheral as indicated by PAN 56: "TWI: TWI module lock-up." found at
121121
// Product Anomaly Notification document found at
122122
// https://www.nordicsemi.com/eng/Products/Bluetooth-R-low-energy/nRF51822/#Downloads
123-
twi->EVENTS_ERROR = 0;
124-
twi->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
125-
twi->POWER = 0;
123+
twi->EVENTS_ERROR = 0;
124+
twi->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
125+
twi->POWER = 0;
126126
nrf_delay_us(5);
127-
twi->POWER = 1;
128-
twi->ENABLE = TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos;
127+
twi->POWER = 1;
128+
twi->ENABLE = TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos;
129129

130-
(void)twi_master_init_and_clear(twi);
130+
(void)twi_master_init_and_clear(twi);
131131

132132
return false;
133133
}
@@ -149,16 +149,16 @@ static bool twi_master_read(uint8_t * data, uint8_t data_length, bool issue_stop
149149
// Product Anomaly Notification document found at
150150
// https://www.nordicsemi.com/eng/Products/Bluetooth-R-low-energy/nRF51822/#Downloads
151151
nrf_delay_us(20);
152-
twi->TASKS_RESUME = 1;
152+
twi->TASKS_RESUME = 1;
153153
}
154154
/** @snippet [TWI HW master read] */
155155

156156
/* Wait until stop sequence is sent */
157-
while(twi->EVENTS_STOPPED == 0)
157+
while(twi->EVENTS_STOPPED == 0)
158158
{
159159
// Do nothing.
160160
}
161-
twi->EVENTS_STOPPED = 0;
161+
twi->EVENTS_STOPPED = 0;
162162

163163
NRF_PPI->CHENCLR = PPI_CHENCLR_CH0_Msk;
164164
return true;
@@ -180,8 +180,8 @@ static bool twi_master_clear_bus(NRF_TWI_Type* twi)
180180
uint32_t data_pin_config;
181181

182182
// Save and disable TWI hardware so software can take control over the pins.
183-
twi_state = twi->ENABLE;
184-
twi->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
183+
twi_state = twi->ENABLE;
184+
twi->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
185185

186186
clk_pin_config = \
187187
NRF_GPIO->PIN_CNF[TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER];
@@ -234,7 +234,7 @@ static bool twi_master_clear_bus(NRF_TWI_Type* twi)
234234
NRF_GPIO->PIN_CNF[TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER] = clk_pin_config;
235235
NRF_GPIO->PIN_CNF[TWI_MASTER_CONFIG_DATA_PIN_NUMBER] = data_pin_config;
236236

237-
twi->ENABLE = twi_state;
237+
twi->ENABLE = twi_state;
238238

239239
return bus_clear;
240240
}
@@ -262,17 +262,17 @@ bool twi_master_init_and_clear(NRF_TWI_Type* twi)
262262
| (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) \
263263
| (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
264264

265-
twi->EVENTS_RXDREADY = 0;
266-
twi->EVENTS_TXDSENT = 0;
267-
twi->PSELSCL = TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER;
268-
twi->PSELSDA = TWI_MASTER_CONFIG_DATA_PIN_NUMBER;
269-
twi->FREQUENCY = TWI_FREQUENCY_FREQUENCY_K100 << TWI_FREQUENCY_FREQUENCY_Pos;
270-
NRF_PPI->CH[0].EEP = (uint32_t)&twi->EVENTS_BB;
271-
NRF_PPI->CH[0].TEP = (uint32_t)&twi->TASKS_SUSPEND;
265+
twi->EVENTS_RXDREADY = 0;
266+
twi->EVENTS_TXDSENT = 0;
267+
twi->PSELSCL = TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER;
268+
twi->PSELSDA = TWI_MASTER_CONFIG_DATA_PIN_NUMBER;
269+
twi->FREQUENCY = TWI_FREQUENCY_FREQUENCY_K100 << TWI_FREQUENCY_FREQUENCY_Pos;
270+
NRF_PPI->CH[0].EEP = (uint32_t)&twi->EVENTS_BB;
271+
NRF_PPI->CH[0].TEP = (uint32_t)&twi->TASKS_SUSPEND;
272272
NRF_PPI->CHENCLR = PPI_CHENCLR_CH0_Msk;
273-
twi->ENABLE = TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos;
273+
twi->ENABLE = TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos;
274274

275-
return twi_master_clear_bus(twi);
275+
return twi_master_clear_bus(twi);
276276
}
277277

278278

@@ -281,21 +281,21 @@ bool twi_master_init_and_clear(NRF_TWI_Type* twi)
281281
bool twi_master_transfer(uint8_t address,
282282
uint8_t * data,
283283
uint8_t data_length,
284-
bool issue_stop_condition,
285-
NRF_TWI_Type* twi)
284+
bool issue_stop_condition,
285+
NRF_TWI_Type* twi)
286286
{
287287
bool transfer_succeeded = false;
288-
if (data_length > 0 && twi_master_clear_bus(twi))
288+
if (data_length > 0 && twi_master_clear_bus(twi))
289289
{
290-
twi->ADDRESS = (address >> 1);
290+
twi->ADDRESS = (address >> 1);
291291

292-
if ((address & TWI_READ_BIT))
292+
if ((address & TWI_READ_BIT))
293293
{
294-
transfer_succeeded = twi_master_read(data, data_length, issue_stop_condition, twi);
294+
transfer_succeeded = twi_master_read(data, data_length, issue_stop_condition, twi);
295295
}
296296
else
297297
{
298-
transfer_succeeded = twi_master_write(data, data_length, issue_stop_condition, twi);
298+
transfer_succeeded = twi_master_write(data, data_length, issue_stop_condition, twi);
299299
}
300300
}
301301
return transfer_succeeded;

0 commit comments

Comments
 (0)