Skip to content

Commit 9e978a8

Browse files
committed
cleanup codes
1 parent d597a96 commit 9e978a8

File tree

3 files changed

+52
-52
lines changed

3 files changed

+52
-52
lines changed

ports/raspberrypi/bindings/wiznet/PIO_SPI.c

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,48 +28,48 @@
2828
static mp_obj_t wiznet_pio_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
2929
#if CIRCUITPY_WIZNET
3030
wiznet_pio_spi_obj_t *self = mp_obj_malloc(wiznet_pio_spi_obj_t, &wiznet_pio_spi_type);
31-
#if CIRCUITPY_WIZNET_W6300
32-
enum { ARG_clock, ARG_quad_io0, ARG_quad_io1, ARG_quad_io2, ARG_quad_io3, ARG_half_duplex, ARG_quad_spi };
33-
static const mp_arg_t allowed_args[] = {
34-
{ MP_QSTR_clock, MP_ARG_REQUIRED | MP_ARG_OBJ },
35-
{ MP_QSTR_quad_io0, MP_ARG_OBJ, {.u_obj = mp_const_none} },
36-
{ MP_QSTR_quad_io1, MP_ARG_OBJ, {.u_obj = mp_const_none} },
37-
{ MP_QSTR_quad_io2, MP_ARG_OBJ, {.u_obj = mp_const_none} },
38-
{ MP_QSTR_quad_io3, MP_ARG_OBJ, {.u_obj = mp_const_none} },
39-
{ MP_QSTR_half_duplex, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
40-
};
41-
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
42-
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
43-
44-
const mcu_pin_obj_t *clock = validate_obj_is_free_pin(args[ARG_clock].u_obj, MP_QSTR_clock);
45-
const mcu_pin_obj_t *quad_io0 = validate_obj_is_free_pin_or_none(args[ARG_quad_io0].u_obj, MP_QSTR_quad_io0);
46-
const mcu_pin_obj_t *quad_io1 = validate_obj_is_free_pin_or_none(args[ARG_quad_io1].u_obj, MP_QSTR_quad_io1);
47-
const mcu_pin_obj_t *quad_io2 = validate_obj_is_free_pin_or_none(args[ARG_quad_io2].u_obj, MP_QSTR_quad_io2);
48-
const mcu_pin_obj_t *quad_io3 = validate_obj_is_free_pin_or_none(args[ARG_quad_io3].u_obj, MP_QSTR_quad_io3);
49-
50-
common_hal_wiznet_pio_qspi_construct(self, clock, quad_io0, quad_io1, quad_io2, quad_io3, args[ARG_half_duplex].u_bool);
51-
52-
#else // W55RP20
53-
enum { ARG_clock, ARG_MOSI, ARG_MISO, ARG_half_duplex };
54-
static const mp_arg_t allowed_args[] = {
55-
{ MP_QSTR_clock, MP_ARG_REQUIRED | MP_ARG_OBJ },
56-
{ MP_QSTR_MOSI, MP_ARG_OBJ, {.u_obj = mp_const_none} },
57-
{ MP_QSTR_MISO, MP_ARG_OBJ, {.u_obj = mp_const_none} },
58-
{ MP_QSTR_half_duplex, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
59-
};
60-
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
61-
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
62-
63-
const mcu_pin_obj_t *clock = validate_obj_is_free_pin(args[ARG_clock].u_obj, MP_QSTR_clock);
64-
const mcu_pin_obj_t *mosi = validate_obj_is_free_pin_or_none(args[ARG_MOSI].u_obj, MP_QSTR_mosi);
65-
const mcu_pin_obj_t *miso = validate_obj_is_free_pin_or_none(args[ARG_MISO].u_obj, MP_QSTR_miso);
66-
67-
if (!miso && !mosi) {
68-
mp_raise_ValueError(MP_ERROR_TEXT("Must provide MISO or MOSI pin"));
69-
}
70-
71-
common_hal_wiznet_pio_spi_construct(self, clock, mosi, miso, args[ARG_half_duplex].u_bool);
72-
#endif
31+
#if CIRCUITPY_WIZNET_W6300
32+
enum { ARG_clock, ARG_quad_io0, ARG_quad_io1, ARG_quad_io2, ARG_quad_io3, ARG_half_duplex, ARG_quad_spi };
33+
static const mp_arg_t allowed_args[] = {
34+
{ MP_QSTR_clock, MP_ARG_REQUIRED | MP_ARG_OBJ },
35+
{ MP_QSTR_quad_io0, MP_ARG_OBJ, {.u_obj = mp_const_none} },
36+
{ MP_QSTR_quad_io1, MP_ARG_OBJ, {.u_obj = mp_const_none} },
37+
{ MP_QSTR_quad_io2, MP_ARG_OBJ, {.u_obj = mp_const_none} },
38+
{ MP_QSTR_quad_io3, MP_ARG_OBJ, {.u_obj = mp_const_none} },
39+
{ MP_QSTR_half_duplex, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
40+
};
41+
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
42+
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
43+
44+
const mcu_pin_obj_t *clock = validate_obj_is_free_pin(args[ARG_clock].u_obj, MP_QSTR_clock);
45+
const mcu_pin_obj_t *quad_io0 = validate_obj_is_free_pin_or_none(args[ARG_quad_io0].u_obj, MP_QSTR_quad_io0);
46+
const mcu_pin_obj_t *quad_io1 = validate_obj_is_free_pin_or_none(args[ARG_quad_io1].u_obj, MP_QSTR_quad_io1);
47+
const mcu_pin_obj_t *quad_io2 = validate_obj_is_free_pin_or_none(args[ARG_quad_io2].u_obj, MP_QSTR_quad_io2);
48+
const mcu_pin_obj_t *quad_io3 = validate_obj_is_free_pin_or_none(args[ARG_quad_io3].u_obj, MP_QSTR_quad_io3);
49+
50+
common_hal_wiznet_pio_qspi_construct(self, clock, quad_io0, quad_io1, quad_io2, quad_io3, args[ARG_half_duplex].u_bool);
51+
52+
#else // W55RP20
53+
enum { ARG_clock, ARG_MOSI, ARG_MISO, ARG_half_duplex };
54+
static const mp_arg_t allowed_args[] = {
55+
{ MP_QSTR_clock, MP_ARG_REQUIRED | MP_ARG_OBJ },
56+
{ MP_QSTR_MOSI, MP_ARG_OBJ, {.u_obj = mp_const_none} },
57+
{ MP_QSTR_MISO, MP_ARG_OBJ, {.u_obj = mp_const_none} },
58+
{ MP_QSTR_half_duplex, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
59+
};
60+
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
61+
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
62+
63+
const mcu_pin_obj_t *clock = validate_obj_is_free_pin(args[ARG_clock].u_obj, MP_QSTR_clock);
64+
const mcu_pin_obj_t *mosi = validate_obj_is_free_pin_or_none(args[ARG_MOSI].u_obj, MP_QSTR_mosi);
65+
const mcu_pin_obj_t *miso = validate_obj_is_free_pin_or_none(args[ARG_MISO].u_obj, MP_QSTR_miso);
66+
67+
if (!miso && !mosi) {
68+
mp_raise_ValueError(MP_ERROR_TEXT("Must provide MISO or MOSI pin"));
69+
}
70+
71+
common_hal_wiznet_pio_spi_construct(self, clock, mosi, miso, args[ARG_half_duplex].u_bool);
72+
#endif
7373
return MP_OBJ_FROM_PTR(self);
7474
#else
7575
mp_raise_NotImplementedError(NULL);

ports/raspberrypi/common-hal/wiznet/wizchip_pio_spi.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ static wiznet_pio_spi_state_t *active_state;
6565
static wiznet_pio_spi_funcs_t *get_wiznet_pio_spi_impl(void);
6666

6767
#if CIRCUITPY_WIZNET_W6300
68-
static uint16_t mk_cmd_buf(uint8_t *pdst, uint8_t opcode, uint16_t addr){
69-
pdst[0] = ( (opcode >> 7 & 0x01) << 4 ) | ( (opcode >> 6 & 0x01) << 0 );
70-
pdst[1] = ( (opcode >> 5 & 0x01) << 4 ) | ( (opcode >> 4 & 0x01) << 0 );
71-
pdst[2] = ( (opcode >> 3 & 0x01) << 4 ) | ( (opcode >> 2 & 0x01) << 0 );
72-
pdst[3] = ( (opcode >> 1 & 0x01) << 4 ) | ( (opcode >> 0 & 0x01) << 0 );
68+
static uint16_t mk_cmd_buf(uint8_t *pdst, uint8_t opcode, uint16_t addr) {
69+
pdst[0] = ((opcode >> 7 & 0x01) << 4) | ((opcode >> 6 & 0x01) << 0);
70+
pdst[1] = ((opcode >> 5 & 0x01) << 4) | ((opcode >> 4 & 0x01) << 0);
71+
pdst[2] = ((opcode >> 3 & 0x01) << 4) | ((opcode >> 2 & 0x01) << 0);
72+
pdst[3] = ((opcode >> 1 & 0x01) << 4) | ((opcode >> 0 & 0x01) << 0);
7373

7474
pdst[4] = ((uint8_t)(addr >> 8) & 0xFF);
7575
pdst[5] = ((uint8_t)(addr >> 0) & 0xFF);
@@ -78,7 +78,7 @@ static uint16_t mk_cmd_buf(uint8_t *pdst, uint8_t opcode, uint16_t addr){
7878

7979
return 6 + 1;
8080
}
81-
#endif
81+
#endif
8282

8383
// Initialise our gpios
8484
static void wiznet_pio_spi_gpio_setup(wiznet_pio_spi_state_t *state) {
@@ -256,7 +256,7 @@ void wiznet_pio_spi_close(wiznet_pio_spi_handle_t handle) {
256256
if (state) {
257257
if (state->pio_sm >= 0) {
258258
if (state->pio_offset != -1) {
259-
pio_remove_program(state->pio, &WIZNET_PIO_SPI_PROGRAM_FUNC , state->pio_offset);
259+
pio_remove_program(state->pio, &WIZNET_PIO_SPI_PROGRAM_FUNC, state->pio_offset);
260260
}
261261

262262
pio_sm_unclaim(state->pio, state->pio_sm);
@@ -317,7 +317,7 @@ static void wiznet_pio_spi_frame_end(void) {
317317
#if CIRCUITPY_WIZNET_W6300
318318

319319
bool wiznet_pio_spi_read_byte(uint8_t op_code, uint16_t AddrSel, uint8_t *rx, uint16_t rx_length) {
320-
uint8_t command_buf[8] = {0,};
320+
uint8_t command_buf[8] = {0, };
321321
uint16_t command_len = mk_cmd_buf(command_buf, op_code, AddrSel);
322322
uint32_t loop_cnt = 0;
323323

@@ -380,7 +380,7 @@ bool wiznet_pio_spi_read_byte(uint8_t op_code, uint16_t AddrSel, uint8_t *rx, ui
380380
}
381381

382382
bool wiznet_pio_spi_write_byte(uint8_t op_code, uint16_t AddrSel, const uint8_t *tx, uint16_t tx_length) {
383-
uint8_t command_buf[8] = {0,};
383+
uint8_t command_buf[8] = {0, };
384384
uint16_t command_len = mk_cmd_buf(command_buf, op_code, AddrSel);
385385
uint32_t loop_cnt = 0;
386386
tx_length = tx_length + command_len;

ports/raspberrypi/common-hal/wiznet/wizchip_pio_spi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include <stdint.h>
1111

12-
typedef struct wiznet_pio_spi_funcs** wiznet_pio_spi_handle_t;
12+
typedef struct wiznet_pio_spi_funcs **wiznet_pio_spi_handle_t;
1313
#if CIRCUITPY_WIZNET_W6300
1414
typedef struct wiznet_pio_spi_config
1515
{

0 commit comments

Comments
 (0)