rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Data Structures | Functions
gpio_ext.h File Reference

Data Structures

struct  GpioChip
 

Functions

int gpiochips_getPinOffset (brain_pin_e pin)
 
const chargpiochips_getChipName (brain_pin_e pin)
 Get external chip name.
 
const chargpiochips_getPinName (brain_pin_e pin)
 Get external chip port name.
 
int gpiochip_register (brain_pin_e base, const char *name, GpioChip &chip, size_t size)
 Register gpiochip.
 
int gpiochips_setPinNames (brain_pin_e base, const char **names)
 Set pins names for registered gpiochip.
 
int gpiochips_init (void)
 Init all registered gpiochips.
 
int gpiochips_setPadMode (brain_pin_e pin, iomode_t mode)
 Set pin mode of gpiochip.
 
int gpiochips_writePad (brain_pin_e pin, int value)
 Set value to gpio of gpiochip.
 
int gpiochips_readPad (brain_pin_e pin)
 Get value to gpio of gpiochip.
 
brain_pin_diag_e gpiochips_getDiag (brain_pin_e pin)
 Get diagnostic for given gpio.
 
void gpiochips_debug ()
 
hardware_pwmgpiochip_tryInitPwm (const char *msg, brain_pin_e pin, float frequency, float duty)
 Try to init PWM on given pin.
 
int gpiochips_get_total_pins (void)
 Get total pin count allocated for external gpio chips.
 

Function Documentation

◆ gpiochip_register()

int gpiochip_register ( brain_pin_e  base,
const char name,
GpioChip gpioChip,
size_t  size 
)

Register gpiochip.

should be called from board file. Can be called before os ready. All chips should be registered before gpiochips_init() called. returns -101 in case of no free chips left returns -100 in case of no ops provided, incorrect chip size returns -102 or -103 in case chip overlaps already registered chip(s) else returns chip base

Definition at line 186 of file core.cpp.

186 {
187 /* zero size? */
188 if (!size)
189 return -100;
190
191 /* outside? */
192 if ((base + size - 1 > BRAIN_PIN_LAST) || (base <= BRAIN_PIN_ONCHIP_LAST))
193 return -101;
194
195 /* check for overlap with other chips */
196 for (int i = 0; i < BOARD_EXT_GPIOCHIPS; i++) {
197 if (chips[i].base != Gpio::Unassigned) {
198 #define in_range(a, b, c) (((a) > (b)) && ((a) < (c)))
199 if (in_range(base, chips[i].base, chips[i].base + chips[i].size))
200 return -102;
201 if (in_range(base + size, chips[i].base, chips[i].base + chips[i].size))
202 return -103;
203 }
204 }
205
206 gpiochip *chip = nullptr;
207
208 /* find free gpiochip struct */
209 for (int i = 0; i < BOARD_EXT_GPIOCHIPS; i++) {
210 if (chips[i].base == Gpio::Unassigned) {
211 chip = &chips[i];
212 break;
213 }
214 }
215
216 /* no free chips left */
217 if (!chip) {
218 return -104;
219 }
220
221 /* register chip */
222 chip->name = name;
223 chip->chip = &gpioChip;
224 chip->base = base;
225 chip->size = size;
226 chip->gpio_names = nullptr;
227
228 // TODO: this cast seems wrong?
229 return (int)base;
230}
@ Unassigned
static gpiochip chips[BOARD_EXT_GPIOCHIPS]
Definition core.cpp:41
composite packet size

Referenced by drv8860_add(), initCanGpioMsiobox(), l9779_add(), mc33810_add(), mc33972_add(), protectedGpio_add(), tle6240_add(), tle8888_add(), and tle9104_add().

Here is the caller graph for this function:

◆ gpiochip_tryInitPwm()

hardware_pwm * gpiochip_tryInitPwm ( const char msg,
brain_pin_e  pin,
float  frequency,
float  duty 
)

Try to init PWM on given pin.

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

Definition at line 439 of file core.cpp.

