microbit-dal: revised capability mapping for the MicroBitPin abstraction.

As per issue #115, AnalogOut was not capable on all IO even though there was no reason for this to be the case.

This commit adds a revised PinCapability enumeration, adding AnalogOut capability to all capable pins using the PIN_CAPABILITY_STANDARD enum, which combines PIN_CAPABILITY_DIGITAL and PIN_CAPABILITY_ANALOG_OUT.
This commit is contained in:
James Devine 2017-01-31 11:52:20 +00:00
parent f569f5f6d1
commit 350aad7a90
3 changed files with 33 additions and 29 deletions

View file

@ -80,9 +80,13 @@ DEALINGS IN THE SOFTWARE.
* Used to determine the capabilities of each Pin as some can only be digital, or can be both digital and analogue.
*/
enum PinCapability{
PIN_CAPABILITY_DIGITAL = 0x01,
PIN_CAPABILITY_ANALOG = 0x02,
PIN_CAPABILITY_AD = PIN_CAPABILITY_DIGITAL | PIN_CAPABILITY_ANALOG,
PIN_CAPABILITY_DIGITAL_IN = 0x01,
PIN_CAPABILITY_DIGITAL_OUT = 0x02,
PIN_CAPABILITY_DIGITAL = PIN_CAPABILITY_DIGITAL_IN | PIN_CAPABILITY_DIGITAL_OUT,
PIN_CAPABILITY_ANALOG_IN = 0x04,
PIN_CAPABILITY_ANALOG_OUT = 0x08,
PIN_CAPABILITY_ANALOG = PIN_CAPABILITY_ANALOG_IN | PIN_CAPABILITY_ANALOG_OUT,
PIN_CAPABILITY_STANDARD = PIN_CAPABILITY_DIGITAL | PIN_CAPABILITY_ANALOG_OUT,
PIN_CAPABILITY_ALL = PIN_CAPABILITY_DIGITAL | PIN_CAPABILITY_ANALOG
};

View file

@ -47,24 +47,24 @@ MicroBitIO::MicroBitIO(int ID_P0, int ID_P1, int ID_P2,
int ID_P12,int ID_P13,int ID_P14,
int ID_P15,int ID_P16,int ID_P19,
int ID_P20) :
P0 (ID_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_ALL), //P0 is the left most pad (ANALOG/DIGITAL/TOUCH)
P1 (ID_P1, MICROBIT_PIN_P1, PIN_CAPABILITY_ALL), //P1 is the middle pad (ANALOG/DIGITAL/TOUCH)
P2 (ID_P2, MICROBIT_PIN_P2, PIN_CAPABILITY_ALL), //P2 is the right most pad (ANALOG/DIGITAL/TOUCH)
P3 (ID_P3, MICROBIT_PIN_P3, PIN_CAPABILITY_AD), //COL1 (ANALOG/DIGITAL)
P4 (ID_P4, MICROBIT_PIN_P4, PIN_CAPABILITY_AD), //COL2 (ANALOG/DIGITAL)
P5 (ID_P5, MICROBIT_PIN_P5, PIN_CAPABILITY_DIGITAL), //BTN_A
P6 (ID_P6, MICROBIT_PIN_P6, PIN_CAPABILITY_DIGITAL), //ROW2
P7 (ID_P7, MICROBIT_PIN_P7, PIN_CAPABILITY_DIGITAL), //ROW1
P8 (ID_P8, MICROBIT_PIN_P8, PIN_CAPABILITY_DIGITAL), //PIN 18
P9 (ID_P9, MICROBIT_PIN_P9, PIN_CAPABILITY_DIGITAL), //ROW3
P10(ID_P10,MICROBIT_PIN_P10,PIN_CAPABILITY_AD), //COL3 (ANALOG/DIGITAL)
P11(ID_P11,MICROBIT_PIN_P11,PIN_CAPABILITY_DIGITAL), //BTN_B
P12(ID_P12,MICROBIT_PIN_P12,PIN_CAPABILITY_DIGITAL), //PIN 20
P13(ID_P13,MICROBIT_PIN_P13,PIN_CAPABILITY_DIGITAL), //SCK
P14(ID_P14,MICROBIT_PIN_P14,PIN_CAPABILITY_DIGITAL), //MISO
P15(ID_P15,MICROBIT_PIN_P15,PIN_CAPABILITY_DIGITAL), //MOSI
P16(ID_P16,MICROBIT_PIN_P16,PIN_CAPABILITY_DIGITAL), //PIN 16
P19(ID_P19,MICROBIT_PIN_P19,PIN_CAPABILITY_DIGITAL), //SCL
P20(ID_P20,MICROBIT_PIN_P20,PIN_CAPABILITY_DIGITAL) //SDA
P0 (ID_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_ALL), //P0 is the left most pad (ANALOG/DIGITAL/TOUCH)
P1 (ID_P1, MICROBIT_PIN_P1, PIN_CAPABILITY_ALL), //P1 is the middle pad (ANALOG/DIGITAL/TOUCH)
P2 (ID_P2, MICROBIT_PIN_P2, PIN_CAPABILITY_ALL), //P2 is the right most pad (ANALOG/DIGITAL/TOUCH)
P3 (ID_P3, MICROBIT_PIN_P3, PIN_CAPABILITY_ALL), //COL1 (ANALOG/DIGITAL)
P4 (ID_P4, MICROBIT_PIN_P4, PIN_CAPABILITY_ALL), //COL2 (ANALOG/DIGITAL)
P5 (ID_P5, MICROBIT_PIN_P5, PIN_CAPABILITY_STANDARD), //BTN_A
P6 (ID_P6, MICROBIT_PIN_P6, PIN_CAPABILITY_STANDARD), //ROW2
P7 (ID_P7, MICROBIT_PIN_P7, PIN_CAPABILITY_STANDARD), //ROW1
P8 (ID_P8, MICROBIT_PIN_P8, PIN_CAPABILITY_STANDARD), //PIN 18
P9 (ID_P9, MICROBIT_PIN_P9, PIN_CAPABILITY_STANDARD), //ROW3
P10(ID_P10,MICROBIT_PIN_P10,PIN_CAPABILITY_ALL), //COL3 (ANALOG/DIGITAL)
P11(ID_P11,MICROBIT_PIN_P11,PIN_CAPABILITY_STANDARD), //BTN_B
P12(ID_P12,MICROBIT_PIN_P12,PIN_CAPABILITY_STANDARD), //PIN 20
P13(ID_P13,MICROBIT_PIN_P13,PIN_CAPABILITY_STANDARD), //SCK
P14(ID_P14,MICROBIT_PIN_P14,PIN_CAPABILITY_STANDARD), //MISO
P15(ID_P15,MICROBIT_PIN_P15,PIN_CAPABILITY_STANDARD), //MOSI
P16(ID_P16,MICROBIT_PIN_P16,PIN_CAPABILITY_STANDARD), //PIN 16
P19(ID_P19,MICROBIT_PIN_P19,PIN_CAPABILITY_STANDARD), //SCL
P20(ID_P20,MICROBIT_PIN_P20,PIN_CAPABILITY_STANDARD) //SDA
{
}

