HAL_ChibiOS: implement DigitalSource()

This commit is contained in:
Andrew Tridgell 2018-03-28 20:41:08 +11:00
parent c2adc26051
commit 9a29c6d3b5
2 changed files with 24 additions and 14 deletions

View File

@ -113,8 +113,13 @@ void GPIO::toggle(uint8_t pin)
}
/* Alternative interface: */
AP_HAL::DigitalSource* GPIO::channel(uint16_t n) {
return new DigitalSource(0);
AP_HAL::DigitalSource* GPIO::channel(uint16_t pin)
{
struct gpio_entry *g = gpio_by_pin_num(pin);
if (!g) {
return nullptr;
}
return new DigitalSource(g->pal_line);
}
extern const AP_HAL::HAL& hal;
@ -175,23 +180,28 @@ bool GPIO::usb_connected(void)
return _usb_connected;
}
DigitalSource::DigitalSource(uint8_t v) :
_v(v)
DigitalSource::DigitalSource(ioline_t _line) :
line(_line)
{}
void DigitalSource::mode(uint8_t output)
{}
uint8_t DigitalSource::read() {
return _v;
{
palSetLineMode(line, output);
}
void DigitalSource::write(uint8_t value) {
_v = value;
uint8_t DigitalSource::read()
{
return palReadLine(line);
}
void DigitalSource::toggle() {
_v = !_v;
void DigitalSource::write(uint8_t value)
{
palWriteLine(line, value);
}
void DigitalSource::toggle()
{
palToggleLine(line);
}
void ext_interrupt_cb(EXTDriver *extp, expchannel_t channel)

View File

@ -61,11 +61,11 @@ private:
class ChibiOS::DigitalSource : public AP_HAL::DigitalSource {
public:
DigitalSource(uint8_t v);
DigitalSource(ioline_t line);
void mode(uint8_t output);
uint8_t read();
void write(uint8_t value);
void toggle();
private:
uint8_t _v;
ioline_t line;
};