440{
441 gpiochip *chip = gpiochip_find(pin);
442
443 if (!chip) {
444 return nullptr;
445 }
446
447 /* TODO: implement reintialization of same pin with different settings reusing same external_hardware_pwm */
448 if (external_hardware_pwm *device = gpiochip_getNextPwmDevice()) {
449 if (device->start(msg, chip, pin - chip->base, frequency, duty) >= 0) {
450 return device;
451 }
452 }
453
454 return nullptr;
455}
static gpiochip * gpiochip_find(brain_pin_e pin)
Definition core.cpp:96
static external_hardware_pwm * gpiochip_getNextPwmDevice()
Definition core.cpp:110
static Lps25 device
Definition init_baro.cpp:4
static float frequency
Definition init_flex.cpp:21
brain_pin_e pin
Definition stm32_adc.cpp:15
static float duty

Referenced by startSimplePwm().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gpiochips_debug()

void gpiochips_debug ( )

Definition at line 413 of file core.cpp.

414{
415 int i;
416
417 for (i = 0; i < BOARD_EXT_GPIOCHIPS; i++) {
418 gpiochip *chip = &chips[i];
419
420 if (chip->base == Gpio::Unassigned)
421 continue;
422
423 efiPrintf("%s (base %d, size %d):\n", chip->name, (int)chip->base, chip->size);
424 chip->chip->debug();
425 }
426}

Referenced by reportPins().

Here is the caller graph for this function:

◆ gpiochips_get_total_pins()

int gpiochips_get_total_pins ( void  )

Get total pin count allocated for external gpio chips.

Will also include unused pins for chips that was registered but later fails to init.

Definition at line 396 of file core.cpp.

397{
398 int i;
399 int cnt = 0;
400
401 for (i = 0; i < BOARD_EXT_GPIOCHIPS; i++) {
402 gpiochip *chip = &chips[i];
403
404 if (chip->base == Gpio::Unassigned)
405 continue;
406
407 cnt += chip->size;
408 }
409
410 return cnt;
411}

◆ gpiochips_getChipName()

const char * gpiochips_getChipName ( brain_pin_e  pin)

Get external chip name.

return gpiochip name

Definition at line 148 of file core.cpp.

148 {
149 gpiochip *chip = gpiochip_find(pin);
150
151 if (chip)
152 return chip->name;
153
154 return nullptr;
155}

Referenced by hwPhysicalPinName(), and reportPins().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gpiochips_getDiag()

brain_pin_diag_e gpiochips_getDiag ( brain_pin_e  pin)

Get diagnostic for given gpio.

actual output value depend on gpiochip capabilities returns PIN_UNKNOWN in case of pin not belong to any gpio chip returns PIN_OK in case of chip does not support getting diagnostic else return brain_pin_diag_e from gpiochip driver;

Definition at line 381 of file core.cpp.

381 {
382 gpiochip *chip = gpiochip_find(pin);
383
384 if (!chip)
385 return PIN_UNKNOWN;
386
387 return chip->chip->getDiag(pin - chip->base);
388}

Referenced by OutputPin::getDiag(), and reportPins().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gpiochips_getPinName()

const char * gpiochips_getPinName ( brain_pin_e  pin)

Get external chip port name.

return pin name or gpiochip name (if no pins names provided)

Definition at line 162 of file core.cpp.

163{
164 int offset;
165 gpiochip *chip = gpiochip_find(pin);
166
167 if (chip) {
168 offset = pin - chip->base;
169 if ((chip->gpio_names) && (chip->gpio_names[offset]))
170 return chip->gpio_names[offset];
171 }
172
173 return nullptr;
174}
uint16_t offset
Definition tunerstudio.h:0

Referenced by hwPhysicalPinName(), and reportPins().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gpiochips_getPinOffset()

int gpiochips_getPinOffset ( brain_pin_e  pin)

return numeric part of EXTERNAL pin name.

Definition at line 132 of file core.cpp.

133{
134 gpiochip *chip = gpiochip_find(pin);
135
136 if (chip)
137 return pin - chip->base;
138
139 return EFI_ERROR_CODE;
140}

