Skip to content

Commit 046b6a7

Browse files
committed
firmware: standardize recursive struct+typedef usage
1 parent dbd627a commit 046b6a7

9 files changed

Lines changed: 49 additions & 65 deletions

File tree

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/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);

firmware/common/max5864.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,10 @@
2424

2525
#include "spi_bus.h"
2626

27-
struct max5864_driver_t; // IWYU pragma: keep - fixed in #1704
28-
typedef struct max5864_driver_t max5864_driver_t;
29-
30-
struct max5864_driver_t {
27+
typedef struct _max5864_driver_t {
3128
spi_bus_t* const bus;
32-
void (*target_init)(max5864_driver_t* const drv);
33-
};
29+
void (*target_init)(struct _max5864_driver_t* const drv);
30+
} max5864_driver_t;
3431

3532
void max5864_setup(max5864_driver_t* const drv);
3633

firmware/common/spi_bus.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ typedef struct {
2929
const size_t count;
3030
} spi_transfer_t;
3131

32-
struct spi_bus_t; // IWYU pragma: keep - fixed in #1704
33-
typedef struct spi_bus_t spi_bus_t;
34-
35-
struct spi_bus_t {
32+
typedef struct _spi_bus_t {
3633
void* const obj;
3734
const void* config;
38-
void (*start)(spi_bus_t* const bus, const void* const config);
39-
void (*stop)(spi_bus_t* const bus);
40-
void (*transfer)(spi_bus_t* const bus, void* const data, const size_t count);
35+
void (*start)(struct _spi_bus_t* const bus, const void* const config);
36+
void (*stop)(struct _spi_bus_t* const bus);
37+
void (*transfer)(
38+
struct _spi_bus_t* const bus,
39+
void* const data,
40+
const size_t count);
4141
void (*transfer_gather)(
42-
spi_bus_t* const bus,
42+
struct _spi_bus_t* const bus,
4343
const spi_transfer_t* const transfers,
4444
const size_t count);
45-
};
45+
} spi_bus_t;
4646

4747
void spi_bus_start(spi_bus_t* const bus, const void* const config);
4848
void spi_bus_stop(spi_bus_t* const bus);

firmware/common/usb_queue.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,25 @@
2929

3030
#include "usb_type.h"
3131

32-
typedef struct _usb_transfer_t usb_transfer_t;
33-
typedef struct _usb_queue_t usb_queue_t;
3432
typedef void (*transfer_completion_cb)(void*, unsigned int);
3533

3634
// This is an opaque datatype. Thou shall not touch these members.
37-
struct _usb_transfer_t {
35+
typedef struct _usb_transfer_t {
3836
struct _usb_transfer_t* next;
3937
usb_transfer_descriptor_t td ATTR_ALIGNED(64);
4038
unsigned int maximum_length;
4139
struct _usb_queue_t* queue;
4240
transfer_completion_cb completion_cb;
4341
void* user_data;
44-
};
42+
} usb_transfer_t;
4543

4644
// This is an opaque datatype. Thou shall not touch these members.
47-
struct _usb_queue_t {
48-
struct usb_endpoint_t* endpoint;
45+
typedef struct _usb_queue_t {
46+
usb_endpoint_t* endpoint;
4947
const unsigned int pool_size;
5048
usb_transfer_t* volatile free_transfers;
5149
usb_transfer_t* volatile active;
52-
};
50+
} usb_queue_t;
5351

5452
#define USB_DECLARE_QUEUE(endpoint_name) struct _usb_queue_t endpoint_name##_queue;
5553
#define USB_DEFINE_QUEUE(endpoint_name, _pool_size) \

firmware/common/usb_type.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,13 @@ typedef struct {
144144
uint8_t* wcid_extended_properties_descriptor;
145145
} usb_device_t;
146146

147-
typedef struct usb_endpoint_t usb_endpoint_t;
148-
149-
struct usb_endpoint_t {
147+
typedef struct _usb_endpoint_t {
150148
usb_setup_t setup;
151149
uint8_t buffer[32]; // Buffer for use during IN stage.
152150
const uint_fast8_t address;
153151
usb_device_t* const device;
154-
usb_endpoint_t* const in;
155-
usb_endpoint_t* const out;
156-
void (*setup_complete)(usb_endpoint_t* const endpoint);
157-
void (*transfer_complete)(usb_endpoint_t* const endpoint);
158-
};
152+
struct _usb_endpoint_t* const in;
153+
struct _usb_endpoint_t* const out;
154+
void (*setup_complete)(struct _usb_endpoint_t* const endpoint);
155+
void (*transfer_complete)(struct _usb_endpoint_t* const endpoint);
156+
} usb_endpoint_t;

firmware/common/w25q80bv.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,15 @@ typedef union {
3939
uint8_t id_8b[8]; /* 8*8bits 64bits Unique ID */
4040
} w25q80bv_unique_id_t;
4141

42-
struct w25q80bv_driver_t; // IWYU pragma: keep - fixed in #1704
43-
typedef struct w25q80bv_driver_t w25q80bv_driver_t;
44-
45-
struct w25q80bv_driver_t {
42+
typedef struct _w25q80bv_driver_t {
4643
spi_bus_t* bus;
4744
gpio_t gpio_hold;
4845
gpio_t gpio_wp;
49-
void (*target_init)(w25q80bv_driver_t* const drv);
46+
void (*target_init)(struct _w25q80bv_driver_t* const drv);
5047
size_t page_len;
5148
size_t num_pages;
5249
size_t num_bytes;
53-
};
50+
} w25q80bv_driver_t;
5451

5552
void w25q80bv_setup(w25q80bv_driver_t* const drv);
5653
void w25q80bv_get_full_status(w25q80bv_driver_t* const drv, uint8_t* data);

0 commit comments

Comments
 (0)