7#define PROTECTED_CHANNEL_COUNT 8
17 void check(efitick_t nowNt);
29int ProtectedGpio::setPadMode(
iomode_t mode) {
30 if (mode == PAL_MODE_OUTPUT_PUSHPULL) {
31 m_output.initPin(
"protected", m_config->Pin);
39int ProtectedGpio::set(
bool value) {
45 m_output.setValue(value);
50int ProtectedGpio::get()
const {
51 return m_output.getLogicValue();
54void ProtectedGpio::check(efitick_t ) {
61 float amps = senseVolts.value_or(0) * m_config->AmpsPerVolt;
64 if (amps > m_config->MaximumAllowedCurrent) {
65 m_output.setValue(
false);
69 m_output.setValue(
false);
78class ProtectedGpios :
public GpioChip {
80 int init()
override {
return 0; }
88 void check(efitick_t nowNt);
91 ProtectedGpio m_channels[PROTECTED_CHANNEL_COUNT];
94int ProtectedGpios::setPadMode(
size_t pin,
iomode_t mode) {
95 if (
pin >= PROTECTED_CHANNEL_COUNT) {
99 return m_channels[
pin].setPadMode(mode);
102int ProtectedGpios::writePad(
size_t pin,
int value) {
103 if (
pin >= PROTECTED_CHANNEL_COUNT) {
107 return m_channels[
pin].set(value);
110int ProtectedGpios::readPad(
size_t pin) {
111 if (
pin >= PROTECTED_CHANNEL_COUNT) {
115 return m_channels[
pin].get();
119 if (
pin >= PROTECTED_CHANNEL_COUNT) {
123 return m_channels[
pin].getDiag();
127 for (
size_t i = 0; i < efi::size(m_channels); i++) {
128 m_channels[i].configure(configs[i]);
132void ProtectedGpios::check(efitick_t nowNt) {
133 for (
size_t i = 0; i < efi::size(m_channels); i++) {
134 m_channels[i].check(nowNt);
146 if (result ==
static_cast<int>(base)) {
Single output pin reference and state.
int gpiochip_register(brain_pin_e base, const char *name, GpioChip &gpioChip, size_t size)
Register gpiochip.
static constexpr persistent_config_s * config
uint32_t iomode_t
Digital I/O modes.
int protectedGpio_add(brain_pin_e base, const ProtectedGpioConfig *const configs)
static ProtectedGpios protectedGpios
void protectedGpio_check(efitick_t nowNt)
static void check(SensorType type)
virtual brain_pin_diag_e getDiag(size_t)
virtual int writePad(size_t, int)
virtual int readPad(size_t)
virtual int setPadMode(size_t, iomode_t)