Skip to content

Commit c00e32b

Browse files
Save a bit of memory from MicroBitIO. (#466)
Display and buttons pull configuration is done in their own components. Moving from a ManageBuffer to a plain array saves another 100-ish bytes.
1 parent 7995a88 commit c00e32b

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

model/MicroBit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ MicroBit::MicroBit() :
8080
ledColPins{&io.col1, &io.col2, &io.col3, &io.col4, &io.col5},
8181
ledMatrixMap{ 5, 5, 5, 5, (Pin**)ledRowPins, (Pin**)ledColPins, ledMatrixPositions},
8282
display(ledMatrixMap),
83-
buttonA(io.P5, DEVICE_ID_BUTTON_A, DEVICE_BUTTON_ALL_EVENTS, ACTIVE_LOW),
84-
buttonB(io.P11, DEVICE_ID_BUTTON_B, DEVICE_BUTTON_ALL_EVENTS, ACTIVE_LOW),
83+
buttonA(io.P5, DEVICE_ID_BUTTON_A, DEVICE_BUTTON_ALL_EVENTS, ACTIVE_LOW, PullMode::None),
84+
buttonB(io.P11, DEVICE_ID_BUTTON_B, DEVICE_BUTTON_ALL_EVENTS, ACTIVE_LOW, PullMode::None),
8585
buttonAB(DEVICE_ID_BUTTON_A, DEVICE_ID_BUTTON_B, DEVICE_ID_BUTTON_AB),
8686
logo(io.logo, touchSensor, CAPTOUCH_DEFAULT_CALIBRATION),
8787
radio(),

model/MicroBitIO.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ using namespace codal;
4242
* by MicroBitPin instances on the default EventModel.
4343
*/
4444
MicroBitIO::MicroBitIO(NRF52ADC &a, TouchSensor &s) :
45+
pins(MICROBIT_PINS_TOTAL),
4546

4647
// Edge Connector Pins
4748
P0(ID_PIN_P0, P0_02, PIN_CAPABILITY_AD),
@@ -91,24 +92,14 @@ MicroBitIO::MicroBitIO(NRF52ADC &a, TouchSensor &s) :
9192
buttonA(P5),
9293
buttonB(P11)
9394
{
94-
pins = 33;
9595
NRF52Pin::adc = &a;
9696
NRF52Pin::touchSensor = &s;
9797

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

102-
// Ensure all internal multiplexed pins are configured with no pull resistors.
103-
col1.setPull(PullMode::None);
104-
col2.setPull(PullMode::None);
105-
col3.setPull(PullMode::None);
106-
col4.setPull(PullMode::None);
107-
col5.setPull(PullMode::None);
108-
buttonA.setPull(PullMode::None);
109-
buttonB.setPull(PullMode::None);
110-
111-
savedStatus = ManagedBuffer(pins + 1);
102+
// Last array entry stores the saved/not-saved status
112103
savedStatus[pins] = 0;
113104
}
114105

model/MicroBitIO.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ typedef enum {
282282
// Unused
283283
#define MICROBIT_PIN_BUTTON_RESET -1
284284

285+
// Total number of available pins in MicroBitIO, excluding aliases
286+
#define MICROBIT_PINS_TOTAL 33
287+
285288
//
286289
// Component IDs for each pin.
287290
// The can be user defined, but uniquely identify a pin when using the eventing APIs/
@@ -355,7 +358,7 @@ namespace codal
355358
{
356359
public:
357360
// Number of pins in use.
358-
int pins;
361+
const int pins;
359362

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

427430
private:
428-
ManagedBuffer savedStatus;
431+
uint8_t savedStatus[MICROBIT_PINS_TOTAL + 1];
429432

430433
/**
431434
* Record current state of pins, so we can return the configuration to the same state later.

0 commit comments

Comments
 (0)