Skip to content

Interface Layer for mbed-drivers #11253

Closed
@tobiasjaster

Description

@tobiasjaster

Description

While working on a driver for the MCP23S17 I had the intention that both internal standard drivers and external drivers could use the same interface. This could be used, for example, to control a DigitalIn object in the same way as a GPIO expander pin. This in turn allows the control of an external module with mixed GPIOs.

Example:
Commit: https://github.com/tobiasjaster/mbed-os/#597c90613b2b81d2047b97d334d114303e1c6617

main.cpp:
#include "mbed.h"
#include "DeviceExpander.h"
#include "GPIOExpansionInterface.h"
#include "MCP/MCP23S17.h"

SPI spi(SPI1_MOSI, SPI1_MISO, SPI1_SCK);
MCP23S17 mcp(&spi, SPI1_CS2, 0x40, TIM1_CH2N);
DigitalOut led1(TIM4_CH4);
DigitalOut reset(TIM1_CH1N);
ExpDigitalOut led2(&mcp, EXPPORT_B, EXPPIN_5, PullUp);
ExpDigitalIn expb4(&mcp, EXPPORT_B, EXPPIN_4, PullUp);
ExpInterruptIn expb3(&mcp, EXPPORT_B, EXPPIN_3, PullUp);
ExpDigitalOut expb2(&mcp, EXPPORT_B, EXPPIN_2, 0);
// main() runs in its own thread in the OS

void toggleLED(void){
led2 = !led2;
}
int main() {

reset = 1;
expb3.rise(toggleLED);

while (true) {
    led1 = !led1;
    expb2 = expb4;
    wait(0.5);
}

}

Issue request type

[x] Question
[ ] Enhancement
[ ] Bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions