AP_IOMCU: iofirmware: support digital write

This commit is contained in:
Iampete1 2021-09-20 14:43:32 +01:00 committed by Andrew Tridgell
parent 4b62bd9180
commit 12d5fbbc86
3 changed files with 39 additions and 0 deletions

View File

@ -257,6 +257,7 @@ void AP_IOMCU_FW::update()
if (dsm_bind_state) {
dsm_bind_step();
}
GPIO_write();
}
}
@ -616,6 +617,24 @@ bool AP_IOMCU_FW::handle_code_write()
break;
}
case PAGE_GPIO:
if (rx_io_packet.count != 1) {
return false;
}
memcpy(&GPIO, &rx_io_packet.regs[0] + rx_io_packet.offset, sizeof(GPIO));
if (GPIO.channel_mask != last_GPIO_channel_mask) {
for (uint8_t i=0; i<8; i++) {
if ((GPIO.channel_mask & (1U << i)) != 0) {
hal.rcout->disable_ch(i);
hal.gpio->pinMode(101+i, HAL_GPIO_OUTPUT);
} else {
hal.rcout->enable_ch(i);
}
}
last_GPIO_channel_mask = GPIO.channel_mask;
}
break;
default:
break;
}
@ -749,4 +768,13 @@ void AP_IOMCU_FW::fill_failsafe_pwm(void)
}
}
void AP_IOMCU_FW::GPIO_write()
{
for (uint8_t i=0; i<8; i++) {
if ((GPIO.channel_mask & (1U << i)) != 0) {
hal.gpio->write(101+i, (GPIO.output_mask & (1U << i)) != 0);
}
}
}
AP_HAL_MAIN();

View File

@ -105,6 +105,11 @@ public:
// MIXER values
struct page_mixing mixing;
// GPIO masks
struct page_GPIO GPIO;
uint8_t last_GPIO_channel_mask;
void GPIO_write();
// true when override channel active
bool override_active;

View File

@ -55,6 +55,7 @@ enum iopage {
PAGE_DIRECT_PWM = 54,
PAGE_FAILSAFE_PWM = 55,
PAGE_MIXING = 200,
PAGE_GPIO = 201,
};
// setup page registers
@ -160,3 +161,8 @@ struct page_mixing {
uint8_t pad; // pad to even size
};
struct page_GPIO {
uint8_t channel_mask;
uint8_t output_mask;
};