Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small optimisation, save a bit of memory from MicroBitIO. #466

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions model/MicroBit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ MicroBit::MicroBit() :
ledColPins{&io.col1, &io.col2, &io.col3, &io.col4, &io.col5},
ledMatrixMap{ 5, 5, 5, 5, (Pin**)ledRowPins, (Pin**)ledColPins, ledMatrixPositions},
display(ledMatrixMap),
buttonA(io.P5, DEVICE_ID_BUTTON_A, DEVICE_BUTTON_ALL_EVENTS, ACTIVE_LOW),
buttonB(io.P11, DEVICE_ID_BUTTON_B, DEVICE_BUTTON_ALL_EVENTS, ACTIVE_LOW),
buttonA(io.P5, DEVICE_ID_BUTTON_A, DEVICE_BUTTON_ALL_EVENTS, ACTIVE_LOW, PullMode::None),
buttonB(io.P11, DEVICE_ID_BUTTON_B, DEVICE_BUTTON_ALL_EVENTS, ACTIVE_LOW, PullMode::None),
buttonAB(DEVICE_ID_BUTTON_A, DEVICE_ID_BUTTON_B, DEVICE_ID_BUTTON_AB),
logo(io.logo, touchSensor, CAPTOUCH_DEFAULT_CALIBRATION),
radio(),
Expand Down
13 changes: 2 additions & 11 deletions model/MicroBitIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ using namespace codal;
* by MicroBitPin instances on the default EventModel.
*/
MicroBitIO::MicroBitIO(NRF52ADC &a, TouchSensor &s) :
pins(MICROBIT_PINS_TOTAL),

// Edge Connector Pins
P0(ID_PIN_P0, P0_02, PIN_CAPABILITY_AD),
Expand Down Expand Up @@ -91,24 +92,14 @@ MicroBitIO::MicroBitIO(NRF52ADC &a, TouchSensor &s) :
buttonA(P5),
buttonB(P11)
{
pins = 33;
NRF52Pin::adc = &a;
NRF52Pin::touchSensor = &s;

// Ensure all internal pins are configured with no pull resistors.
for (int i=19; i<pins; i++)
pin[i].setPull(PullMode::None);

// Ensure all internal multiplexed pins are configured with no pull resistors.
col1.setPull(PullMode::None);
col2.setPull(PullMode::None);
col3.setPull(PullMode::None);
col4.setPull(PullMode::None);
col5.setPull(PullMode::None);
buttonA.setPull(PullMode::None);
buttonB.setPull(PullMode::None);

savedStatus = ManagedBuffer(pins + 1);
// Last array entry stores the saved/not-saved status
savedStatus[pins] = 0;
}

Expand Down
7 changes: 5 additions & 2 deletions model/MicroBitIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ typedef enum {
// Unused
#define MICROBIT_PIN_BUTTON_RESET -1

// Total number of available pins in MicroBitIO, excluding aliases
#define MICROBIT_PINS_TOTAL 33

//
// Component IDs for each pin.
// The can be user defined, but uniquely identify a pin when using the eventing APIs/
Expand Down Expand Up @@ -355,7 +358,7 @@ namespace codal
{
public:
// Number of pins in use.
int pins;
const int pins;

// Enumeration of all pins, ordered by edge connector.
NRF52Pin pin[0];
Expand Down Expand Up @@ -425,7 +428,7 @@ namespace codal
virtual int deepSleepCallback( deepSleepCallbackReason reason, deepSleepCallbackData *data) override;

private:
ManagedBuffer savedStatus;
uint8_t savedStatus[MICROBIT_PINS_TOTAL + 1];

/**
* Record current state of pins, so we can return the configuration to the same state later.
Expand Down
Loading