Referenced by hwPhysicalPinName(), and reportPins().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gpiochips_init()

int gpiochips_init ( void  )

Init all registered gpiochips.

will call gpiochip init ops for all registered chips calles when OS is ready, so gpiochip can start threads, use drivers and so on.

Definition at line 284 of file core.cpp.

284 {
285 int pins_added = 0;
286
287 for (int i = 0; i < BOARD_EXT_GPIOCHIPS; i++) {
288 gpiochip *chip = &chips[i];
289
290 if (chip->base == Gpio::Unassigned)
291 continue;
292
293 int ret = chip->chip->init();
294 if (ret < 0) {
295 #if EFI_PROD_CODE
296 // todo: adjust unit tests to validate this fatal
297 criticalError("Failed to init chip %d: %d", i, ret);
298 #else
299 chip->base = Gpio::Unassigned;
300 #endif
301 } else {
302 pins_added += chip->size;
303 }
304 }
305
306 return pins_added;
307}

Referenced by initSmartGpio().

Here is the caller graph for this function:

◆ gpiochips_readPad()

int gpiochips_readPad ( brain_pin_e  pin)

Get value to gpio of gpiochip.

actual input value depent on current gpiochip implementation returns -1 in case of pin not belong to any gpio chip returns -1 in case of chip does not support getting output value (output only) else return value from gpiochip driver;

Definition at line 363 of file core.cpp.

364{
365 gpiochip *chip = gpiochip_find(pin);
366
367 if (!chip)
368 return -109;
369
370 return chip->chip->readPad(pin - chip->base);
371}

Referenced by efiReadPin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gpiochips_setPadMode()

int gpiochips_setPadMode ( brain_pin_e  pin,
iomode_t  mode 
)

Set pin mode of gpiochip.

set pad mode for given pin. return -107 if driver does not implemet setPadMode ops else return value from gpiochip driver.

Definition at line 317 of file core.cpp.

318{
319 gpiochip *chip = gpiochip_find(pin);
320
321 if (!chip)
322 return -107;
323
324 return chip->chip->setPadMode(pin - chip->base, mode);
325}

Referenced by efiSetPadModeWithoutOwnershipAcquisition(), and efiSetPadUnused().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gpiochips_setPinNames()

int gpiochips_setPinNames ( brain_pin_e  base,
const char **  names 
)

Set pins names for registered gpiochip.

should be called after chip registration. May be called several times Names array size should be aqual to chip gpio count

Definition at line 266 of file core.cpp.

267{
268 gpiochip *chip = gpiochip_find(base);
269
270 if (!chip)
271 return -113;
272
273 chip->gpio_names = names;
274
275 return 0;
276}

Referenced by drv8860_add(), l9779_add(), mc33810_add(), tle6240_add(), and tle8888_add().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gpiochips_writePad()

int gpiochips_writePad ( brain_pin_e  pin,
int  value 
)

Set value to gpio of gpiochip.

actual output value depent on current gpiochip implementation for smart switch inactive supposed to be closed switch (no current flows) returns -1 in case of pin not belong to any gpio chip returns -1 in case of chip does not support seting output value (input only) else return value from gpiochip driver;

Definition at line 336 of file core.cpp.

336 {
337#if EFI_PROD_CODE
338extern bool isInHardFaultHandler;
339 // todo: technical debt, how do we turn off smart GPIO?!
341 return -130;
342 }
343#endif // EFI_PROD_CODE
344 gpiochip *chip = gpiochip_find(pin);
345
346 if (!chip) {
347 // todo: make readPad fail in a similar way?
348 criticalError("Failed migration? Time to reset settings? gpiochip not found for pin %d", pin);
349 return -108;
350 }
351
352 return chip->chip->writePad(pin - chip->base, value);
353}
bool isInHardFaultHandler

Referenced by directWritePad(), and OutputPin::setValue().

Here is the call graph for this function:
Here is the caller graph for this function:

Go to the source code of this file.