Skip to content

Commit 6127259

Browse files
committed
nrf/modules/machine: Enable code formatting.
It destroys a few manual alignments, but these seem minor compared to the benefit of automated code style consistency. Signed-off-by: Christian Walther <cwalther@gmx.ch>
1 parent d712feb commit 6127259

File tree

14 files changed

+177
-181
lines changed

14 files changed

+177
-181
lines changed

ports/nrf/modules/machine/adc.c

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838

3939
typedef struct _machine_adc_obj_t {
4040
mp_obj_base_t base;
41-
uint8_t id;
42-
#if NRF51
43-
uint8_t ain;
44-
#endif
41+
uint8_t id;
42+
#if NRF51
43+
uint8_t ain;
44+
#endif
4545
} machine_adc_obj_t;
4646

4747
static const machine_adc_obj_t machine_adc_obj[] = {
48-
#if NRF51
48+
#if NRF51
4949
{{&machine_adc_type}, .id = 0, .ain = NRF_ADC_CONFIG_INPUT_0},
5050
{{&machine_adc_type}, .id = 1, .ain = NRF_ADC_CONFIG_INPUT_1},
5151
{{&machine_adc_type}, .id = 2, .ain = NRF_ADC_CONFIG_INPUT_2},
@@ -54,7 +54,7 @@ static const machine_adc_obj_t machine_adc_obj[] = {
5454
{{&machine_adc_type}, .id = 5, .ain = NRF_ADC_CONFIG_INPUT_5},
5555
{{&machine_adc_type}, .id = 6, .ain = NRF_ADC_CONFIG_INPUT_6},
5656
{{&machine_adc_type}, .id = 7, .ain = NRF_ADC_CONFIG_INPUT_7},
57-
#else
57+
#else
5858
{{&machine_adc_type}, .id = 0},
5959
{{&machine_adc_type}, .id = 1},
6060
{{&machine_adc_type}, .id = 2},
@@ -63,14 +63,14 @@ static const machine_adc_obj_t machine_adc_obj[] = {
6363
{{&machine_adc_type}, .id = 5},
6464
{{&machine_adc_type}, .id = 6},
6565
{{&machine_adc_type}, .id = 7},
66-
#endif
66+
#endif
6767
};
6868

6969
void adc_init0(void) {
70-
#if defined(NRF52_SERIES)
70+
#if defined(NRF52_SERIES)
7171
const uint8_t interrupt_priority = 6;
7272
nrfx_saadc_init(interrupt_priority);
73-
#endif
73+
#endif
7474
}
7575

7676
static int adc_find(mp_obj_t id) {
@@ -124,49 +124,49 @@ static mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args
124124
int adc_id = adc_find(args[ARG_id].u_obj);
125125
const machine_adc_obj_t *self = &machine_adc_obj[adc_id];
126126

127-
#if defined(NRF52_SERIES)
127+
#if defined(NRF52_SERIES)
128128
const nrfx_saadc_channel_t config = { \
129129
.channel_config =
130130
{
131131
.resistor_p = NRF_SAADC_RESISTOR_DISABLED,
132132
.resistor_n = NRF_SAADC_RESISTOR_DISABLED,
133-
.gain = NRF_SAADC_GAIN1_4,
134-
.reference = NRF_SAADC_REFERENCE_VDD4,
135-
.acq_time = NRF_SAADC_ACQTIME_3US,
136-
.mode = NRF_SAADC_MODE_SINGLE_ENDED,
137-
.burst = NRF_SAADC_BURST_DISABLED,
133+
.gain = NRF_SAADC_GAIN1_4,
134+
.reference = NRF_SAADC_REFERENCE_VDD4,
135+
.acq_time = NRF_SAADC_ACQTIME_3US,
136+
.mode = NRF_SAADC_MODE_SINGLE_ENDED,
137+
.burst = NRF_SAADC_BURST_DISABLED,
138138
},
139-
.pin_p = (nrf_saadc_input_t)(1 + self->id), // pin_p=0 is AIN0, pin_p=8 is AIN7
140-
.pin_n = NRF_SAADC_INPUT_DISABLED,
141-
.channel_index = self->id,
139+
.pin_p = (nrf_saadc_input_t)(1 + self->id), // pin_p=0 is AIN0, pin_p=8 is AIN7
140+
.pin_n = NRF_SAADC_INPUT_DISABLED,
141+
.channel_index = self->id,
142142
};
143143
nrfx_saadc_channels_config(&config, 1);
144-
#endif
144+
#endif
145145

146146
return MP_OBJ_FROM_PTR(self);
147147
}
148148

149-
int16_t machine_adc_value_read(machine_adc_obj_t * adc_obj) {
149+
int16_t machine_adc_value_read(machine_adc_obj_t *adc_obj) {
150150

151-
#if NRF51
151+
#if NRF51
152152
nrf_adc_value_t value = 0;
153153

154154
nrfx_adc_channel_t channel_config = {
155155
.config.resolution = NRF_ADC_CONFIG_RES_8BIT,
156-
.config.input = NRF_ADC_CONFIG_SCALING_INPUT_TWO_THIRDS,
157-
.config.reference = NRF_ADC_CONFIG_REF_VBG,
158-
.config.input = adc_obj->ain,
159-
.config.extref = ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos // Currently not defined in nrfx/hal.
156+
.config.input = NRF_ADC_CONFIG_SCALING_INPUT_TWO_THIRDS,
157+
.config.reference = NRF_ADC_CONFIG_REF_VBG,
158+
.config.input = adc_obj->ain,
159+
.config.extref = ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos // Currently not defined in nrfx/hal.
160160
};
161161

162162
nrfx_adc_sample_convert(&channel_config, &value);
163-
#else // NRF52
163+
#else // NRF52
164164
nrf_saadc_value_t value = 0;
165165

166166
nrfx_saadc_simple_mode_set((1 << adc_obj->id), NRF_SAADC_RESOLUTION_8BIT, NRF_SAADC_INPUT_DISABLED, NULL);
167167
nrfx_saadc_buffer_set(&value, 1);
168168
nrfx_saadc_mode_trigger();
169-
#endif
169+
#endif
170170
return value;
171171
}
172172

@@ -209,10 +209,9 @@ static MP_DEFINE_CONST_FUN_OBJ_1(mp_machine_adc_value_obj, machine_adc_value);
209209
#define DIODE_VOLT_DROP_MILLIVOLT (270) // Voltage drop over diode.
210210

211211
#define BATTERY_MILLIVOLT(VALUE) \
212-
((((VALUE) * ADC_REF_VOLTAGE_IN_MILLIVOLT) / 255) * ADC_PRE_SCALING_MULTIPLIER)
212+
((((VALUE)*ADC_REF_VOLTAGE_IN_MILLIVOLT) / 255) * ADC_PRE_SCALING_MULTIPLIER)
213213

214-
static uint8_t battery_level_in_percent(const uint16_t mvolts)
215-
{
214+
static uint8_t battery_level_in_percent(const uint16_t mvolts) {
216215
uint8_t battery_level;
217216

218217
if (mvolts >= 3000) {
@@ -236,42 +235,42 @@ static uint8_t battery_level_in_percent(const uint16_t mvolts)
236235
/// Get battery level in percentage.
237236
mp_obj_t machine_adc_battery_level(void) {
238237

239-
#if NRF51
238+
#if NRF51
240239
nrf_adc_value_t value = 0;
241240

242241
nrfx_adc_channel_t channel_config = {
243242
.config.resolution = NRF_ADC_CONFIG_RES_8BIT,
244-
.config.input = NRF_ADC_CONFIG_SCALING_SUPPLY_ONE_THIRD,
245-
.config.reference = NRF_ADC_CONFIG_REF_VBG,
246-
.config.input = NRF_ADC_CONFIG_INPUT_DISABLED,
247-
.config.extref = ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos // Currently not defined in nrfx/hal.
243+
.config.input = NRF_ADC_CONFIG_SCALING_SUPPLY_ONE_THIRD,
244+
.config.reference = NRF_ADC_CONFIG_REF_VBG,
245+
.config.input = NRF_ADC_CONFIG_INPUT_DISABLED,
246+
.config.extref = ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos // Currently not defined in nrfx/hal.
248247
};
249248

250249
nrfx_adc_sample_convert(&channel_config, &value);
251-
#else // NRF52
250+
#else // NRF52
252251
nrf_saadc_value_t value = 0;
253252

254253
const nrfx_saadc_channel_t config = { \
255254
.channel_config =
256255
{
257256
.resistor_p = NRF_SAADC_RESISTOR_DISABLED,
258257
.resistor_n = NRF_SAADC_RESISTOR_DISABLED,
259-
.gain = NRF_SAADC_GAIN1_6,
260-
.reference = NRF_SAADC_REFERENCE_INTERNAL,
261-
.acq_time = NRF_SAADC_ACQTIME_3US,
262-
.mode = NRF_SAADC_MODE_SINGLE_ENDED,
263-
.burst = NRF_SAADC_BURST_DISABLED,
258+
.gain = NRF_SAADC_GAIN1_6,
259+
.reference = NRF_SAADC_REFERENCE_INTERNAL,
260+
.acq_time = NRF_SAADC_ACQTIME_3US,
261+
.mode = NRF_SAADC_MODE_SINGLE_ENDED,
262+
.burst = NRF_SAADC_BURST_DISABLED,
264263
},
265-
.pin_p = NRF_SAADC_INPUT_VDD,
266-
.pin_n = NRF_SAADC_INPUT_DISABLED,
267-
.channel_index = 0,
264+
.pin_p = NRF_SAADC_INPUT_VDD,
265+
.pin_n = NRF_SAADC_INPUT_DISABLED,
266+
.channel_index = 0,
268267
};
269268
nrfx_saadc_channels_config(&config, 1);
270269

271270
nrfx_saadc_simple_mode_set((1 << 0), NRF_SAADC_RESOLUTION_8BIT, NRF_SAADC_INPUT_DISABLED, NULL);
272271
nrfx_saadc_buffer_set(&value, 1);
273272
nrfx_saadc_mode_trigger();
274-
#endif
273+
#endif
275274

276275
uint16_t batt_lvl_in_milli_volts = BATTERY_MILLIVOLT(value) + DIODE_VOLT_DROP_MILLIVOLT;
277276
uint16_t batt_in_percent = battery_level_in_percent(batt_lvl_in_milli_volts);

ports/nrf/modules/machine/adc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ typedef struct _machine_adc_obj_t machine_adc_obj_t;
3131

3232
void adc_init0(void);
3333

34-
int16_t machine_adc_value_read(machine_adc_obj_t * adc_obj);
34+
int16_t machine_adc_value_read(machine_adc_obj_t *adc_obj);
3535

3636
#endif // ADC_H__

ports/nrf/modules/machine/i2c.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868

6969
typedef struct _machine_hard_i2c_obj_t {
7070
mp_obj_base_t base;
71-
nrfx_twi_t p_twi; // Driver instance
71+
nrfx_twi_t p_twi; // Driver instance
7272
} machine_hard_i2c_obj_t;
7373

7474
static const machine_hard_i2c_obj_t machine_hard_i2c_obj[] = {
@@ -159,8 +159,7 @@ int machine_hard_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, size
159159
if (err_code != NRFX_SUCCESS) {
160160
if (err_code == NRFX_ERROR_DRV_TWI_ERR_ANACK) {
161161
return -MP_ENODEV;
162-
}
163-
else if (err_code == NRFX_ERROR_DRV_TWI_ERR_DNACK) {
162+
} else if (err_code == NRFX_ERROR_DRV_TWI_ERR_DNACK) {
164163
return -MP_EIO;
165164
}
166165
return -MP_ETIMEDOUT;

ports/nrf/modules/machine/modmachine.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,16 @@ void machine_init(void) {
116116
reset_cause = PYB_RESET_LOCKUP;
117117
} else if (state & POWER_RESETREAS_OFF_Msk) {
118118
reset_cause = PYB_RESET_POWER_ON;
119-
#if !defined(NRF9160_XXAA)
119+
#if !defined(NRF9160_XXAA)
120120
} else if (state & POWER_RESETREAS_LPCOMP_Msk) {
121121
reset_cause = PYB_RESET_LPCOMP;
122-
#endif
122+
#endif
123123
} else if (state & POWER_RESETREAS_DIF_Msk) {
124124
reset_cause = PYB_RESET_DIF;
125-
#if defined(NRF52_SERIES)
125+
#if defined(NRF52_SERIES)
126126
} else if (state & POWER_RESETREAS_NFC_Msk) {
127127
reset_cause = PYB_RESET_NFC;
128-
#endif
128+
#endif
129129
}
130130

131131
// clear reset reason
@@ -216,22 +216,22 @@ static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
216216
}
217217

218218
static mp_obj_t machine_enable_irq(void) {
219-
#ifndef BLUETOOTH_SD
219+
#ifndef BLUETOOTH_SD
220220
__enable_irq();
221-
#else
221+
#else
222222

223-
#endif
223+
#endif
224224
return mp_const_none;
225225
}
226226
MP_DEFINE_CONST_FUN_OBJ_0(machine_enable_irq_obj, machine_enable_irq);
227227

228228
// Resets the board in a manner similar to pushing the external RESET button.
229229
static mp_obj_t machine_disable_irq(void) {
230-
#ifndef BLUETOOTH_SD
230+
#ifndef BLUETOOTH_SD
231231
__disable_irq();
232-
#else
232+
#else
233233

234-
#endif
234+
#endif
235235
return mp_const_none;
236236
}
237237
MP_DEFINE_CONST_FUN_OBJ_0(machine_disable_irq_obj, machine_disable_irq);

ports/nrf/modules/machine/pin.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ static void pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
234234
}
235235

236236
mp_printf(print, "Pin(%d, mode=%s, pull=%s)",
237-
self->pin,
238-
(nrf_gpio_pin_dir_get(self->pin) == NRF_GPIO_PIN_DIR_OUTPUT) ? "OUT" : "IN",
239-
pull);
237+
self->pin,
238+
(nrf_gpio_pin_dir_get(self->pin) == NRF_GPIO_PIN_DIR_OUTPUT) ? "OUT" : "IN",
239+
pull);
240240
}
241241

242242
static mp_obj_t pin_obj_init_helper(const pin_obj_t *pin, mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args);
@@ -375,11 +375,11 @@ static mp_obj_t pin_obj_init_helper(const pin_obj_t *self, mp_uint_t n_args, con
375375

376376
if (mode == NRF_GPIO_PIN_DIR_OUTPUT || mode == NRF_GPIO_PIN_DIR_INPUT) {
377377
nrf_gpio_cfg(self->pin,
378-
mode,
379-
input,
380-
pull,
381-
NRF_GPIO_PIN_S0S1,
382-
NRF_GPIO_PIN_NOSENSE);
378+
mode,
379+
input,
380+
pull,
381+
NRF_GPIO_PIN_S0S1,
382+
NRF_GPIO_PIN_NOSENSE);
383383
} else {
384384
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("invalid pin mode: %d"), mode);
385385
}
@@ -496,7 +496,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(pin_af_obj, pin_af);
496496
static void pin_common_irq_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
497497
mp_obj_t pin_handler = MP_STATE_PORT(pin_irq_handlers)[pin];
498498
mp_obj_t pin_number = MP_OBJ_NEW_SMALL_INT(pin);
499-
const pin_obj_t *pin_obj = pin_find(pin_number);
499+
const pin_obj_t *pin_obj = pin_find(pin_number);
500500

501501
mp_call_function_1(pin_handler, (mp_obj_t)pin_obj);
502502
}
@@ -591,7 +591,7 @@ static const mp_rom_map_elem_t pin_locals_dict_table[] = {
591591
{ MP_ROM_QSTR(MP_QSTR_AF_OD), MP_ROM_INT(GPIO_MODE_AF_OD) },
592592
{ MP_ROM_QSTR(MP_QSTR_PULL_NONE), MP_ROM_INT(GPIO_NOPULL) },
593593
*/
594-
#include "genhdr/pins_af_const.h"
594+
#include "genhdr/pins_af_const.h"
595595
};
596596

597597
static MP_DEFINE_CONST_DICT(pin_locals_dict, pin_locals_dict_table);

ports/nrf/modules/machine/pin.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,43 +34,43 @@
3434
#include "py/obj.h"
3535

3636
typedef struct {
37-
mp_obj_base_t base;
38-
qstr name;
39-
uint8_t idx;
40-
uint8_t fn;
41-
uint8_t unit;
42-
uint8_t type;
43-
44-
union {
45-
void *reg;
46-
47-
PIN_DEFS_PORT_AF_UNION
48-
};
37+
mp_obj_base_t base;
38+
qstr name;
39+
uint8_t idx;
40+
uint8_t fn;
41+
uint8_t unit;
42+
uint8_t type;
43+
44+
union {
45+
void *reg;
46+
47+
PIN_DEFS_PORT_AF_UNION
48+
};
4949
} pin_af_obj_t;
5050

5151
typedef struct {
52-
mp_obj_base_t base;
53-
qstr name;
54-
uint32_t pin : 8;
55-
uint32_t num_af : 4;
56-
uint32_t adc_channel : 5; // Some ARM processors use 32 bits/PORT
57-
uint32_t adc_num : 3; // 1 bit per ADC
58-
const pin_af_obj_t *af;
59-
uint32_t pull;
52+
mp_obj_base_t base;
53+
qstr name;
54+
uint32_t pin : 8;
55+
uint32_t num_af : 4;
56+
uint32_t adc_channel : 5; // Some ARM processors use 32 bits/PORT
57+
uint32_t adc_num : 3; // 1 bit per ADC
58+
const pin_af_obj_t *af;
59+
uint32_t pull;
6060
} pin_obj_t;
6161

6262
extern const mp_obj_type_t pin_type;
6363
extern const mp_obj_type_t pin_af_type;
6464

6565
typedef struct {
66-
const char *name;
67-
const pin_obj_t *pin;
66+
const char *name;
67+
const pin_obj_t *pin;
6868
} pin_named_pin_t;
6969

7070
extern const pin_named_pin_t pin_board_pins[];
7171
extern const pin_named_pin_t pin_cpu_pins[];
7272

73-
//extern pin_map_obj_t pin_map_obj;
73+
// extern pin_map_obj_t pin_map_obj;
7474

7575
typedef struct {
7676
mp_obj_base_t base;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy