gpio: core: guards
This commit is contained in:
parent
6e85b753d5
commit
a4d9238a13
|
@ -40,6 +40,8 @@ struct gpiochip {
|
||||||
|
|
||||||
static gpiochip chips[BOARD_EXT_GPIOCHIPS];
|
static gpiochip chips[BOARD_EXT_GPIOCHIPS];
|
||||||
|
|
||||||
|
#if EFI_PROD_CODE
|
||||||
|
|
||||||
/* TODO: move inside gpio chip driver? */
|
/* TODO: move inside gpio chip driver? */
|
||||||
class external_hardware_pwm : public hardware_pwm {
|
class external_hardware_pwm : public hardware_pwm {
|
||||||
public:
|
public:
|
||||||
|
@ -81,6 +83,8 @@ private:
|
||||||
/* TODO: is 5 enought? */
|
/* TODO: is 5 enought? */
|
||||||
static external_hardware_pwm extPwms[5];
|
static external_hardware_pwm extPwms[5];
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/*==========================================================================*/
|
/*==========================================================================*/
|
||||||
/* Local functions. */
|
/* Local functions. */
|
||||||
/*==========================================================================*/
|
/*==========================================================================*/
|
||||||
|
@ -100,6 +104,8 @@ static gpiochip *gpiochip_find(brain_pin_e pin)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if EFI_PROD_CODE
|
||||||
|
|
||||||
static external_hardware_pwm* gpiochip_getNextPwmDevice() {
|
static external_hardware_pwm* gpiochip_getNextPwmDevice() {
|
||||||
for (size_t i = 0; i < efi::size(extPwms); i++) {
|
for (size_t i = 0; i < efi::size(extPwms); i++) {
|
||||||
if (!extPwms[i].hasInit()) {
|
if (!extPwms[i].hasInit()) {
|
||||||
|
@ -111,6 +117,8 @@ static external_hardware_pwm* gpiochip_getNextPwmDevice() {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/*==========================================================================*/
|
/*==========================================================================*/
|
||||||
/* Exported functions. */
|
/* Exported functions. */
|
||||||
/*==========================================================================*/
|
/*==========================================================================*/
|
||||||
|
@ -354,33 +362,6 @@ int gpiochips_readPad(brain_pin_e pin)
|
||||||
return chip->chip->readPad(pin - chip->base);
|
return chip->chip->readPad(pin - chip->base);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Try to init PWM on given pin
|
|
||||||
* @details success of call depends on chip capabilities
|
|
||||||
* returns nullptr in case there is no chip for given pin
|
|
||||||
* returns nullptr in case of pin is not PWM capable
|
|
||||||
* returns nullptr in case all extPwms are already used
|
|
||||||
* returns hardware_pwm if succes, later user can call ->setDuty to change duty
|
|
||||||
*/
|
|
||||||
|
|
||||||
hardware_pwm* gpiochip_tryInitPwm(const char* msg, brain_pin_e pin, float frequency, float duty)
|
|
||||||
{
|
|
||||||
gpiochip *chip = gpiochip_find(pin);
|
|
||||||
|
|
||||||
if (!chip) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* TODO: implement reintialization of same pin with different settings reusing same external_hardware_pwm */
|
|
||||||
if (external_hardware_pwm *device = gpiochip_getNextPwmDevice()) {
|
|
||||||
if (device->start(msg, chip, pin - chip->base, frequency, duty) >= 0) {
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get diagnostic for given gpio
|
* @brief Get diagnostic for given gpio
|
||||||
* @details actual output value depend on gpiochip capabilities
|
* @details actual output value depend on gpiochip capabilities
|
||||||
|
@ -421,6 +402,37 @@ int gpiochips_get_total_pins(void)
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if EFI_PROD_CODE
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Try to init PWM on given pin
|
||||||
|
* @details success of call depends on chip capabilities
|
||||||
|
* returns nullptr in case there is no chip for given pin
|
||||||
|
* returns nullptr in case of pin is not PWM capable
|
||||||
|
* returns nullptr in case all extPwms are already used
|
||||||
|
* returns hardware_pwm if succes, later user can call ->setDuty to change duty
|
||||||
|
*/
|
||||||
|
|
||||||
|
hardware_pwm* gpiochip_tryInitPwm(const char* msg, brain_pin_e pin, float frequency, float duty)
|
||||||
|
{
|
||||||
|
gpiochip *chip = gpiochip_find(pin);
|
||||||
|
|
||||||
|
if (!chip) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO: implement reintialization of same pin with different settings reusing same external_hardware_pwm */
|
||||||
|
if (external_hardware_pwm *device = gpiochip_getNextPwmDevice()) {
|
||||||
|
if (device->start(msg, chip, pin - chip->base, frequency, duty) >= 0) {
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#else /* BOARD_EXT_GPIOCHIPS > 0 */
|
#else /* BOARD_EXT_GPIOCHIPS > 0 */
|
||||||
|
|
||||||
int gpiochips_getPinOffset(brain_pin_e pin) {
|
int gpiochips_getPinOffset(brain_pin_e pin) {
|
||||||
|
|
|
@ -55,8 +55,11 @@ int gpiochips_init(void);
|
||||||
int gpiochips_setPadMode(brain_pin_e pin, iomode_t mode);
|
int gpiochips_setPadMode(brain_pin_e pin, iomode_t mode);
|
||||||
int gpiochips_writePad(brain_pin_e pin, int value);
|
int gpiochips_writePad(brain_pin_e pin, int value);
|
||||||
int gpiochips_readPad(brain_pin_e pin);
|
int gpiochips_readPad(brain_pin_e pin);
|
||||||
hardware_pwm* gpiochip_tryInitPwm(const char* msg, brain_pin_e pin, float frequency, float duty);
|
|
||||||
brain_pin_diag_e gpiochips_getDiag(brain_pin_e pin);
|
brain_pin_diag_e gpiochips_getDiag(brain_pin_e pin);
|
||||||
|
|
||||||
|
#if EFI_PROD_CODE
|
||||||
|
hardware_pwm* gpiochip_tryInitPwm(const char* msg, brain_pin_e pin, float frequency, float duty);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* return total number of external gpios */
|
/* return total number of external gpios */
|
||||||
int gpiochips_get_total_pins(void);
|
int gpiochips_get_total_pins(void);
|
||||||
|
|
Loading…
Reference in New Issue