View file

@ -118,7 +118,7 @@ void MicroBitPin::disconnect()
int MicroBitPin::setDigitalValue(int value)
{
// Check if this pin has a digital mode...
if(!(PIN_CAPABILITY_DIGITAL & capability))
if(!(PIN_CAPABILITY_DIGITAL_OUT & capability))
return MICROBIT_NOT_SUPPORTED;
// Ensure we have a valid value.
@ -153,7 +153,7 @@ int MicroBitPin::setDigitalValue(int value)
int MicroBitPin::getDigitalValue()
{
//check if this pin has a digital mode...
if(!(PIN_CAPABILITY_DIGITAL & capability))
if(!(PIN_CAPABILITY_DIGITAL_IN & capability))
return MICROBIT_NOT_SUPPORTED;
// Move into a Digital input state if necessary.
@ -212,7 +212,7 @@ int MicroBitPin::obtainAnalogChannel()
int MicroBitPin::setAnalogValue(int value)
{
//check if this pin has an analogue mode...
if(!(PIN_CAPABILITY_ANALOG & capability))
if(!(PIN_CAPABILITY_ANALOG_OUT & capability))
return MICROBIT_NOT_SUPPORTED;
//sanitise the level value
@ -248,7 +248,7 @@ int MicroBitPin::setAnalogValue(int value)
int MicroBitPin::setServoValue(int value, int range, int center)
{
//check if this pin has an analogue mode...
if(!(PIN_CAPABILITY_ANALOG & capability))
if(!(PIN_CAPABILITY_ANALOG_OUT & capability))
return MICROBIT_NOT_SUPPORTED;
//sanitise the servo level
@ -284,7 +284,7 @@ int MicroBitPin::setServoValue(int value, int range, int center)
int MicroBitPin::getAnalogValue()
{
//check if this pin has an analogue mode...
if(!(PIN_CAPABILITY_ANALOG & capability))
if(!(PIN_CAPABILITY_ANALOG_IN & capability))
return MICROBIT_NOT_SUPPORTED;
// Move into an analogue input state if necessary.
@ -362,7 +362,7 @@ int MicroBitPin::isAnalog()
int MicroBitPin::isTouched()
{
//check if this pin has a touch mode...
if(!(PIN_CAPABILITY_DIGITAL & capability))
if(!(PIN_CAPABILITY_DIGITAL_IN & capability))
return MICROBIT_NOT_SUPPORTED;
// Move into a touch input state if necessary.
@ -387,7 +387,7 @@ int MicroBitPin::isTouched()
int MicroBitPin::setServoPulseUs(int pulseWidth)
{
//check if this pin has an analogue mode...
if(!(PIN_CAPABILITY_ANALOG & capability))
if(!(PIN_CAPABILITY_ANALOG_OUT & capability))
return MICROBIT_NOT_SUPPORTED;
//sanitise the pulse width