code style/type safety/docs/typos

This commit is contained in:
rusefi 2019-08-10 11:13:41 -04:00
parent 7768134a46
commit ee41d37c08
6 changed files with 37 additions and 43 deletions

View File

@ -49,11 +49,12 @@ static struct gpiochip chips[BOARD_EXT_GPIOCHIPS];
/* Local functions. */
/*==========================================================================*/
static struct gpiochip *gpiochip_find(unsigned int pin)
/**
* @return pointer to GPIO device for specified pin
*/
static struct gpiochip *gpiochip_find(brain_pin_e pin)
{
int i;
for (i = 0; i < BOARD_EXT_GPIOCHIPS; i++) {
for (int i = 0; i < BOARD_EXT_GPIOCHIPS; i++) {
struct gpiochip *chip = &chips[i];
if ((pin >= chip->base) && (pin < (chip->base + chip->size)))
@ -72,7 +73,7 @@ static struct gpiochip *gpiochip_find(unsigned int pin)
* @details
*/
int gpiochips_getPinOffset(unsigned int pin)
int gpiochips_getPinOffset(brain_pin_e pin)
{
struct gpiochip *chip = gpiochip_find(pin);
@ -88,8 +89,7 @@ int gpiochips_getPinOffset(unsigned int pin)
* @details return gpiochip name
*/
const char *gpiochips_getChipName(unsigned int pin)
{
const char *gpiochips_getChipName(brain_pin_e pin) {
struct gpiochip *chip = gpiochip_find(pin);
if (chip)
@ -103,7 +103,7 @@ const char *gpiochips_getChipName(unsigned int pin)
* @details return pin name or gpiochip name (if no pins names provided)
*/
const char *gpiochips_getPinName(unsigned int pin)
const char *gpiochips_getPinName(brain_pin_e pin)
{
int offset;
struct gpiochip *chip = gpiochip_find(pin);
@ -140,6 +140,7 @@ int gpiochip_register(const char *name, struct gpiochip_ops *ops, size_t size, v
if ((!ops) || (!size))
return -1;
/* no 'writePad' and no 'readPad' implementation? return error code */
if ((!ops->writePad) && (!ops->readPad))
return -1;
@ -283,7 +284,7 @@ int gpiochips_readPad(brain_pin_e pin)
/**
* @brief Get total pin count allocated for external gpio chips.
* @details Will also include unused pins for chips that was registred
* @details Will also include unused pins for chips that was registered
* but later fails to init.
*/
@ -294,22 +295,19 @@ int gpiochips_get_total_pins(void)
#else /* BOARD_EXT_GPIOCHIPS > 0 */
int gpiochips_getPinOffset(unsigned int pin)
{
int gpiochips_getPinOffset(brain_pin_e pin) {
(void)pin;
return -1;
}
const char *gpiochips_getChipName(unsigned int pin)
{
const char *gpiochips_getChipName(brain_pin_e pin) {
(void)pin;
return NULL;
}
const char *gpiochips_getPinName(unsigned int pin)
{
const char *gpiochips_getPinName(brain_pin_e pin) {
(void)pin;
return NULL;

View File

@ -26,19 +26,19 @@ extern "C"
#endif /* __cplusplus */
struct gpiochip_ops {
int (*setPadMode)(void *data, unsigned int pin, int mode);
int (*writePad)(void *data, unsigned int pin, int value);
int (*readPad)(void *data, unsigned int pin);
int (*getDiag)(void *data, unsigned int pin);
int (*setPadMode)(void *data, brain_pin_e pin, int mode);
int (*writePad)(void *data, brain_pin_e pin, int value);
int (*readPad)(void *data, brain_pin_e pin);
int (*getDiag)(void *data, brain_pin_e pin);
int (*init)(void *data);
int (*deinit)(void *data);
};
int gpiochips_getPinOffset(unsigned int pin);
const char *gpiochips_getChipName(unsigned int pin);
const char *gpiochips_getPinName(unsigned int pin);
int gpiochips_getPinOffset(brain_pin_e pin);
const char *gpiochips_getChipName(brain_pin_e pin);
const char *gpiochips_getPinName(brain_pin_e pin);
/* register gpio cgip */
/* register GPIO chip */
int gpiochip_register(const char *name, struct gpiochip_ops *ops, size_t size, void *priv);
void gpiochip_use_gpio_base(int size);

View File

@ -203,7 +203,7 @@ err:
* @details Wake up driver. Will cause input and diagnostic
* update
*/
/* todo: why is this unused? dead code? bug?
static int mc33972_wake_driver(struct mc33972_priv *chip)
{
(void)chip;
@ -212,6 +212,7 @@ static int mc33972_wake_driver(struct mc33972_priv *chip)
return 0;
}
*/
/*==========================================================================*/
/* Driver thread. */
@ -260,8 +261,7 @@ static THD_FUNCTION(mc33972_driver_thread, p)
/* Driver exported functions. */
/*==========================================================================*/
int mc33972_readPad(void *data, unsigned int pin)
{
int mc33972_readPad(void *data, brain_pin_e pin) {
struct mc33972_priv *chip;
if ((pin >= MC33972_INPUTS) || (data == NULL))
@ -273,8 +273,7 @@ int mc33972_readPad(void *data, unsigned int pin)
return !!(chip->i_state & FLAG_PIN(pin));
}
int mc33972_getDiag(void *data, unsigned int pin)
{
int mc33972_getDiag(void *data, brain_pin_e pin) {
int diag;
struct mc33972_priv *chip;

View File

@ -376,7 +376,7 @@ static THD_FUNCTION(tle6240_driver_thread, p)
/* Driver exported functions. */
/*==========================================================================*/
int tle6240_writePad(void *data, unsigned int pin, int value)
int tle6240_writePad(void *data, brain_pin_e pin, int value)
{
struct tle6240_priv *chip;
@ -409,7 +409,7 @@ int tle6240_writePad(void *data, unsigned int pin, int value)
return 0;
}
int tle6240_getDiag(void *data, unsigned int pin)
int tle6240_getDiag(void *data, brain_pin_e pin)
{
int diag;
struct tle6240_priv *chip;

View File

@ -321,20 +321,19 @@ static THD_FUNCTION(tle8888_driver_thread, p)
/* Driver exported functions. */
/*==========================================================================*/
int tle8888_writePad(void *data, unsigned int pin, int value)
{
struct tle8888_priv *chip;
int tle8888_writePad(void *data, brain_pin_e pin, int value) {
if ((pin >= TLE8888_OUTPUTS) || (data == NULL))
return -1;
chip = (struct tle8888_priv *)data;
struct tle8888_priv *chip = (struct tle8888_priv *)data;
/* TODO: lock */
if (value)
if (value) {
chip->o_state |= (1 << pin);
else
} else {
chip->o_state &= ~(1 << pin);
}
/* TODO: unlock */
/* direct driven? */
if (chip->o_direct_mask & (1 << pin)) {
@ -514,9 +513,7 @@ struct gpiochip_ops tle8888_ops = {
* @return return gpio chip base
*/
int tle8888_add(unsigned int index, const struct tle8888_config *cfg)
{
int ret;
int tle8888_add(unsigned int index, const struct tle8888_config *cfg) {
struct tle8888_priv *chip;
efiAssert(OBD_PCM_Processor_Fault, cfg != NULL, "8888CFG", 0)
@ -543,7 +540,7 @@ int tle8888_add(unsigned int index, const struct tle8888_config *cfg)
chip->drv_state = TLE8888_WAIT_INIT;
/* register, return gpio chip base */
ret = gpiochip_register(DRIVER_NAME, &tle8888_ops, TLE8888_OUTPUTS, chip);
int ret = gpiochip_register(DRIVER_NAME, &tle8888_ops, TLE8888_OUTPUTS, chip);
/* set default pin names, board init code can rewrite */
gpiochips_setPinNames(ret, tle8888_pin_names);

View File

@ -10,7 +10,7 @@
using ::testing::_;
static int testchip_readPad(void *data, unsigned int pin)
static int testchip_readPad(void *data, brain_pin_e pin)
{
if (pin & 0x01)
return 1;
@ -19,7 +19,7 @@ static int testchip_readPad(void *data, unsigned int pin)
static int io_state = 0;
static int testchip_writePad(void *data, unsigned int pin, int value)
static int testchip_writePad(void *data, brain_pin_e pin, int value)
{
if (value)
io_state |= (1 << value);
@ -39,7 +39,7 @@ static int testchip_init(void *data)
}
static int calls_to_failed_chip = 0;
static int testchip_failed_writePad(void *data, unsigned int pin, int value)
static int testchip_failed_writePad(void *data, brain_pin_e pin, int value)
{
calls_to_failed_chip++;
}