Skip to content

Commit 159050b

Browse files
authored
Merge pull request #1704 from antoinevg/antoinevg/consistent-structs
Standardize `struct` + `typedef` usage.
2 parents 1e9991e + d49b5b1 commit 159050b

23 files changed

Lines changed: 73 additions & 97 deletions

firmware/common/cpld_jtag.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#include "gpio.h"
2727

28-
typedef struct jtag_gpio_t {
28+
typedef struct {
2929
gpio_t gpio_tck;
3030
#ifndef PRALINE
3131
gpio_t gpio_tms;
@@ -38,7 +38,7 @@ typedef struct jtag_gpio_t {
3838
#endif
3939
} jtag_gpio_t;
4040

41-
typedef struct jtag_t {
41+
typedef struct {
4242
jtag_gpio_t* const gpio;
4343
} jtag_t;
4444

firmware/common/fault_handler.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
// TODO: Move all this to a Cortex-M(?) include file, since these
3030
// structures are supposedly the same between processors (to an
3131
// undetermined extent).
32-
typedef struct armv7m_scb_t armv7m_scb_t;
33-
34-
struct armv7m_scb_t {
32+
typedef struct {
3533
volatile const uint32_t CPUID;
3634
volatile uint32_t ICSR;
3735
volatile uint32_t VTOR;
@@ -63,7 +61,7 @@ struct armv7m_scb_t {
6361
volatile const uint32_t ID_ISAR4;
6462
volatile const uint32_t __reserved_0x74_0x87[5];
6563
volatile uint32_t CPACR;
66-
} __attribute__((packed));
64+
} __attribute__((packed)) armv7m_scb_t;
6765

6866
static armv7m_scb_t* const SCB = (armv7m_scb_t*) SCB_BASE;
6967

firmware/common/fpga.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,11 @@ typedef enum {
3636
FPGA_QUARTER_SHIFT_MODE_DOWN = 0b01,
3737
} fpga_quarter_shift_mode_t;
3838

39-
struct fpga_driver_t; // IWYU pragma: keep - fixed in #1704
40-
typedef struct fpga_driver_t fpga_driver_t;
41-
42-
struct fpga_driver_t {
39+
typedef struct {
4340
ice40_spi_driver_t* bus;
4441
uint8_t regs[FPGA_NUM_REGS];
4542
uint8_t regs_dirty;
46-
};
43+
} fpga_driver_t;
4744

4845
struct fpga_loader_t {
4946
/* Start address added as an offset to all read() calls. */

firmware/common/gpio_lpc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* register #defines and API declarations into separate header files.
3030
*/
3131

32-
typedef struct gpio_port {
32+
typedef struct {
3333
volatile uint32_t dir; /* +0x000 */
3434
uint32_t _reserved0[31];
3535
volatile uint32_t mask; /* +0x080 */

firmware/common/i2c_bus.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,18 @@
2525
#include <stddef.h>
2626
#include <stdint.h>
2727

28-
struct i2c_bus_t; // IWYU pragma: keep - fixed in #1704
29-
typedef struct i2c_bus_t i2c_bus_t;
30-
31-
struct i2c_bus_t {
28+
typedef struct _i2c_bus_t {
3229
void* const obj;
33-
void (*start)(i2c_bus_t* const bus, const void* const config);
34-
void (*stop)(i2c_bus_t* const bus);
30+
void (*start)(struct _i2c_bus_t* const bus, const void* const config);
31+
void (*stop)(struct _i2c_bus_t* const bus);
3532
void (*transfer)(
36-
i2c_bus_t* const bus,
33+
struct _i2c_bus_t* const bus,
3734
const uint_fast8_t peripheral_address,
3835
const uint8_t* const tx,
3936
const size_t tx_count,
4037
uint8_t* const rx,
4138
const size_t rx_count);
42-
};
39+
} i2c_bus_t;
4340

4441
void i2c_bus_start(i2c_bus_t* const bus, const void* const config);
4542
void i2c_bus_stop(i2c_bus_t* const bus);

firmware/common/i2c_lpc.h

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

2929
#include "i2c_bus.h"
3030

31-
typedef struct i2c_lpc_config_t {
31+
typedef struct {
3232
const uint16_t duty_cycle_count;
3333
} i2c_lpc_config_t;
3434

firmware/common/ice40_spi.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,12 @@
2828
#include "gpio.h"
2929
#include "spi_bus.h"
3030

31-
struct ice40_spi_driver_t; // IWYU pragma: keep - fixed in #1704
32-
typedef struct ice40_spi_driver_t ice40_spi_driver_t;
33-
34-
struct ice40_spi_driver_t {
31+
typedef struct {
3532
spi_bus_t* const bus;
3633
gpio_t gpio_select;
3734
gpio_t gpio_creset;
3835
gpio_t gpio_cdone;
39-
};
36+
} ice40_spi_driver_t;
4037

4138
void ice40_spi_target_init(ice40_spi_driver_t* const drv);
4239
uint8_t ice40_spi_read(ice40_spi_driver_t* const drv, uint8_t r);

firmware/common/max2831.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,21 @@ typedef enum {
4747
MAX2831_RX_HPF_600_KHZ = 3,
4848
} max2831_rx_hpf_freq_t;
4949

50-
struct max2831_driver_t; // IWYU pragma: keep - fixed in #1704
51-
typedef struct max2831_driver_t max2831_driver_t;
52-
53-
struct max2831_driver_t {
50+
typedef struct _max2831_driver_t {
5451
spi_bus_t* bus;
5552
gpio_t gpio_enable;
5653
gpio_t gpio_rxtx;
5754
gpio_t gpio_rxhp;
5855
gpio_t gpio_ld;
59-
void (*target_init)(max2831_driver_t* const drv);
60-
void (*set_mode)(max2831_driver_t* const drv, const max2831_mode_t new_mode);
56+
void (*target_init)(struct _max2831_driver_t* const drv);
57+
void (*set_mode)(
58+
struct _max2831_driver_t* const drv,
59+
const max2831_mode_t new_mode);
6160
max2831_mode_t mode;
6261
uint16_t regs[MAX2831_NUM_REGS];
6362
uint16_t regs_dirty;
6463
uint32_t desired_lpf_bw;
65-
};
64+
} max2831_driver_t;
6665

6766
/* Initialize chip. */
6867
extern void max2831_setup(max2831_driver_t* const drv);

firmware/common/max2837.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,19 @@ typedef enum {
4040
MAX2837_MODE_RX
4141
} max2837_mode_t;
4242

43-
struct max2837_driver_t; // IWYU pragma: keep - fixed in #1704
44-
typedef struct max2837_driver_t max2837_driver_t;
45-
46-
struct max2837_driver_t {
43+
typedef struct _max2837_driver_t {
4744
spi_bus_t* bus;
4845
gpio_t gpio_enable;
4946
gpio_t gpio_rx_enable;
5047
gpio_t gpio_tx_enable;
51-
void (*target_init)(max2837_driver_t* const drv);
52-
void (*set_mode)(max2837_driver_t* const drv, const max2837_mode_t new_mode);
48+
void (*target_init)(struct _max2837_driver_t* const drv);
49+
void (*set_mode)(
50+
struct _max2837_driver_t* const drv,
51+
const max2837_mode_t new_mode);
5352
max2837_mode_t mode;
5453
uint16_t regs[MAX2837_NUM_REGS];
5554
uint32_t regs_dirty;
56-
};
55+
} max2837_driver_t;
5756

5857
/* Initialize chip. */
5958
extern void max2837_setup(max2837_driver_t* const drv);

firmware/common/max2839.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,18 @@ typedef enum {
4343
MAX2839_MODE_CLKOUT,
4444
} max2839_mode_t;
4545

46-
struct max2839_driver_t; // IWYU pragma: keep - fixed in #1704
47-
typedef struct max2839_driver_t max2839_driver_t;
48-
49-
struct max2839_driver_t {
46+
typedef struct _max2839_driver_t {
5047
spi_bus_t* bus;
5148
gpio_t gpio_enable;
5249
gpio_t gpio_rxtx;
53-
void (*target_init)(max2839_driver_t* const drv);
54-
void (*set_mode)(max2839_driver_t* const drv, const max2839_mode_t new_mode);
50+
void (*target_init)(struct _max2839_driver_t* const drv);
51+
void (*set_mode)(
52+
struct _max2839_driver_t* const drv,
53+
const max2839_mode_t new_mode);
5554
max2839_mode_t mode;
5655
uint16_t regs[MAX2839_NUM_REGS];
5756
uint32_t regs_dirty;
58-
};
57+
} max2839_driver_t;
5958

6059
/* Initialize chip. */
6160
extern void max2839_setup(max2839_driver_t* const drv);

0 commit comments

Comments
 (0)