diff --git a/device/adc.c b/device/adc.c index 0ba4ca6..1d02bca 100644 --- a/device/adc.c +++ b/device/adc.c @@ -64,11 +64,11 @@ static int mr_adc_close(struct mr_dev *dev) struct mr_adc_ops *ops = (struct mr_adc_ops *)dev->drv->ops; /* Disable all channels */ - for (int i = 0; i < 32; i++) + for (size_t i = 0; i < 32; i++) { if (MR_BIT_IS_SET(adc->channel, (1 << i)) == MR_ENABLE) { - ops->channel_configure(adc, i, MR_DISABLE); + ops->channel_configure(adc, (int)i, MR_DISABLE); MR_BIT_CLR(adc->channel, (1 << i)); } } @@ -81,7 +81,7 @@ static ssize_t mr_adc_read(struct mr_dev *dev, int off, void *buf, size_t size, struct mr_adc *adc = (struct mr_adc *)dev; struct mr_adc_ops *ops = (struct mr_adc_ops *)dev->drv->ops; uint32_t *rd_buf = (uint32_t *)buf; - ssize_t rd_size = 0; + ssize_t rd_size; /* Check if the channel is enabled */ if (MR_BIT_IS_SET(adc->channel, (1 << off)) == MR_DISABLE) diff --git a/device/dac.c b/device/dac.c index 72f1d34..b536858 100644 --- a/device/dac.c +++ b/device/dac.c @@ -64,11 +64,11 @@ static int mr_dac_close(struct mr_dev *dev) struct mr_dac_ops *ops = (struct mr_dac_ops *)dev->drv->ops; /* Disable all channels */ - for (int i = 0; i < 32; i++) + for (size_t i = 0; i < 32; i++) { if (MR_BIT_IS_SET(dac->channel, (1 << i)) == MR_ENABLE) { - ops->channel_configure(dac, i, MR_DISABLE); + ops->channel_configure(dac, (int)i, MR_DISABLE); MR_BIT_CLR(dac->channel, (1 << i)); } } @@ -81,7 +81,7 @@ static ssize_t mr_dac_write(struct mr_dev *dev, int off, const void *buf, size_t struct mr_dac *dac = (struct mr_dac *)dev; struct mr_dac_ops *ops = (struct mr_dac_ops *)dev->drv->ops; uint32_t *wr_buf = (uint32_t *)buf; - ssize_t wr_size = 0; + ssize_t wr_size; /* Check if the channel is enabled */ if (MR_BIT_IS_SET(dac->channel, (1 << off)) == MR_DISABLE) diff --git a/device/i2c.c b/device/i2c.c index 41f16dd..6e0295a 100644 --- a/device/i2c.c +++ b/device/i2c.c @@ -194,7 +194,7 @@ MR_INLINE ssize_t i2c_dev_read(struct mr_i2c_dev *i2c_dev, uint8_t *buf, size_t struct mr_i2c_bus *i2c_bus = (struct mr_i2c_bus *)i2c_dev->dev.parent; struct mr_i2c_bus_ops *ops = (struct mr_i2c_bus_ops *)i2c_bus->dev.drv->ops; uint8_t *rd_buf = (uint8_t *)buf; - ssize_t rd_size = 0; + ssize_t rd_size; for (rd_size = 0; rd_size < size; rd_size += sizeof(*rd_buf)) { @@ -209,7 +209,7 @@ MR_INLINE ssize_t i2c_dev_write(struct mr_i2c_dev *i2c_dev, const uint8_t *buf, struct mr_i2c_bus *i2c_bus = (struct mr_i2c_bus *)i2c_dev->dev.parent; struct mr_i2c_bus_ops *ops = (struct mr_i2c_bus_ops *)i2c_bus->dev.drv->ops; uint8_t *wr_buf = (uint8_t *)buf; - ssize_t wr_size = 0; + ssize_t wr_size; for (wr_size = 0; wr_size < size; wr_size += sizeof(*wr_buf)) { diff --git a/device/pin.c b/device/pin.c index ee38e19..d1d4c60 100644 --- a/device/pin.c +++ b/device/pin.c @@ -96,7 +96,7 @@ static ssize_t mr_pin_read(struct mr_dev *dev, int off, void *buf, size_t size, struct mr_pin *pin = (struct mr_pin *)dev; struct mr_pin_ops *ops = (struct mr_pin_ops *)dev->drv->ops; uint8_t *rd_buf = (uint8_t *)buf; - ssize_t rd_size = 0; + ssize_t rd_size; /* Check offset is valid */ if (off < 0) @@ -117,7 +117,7 @@ static ssize_t mr_pin_write(struct mr_dev *dev, int off, const void *buf, size_t struct mr_pin *pin = (struct mr_pin *)dev; struct mr_pin_ops *ops = (struct mr_pin_ops *)dev->drv->ops; uint8_t *wr_buf = (uint8_t *)buf; - ssize_t wr_size = 0; + ssize_t wr_size; /* Check offset is valid */ if (off < 0) @@ -168,8 +168,7 @@ static ssize_t mr_pin_isr(struct mr_dev *dev, int event, void *args) ssize_t number = *(int *)args; /* If the irq exists, call it */ - struct mr_list *list = MR_NULL; - for (list = pin->irq_list.next; list != &pin->irq_list; list = list->next) + for (struct mr_list *list = pin->irq_list.next; list != &pin->irq_list; list = list->next) { struct pin_irq *irq = (struct pin_irq *)MR_CONTAINER_OF(list, struct pin_irq, list); if (irq->number == number) diff --git a/device/pwm.c b/device/pwm.c index bbaba33..0957f88 100644 --- a/device/pwm.c +++ b/device/pwm.c @@ -100,8 +100,7 @@ static int pwm_calculate(struct mr_pwm *pwm, uint32_t freq) } /* Optimize the prescaler and period */ - uint32_t divisor = 0; - for (divisor = 9; divisor > 1; divisor--) + for (uint32_t divisor = 9; divisor > 1; divisor--) { /* Check if reload value can be divided by current divisor */ while ((psc_best % divisor) == 0) @@ -152,11 +151,11 @@ static int mr_pwm_close(struct mr_dev *dev) struct mr_pwm_ops *ops = (struct mr_pwm_ops *)dev->drv->ops; /* Disable all channels */ - for (int i = 0; i < 32; i++) + for (size_t i = 0; i < 32; i++) { if (MR_BIT_IS_SET(pwm->channel, (1 << i)) == MR_ENABLE) { - ops->channel_configure(pwm, i, MR_DISABLE, MR_PWM_POLARITY_NORMAL); + ops->channel_configure(pwm, (int)i, MR_DISABLE, MR_PWM_POLARITY_NORMAL); MR_BIT_CLR(pwm->channel, (1 << i)); } } @@ -169,7 +168,7 @@ static ssize_t mr_pwm_read(struct mr_dev *dev, int off, void *buf, size_t size, struct mr_pwm *pwm = (struct mr_pwm *)dev; struct mr_pwm_ops *ops = (struct mr_pwm_ops *)dev->drv->ops; uint32_t *rd_buf = (uint32_t *)buf; - ssize_t rd_size = 0; + ssize_t rd_size; /* Check if the channel is enabled */ if (MR_BIT_IS_SET(pwm->channel, (1 << off)) == MR_DISABLE) @@ -191,7 +190,7 @@ static ssize_t mr_pwm_write(struct mr_dev *dev, int off, const void *buf, size_t struct mr_pwm *pwm = (struct mr_pwm *)dev; struct mr_pwm_ops *ops = (struct mr_pwm_ops *)dev->drv->ops; uint32_t *wr_buf = (uint32_t *)buf; - ssize_t wr_size = 0; + ssize_t wr_size; /* Check if the channel is enabled */ if (MR_BIT_IS_SET(pwm->channel, (1 << off)) == MR_DISABLE) diff --git a/device/serial.c b/device/serial.c index 988c60f..a4df74f 100644 --- a/device/serial.c +++ b/device/serial.c @@ -46,7 +46,7 @@ static ssize_t mr_serial_read(struct mr_dev *dev, int off, void *buf, size_t siz struct mr_serial *serial = (struct mr_serial *)dev; struct mr_serial_ops *ops = (struct mr_serial_ops *)dev->drv->ops; uint8_t *rd_buf = (uint8_t *)buf; - ssize_t rd_size = 0; + ssize_t rd_size; if (mr_ringbuf_get_bufsz(&serial->rd_fifo) == 0) { @@ -67,7 +67,7 @@ static ssize_t mr_serial_write(struct mr_dev *dev, int off, const void *buf, siz struct mr_serial *serial = (struct mr_serial *)dev; struct mr_serial_ops *ops = (struct mr_serial_ops *)dev->drv->ops; uint8_t *wr_buf = (uint8_t *)buf; - ssize_t wr_size = 0; + ssize_t wr_size; if ((async == MR_SYNC) || (mr_ringbuf_get_bufsz(&serial->wr_fifo) == 0)) { @@ -231,7 +231,7 @@ static ssize_t mr_serial_isr(struct mr_dev *dev, int event, void *args) case MR_ISR_SERIAL_WR_INT: { /* Write data from FIFO, if FIFO is empty, stop transmit */ - uint8_t data = 0; + uint8_t data; if (mr_ringbuf_pop(&serial->wr_fifo, &data) == sizeof(data)) { ops->write(serial, data); diff --git a/device/soft_i2c.c b/device/soft_i2c.c index c37c688..5501795 100644 --- a/device/soft_i2c.c +++ b/device/soft_i2c.c @@ -33,7 +33,7 @@ MR_INLINE void soft_i2c_bus_sda_set(struct mr_soft_i2c_bus *soft_i2c_bus, uint8_ MR_INLINE uint8_t soft_i2c_sda_get(struct mr_soft_i2c_bus *soft_i2c_bus) { - uint8_t value = 0; + uint8_t value; mr_dev_ioctl(soft_i2c_bus->desc, MR_CTL_PIN_SET_NUMBER, &soft_i2c_bus->sda_pin); mr_dev_read(soft_i2c_bus->desc, &value, sizeof(value)); diff --git a/device/spi.c b/device/spi.c index b143c59..c0088fb 100644 --- a/device/spi.c +++ b/device/spi.c @@ -263,7 +263,7 @@ static ssize_t spi_dev_transfer(struct mr_spi_dev *spi_dev, void *rd_buf, const { struct mr_spi_bus *spi_bus = (struct mr_spi_bus *)spi_dev->dev.parent; struct mr_spi_bus_ops *ops = (struct mr_spi_bus_ops *)spi_bus->dev.drv->ops; - size_t tf_size = 0; + size_t tf_size; if (rdwr == MR_SPI_RD) { diff --git a/device/timer.c b/device/timer.c index e8e02de..d0c90e2 100644 --- a/device/timer.c +++ b/device/timer.c @@ -14,7 +14,7 @@ static int timer_calculate(struct mr_timer *timer, uint32_t timeout) { uint32_t clk = timer->info->clk, psc_max = timer->info->prescaler_max, per_max = timer->info->period_max; uint32_t psc_best = 0, per_best = 0, reload_best = 0; - uint32_t psc = 0; + uint32_t psc; int error_min = INT32_MAX; /* Check the clock */ @@ -127,7 +127,7 @@ static ssize_t mr_timer_read(struct mr_dev *dev, int off, void *buf, size_t size struct mr_timer *timer = (struct mr_timer *)dev; struct mr_timer_ops *ops = (struct mr_timer_ops *)dev->drv->ops; uint32_t *rd_buf = (uint32_t *)buf; - ssize_t rd_size = 0; + ssize_t rd_size; MR_BIT_CLR(size, sizeof(*rd_buf) - 1); for (rd_size = 0; rd_size < size; rd_size += sizeof(*rd_buf)) @@ -148,7 +148,7 @@ static ssize_t mr_timer_write(struct mr_dev *dev, int off, const void *buf, size struct mr_timer_ops *ops = (struct mr_timer_ops *)dev->drv->ops; uint32_t *wr_buf = (uint32_t *)buf; uint32_t timeout = 0; - ssize_t wr_size = 0; + ssize_t wr_size; /* Only the last write is valid */ MR_BIT_CLR(size, sizeof(*wr_buf) - 1); diff --git a/document/device/serial/serial.md b/document/device/serial/serial.md index 37cbdca..fd9daf4 100644 --- a/document/device/serial/serial.md +++ b/document/device/serial/serial.md @@ -89,7 +89,7 @@ SERIAL设备配置: - `stop_bits`:停止位数。 - `parity`:校验位。 - `bit_order`:数据传输顺序。 -- `invert`:极性反转。 +- `polarity`:极性反转。 ```c /* 设置默认配置 */ diff --git a/document/device/serial/serial_EN.md b/document/device/serial/serial_EN.md index d0af964..e7f5bb4 100644 --- a/document/device/serial/serial_EN.md +++ b/document/device/serial/serial_EN.md @@ -91,7 +91,7 @@ SERIAL device configuration: - `stop_bits`: Stop bits - `parity`: Parity check - `bit_order`: Data transmission order -- `invert`: Polarity inversion +- `polarity`: Polarity inversion ```c /* Set default configuration */ diff --git a/include/mr_def.h b/include/mr_def.h index 7e541f7..9adb32f 100644 --- a/include/mr_def.h +++ b/include/mr_def.h @@ -66,7 +66,7 @@ typedef int (*mr_init_fn_t)(void); * @brief Exports an auto initialization function with level. */ #define MR_INIT_EXPORT(fn, level) \ - MR_USED const mr_init_fn_t _mr_auto_init_##fn MR_SECTION(".auto_init."level) = fn + MR_USED const mr_init_fn_t _mr_auto_init_##fn MR_SECTION(".mr_auto_init."level) = fn /** * @brief Exports a board auto initialization function. diff --git a/include/mr_service.h b/include/mr_service.h index c1cc386..e40a4b8 100644 --- a/include/mr_service.h +++ b/include/mr_service.h @@ -103,7 +103,7 @@ extern "C" { * * @return The number of elements in the array. */ -#define MR_ARRAY_SIZE(array) (sizeof(array)/sizeof((array)[0])) +#define MR_ARRAY_NUM(array) (sizeof(array)/sizeof((array)[0])) /** * @brief This macro function gets the maximum of two values. diff --git a/source/device.c b/source/device.c index ad6147b..7069958 100644 --- a/source/device.c +++ b/source/device.c @@ -74,13 +74,12 @@ MR_INLINE const char *dev_clear_path(const char *path) MR_INLINE int dev_register_by_path(struct mr_dev *parent, struct mr_dev *dev, const char *path) { char child_name[MR_CFG_NAME_MAX + 1] = {0}; - const char *child_path = MR_NULL; /* Clear the path */ path = dev_clear_path(path); /* Check whether the child path exists */ - child_path = strchr(path, '/'); + const char *child_path = strchr(path, '/'); if (child_path != MR_NULL) { /* Get the child name */ @@ -107,13 +106,12 @@ MR_INLINE int dev_register_by_path(struct mr_dev *parent, struct mr_dev *dev, co MR_INLINE struct mr_dev *dev_find_by_path(struct mr_dev *parent, const char *path) { char child_name[MR_CFG_NAME_MAX + 1] = {0}; - const char *child_path = MR_NULL; /* Clear the path */ path = dev_clear_path(path); /* Check whether the child path exists */ - child_path = strchr(path, '/'); + const char *child_path = strchr(path, '/'); if (child_path != MR_NULL) { /* Get the child name */ @@ -421,7 +419,7 @@ int mr_dev_register(struct mr_dev *dev, struct mr_dev_ops *ops, struct mr_drv *drv) { - static struct mr_dev_ops null_ops = {0}; + static struct mr_dev_ops null_ops = {MR_NULL}; MR_ASSERT(dev != MR_NULL); MR_ASSERT(dev->magic != MR_MAGIC_NUMBER);