Skip to content

Commit

Permalink
MicroBitButton PinNumber compatibility
Browse files Browse the repository at this point in the history
- Additional constructor to handle PinNumber/PinName
  • Loading branch information
microbit-sam committed Nov 19, 2020
1 parent dc80192 commit 5e38360
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
16 changes: 16 additions & 0 deletions inc/compat/MicroBitButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ class MicroBitButton : public NRF52Pin, public Button
*/
MicroBitButton(PinName name, uint16_t id, MicroBitButtonEventConfiguration eventConfiguration = MICROBIT_BUTTON_ALL_EVENTS, PinMode mode = PullNone);

/**
* Constructor.
*
* Create a software representation of a button.
*
* @param p_number the physical pin on the processor that should be used as input.
*
* @param id the ID of the new MicroBitButton object.
*
* @param eventConfiguration Configures the events that will be generated by this MicroBitButton instance.
* Defaults to MICROBIT_BUTTON_ALL_EVENTS.
*
* @param mode the configuration of internal pullups/pulldowns, as defined in the mbed PinMode class. PullNone by default.
*/
MicroBitButton(PinNumber p_number, uint16_t id, MicroBitButtonEventConfiguration eventConfiguration = MICROBIT_BUTTON_ALL_EVENTS, PinMode mode = PullNone);

/**
* Constructor.
*
Expand Down
18 changes: 18 additions & 0 deletions source/compat/MicroBitButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ MicroBitButton::MicroBitButton(PinName name, uint16_t id, MicroBitButtonEventCon
{
}

/**
* Constructor.
*
* Create a software representation of a button.
*
* @param p_number the physical pin on the processor that should be used as input.
*
* @param id the ID of the new MicroBitButton object.
*
* @param eventConfiguration Configures the events that will be generated by this MicroBitButton instance.
* Defaults to MICROBIT_BUTTON_ALL_EVENTS.
*
* @param mode the configuration of internal pullups/pulldowns, as defined in the mbed PinMode class. PullNone by default.
*/
MicroBitButton::MicroBitButton(PinNumber p_number, uint16_t id, MicroBitButtonEventConfiguration eventConfiguration, PinMode mode) : NRF52Pin(id, p_number, PIN_CAPABILITY_DIGITAL), Button(*this, id, eventConfiguration, ButtonPolarity::ACTIVE_LOW, getPullModeFronPinMode(mode))
{
}

/**
* Constructor.
*
Expand Down

0 comments on commit 5e38360

Please sign in to comment.