Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: mbedInterface/mbedInterface.cpp
- Revision:
- 7:5fe7329751d4
- Parent:
- 4:abee20c0bf2a
--- a/mbedInterface/mbedInterface.cpp Fri Jun 10 21:22:34 2016 +0000
+++ b/mbedInterface/mbedInterface.cpp Tue Feb 07 18:45:25 2017 +0000
@@ -134,10 +134,17 @@
//---------------------------------------------------------------------
//translate pin numbers to hardware pins
-PinName outPins[NUMOUTPORTS] = {p11,p13,p15,p18,p21,p23,p25,p29,p20,p6}; //Old board output pins
-//PinName outPins[NUMPORTS] = {p18,p15,p13,p11,p29,p25,p23,p21,p20}; //New board output pins
-PinName inPins[NUMINPORTS] = {p12,p14,p16,p17,p22,p24,p26,p30,p7};
+//PinName dOutPins[NUMDIGOUTPORTS] = {p11,p13,p15,p18,p21,p23,p25,p29,p20,p6}; //Old board output pins
+//PinName dOutPins[NUMDIGOUTPORTS] = {p18,p15,p13,p11,p29,p25,p23,p21,p20}; //New board output pins
+//PinName dInPins[NUMDIGINPORTS] = {p12,p14,p16,p17,p22,p24,p26,p30,p7};
+//PinName aInPins[NUMANINPORTS] = {};
+//PinName aOutPins[NUMANOUTPORTS] = {};
+
+PinName dOutPins[NUMDIGOUTPORTS] = {p7,p15,p13,p11,p29,p25,p23,p21}; //With analog pins
+PinName dInPins[NUMDIGINPORTS] = {p12,p14,p16,p17,p22,p24,p26,p30};
+PinName aInPins[NUMANINPORTS] = {p20};
+PinName aOutPins[NUMANOUTPORTS] = {p18};
//The sound output uses a SmartWav device and their simple serial library
@@ -196,10 +203,19 @@
//-------------------------------
- for (int i=0; i < NUMPORTS; i++) {
+ for (int i=0; i < NUMDIGINPORTS; i++) {
dIn[i].init(i);
+ }
+ for (int i=0; i < NUMDIGOUTPORTS; i++) {
dOut[i].init(i);
}
+ for (int i=0; i < NUMANINPORTS; i++) {
+ aIn[i].init(i);
+ }
+ for (int i=0; i < NUMANOUTPORTS; i++) {
+ aOut[i].init(i);
+ }
+
sWav.reset();
@@ -263,7 +279,7 @@
}
sDigitalOut* MBEDSystem::getDigitalOutPtr(int portNum){
- if (portNum < NUMPORTS) {
+ if (portNum < NUMDIGOUTPORTS) {
return &dOut[portNum];
} else {
return NULL;
@@ -271,13 +287,29 @@
}
sDigitalIn* MBEDSystem::getDigitalInPtr(int portNum) {
- if (portNum < NUMPORTS) {
+ if (portNum < NUMDIGINPORTS) {
return &dIn[portNum];
} else {
return NULL;
}
}
+sAnalogOut* MBEDSystem::getAnalogOutPtr(int portNum){
+ if (portNum < NUMANOUTPORTS) {
+ return &aOut[portNum];
+ } else {
+ return NULL;
+ }
+}
+
+sAnalogIn* MBEDSystem::getAnalogInPtr(int portNum) {
+ if (portNum < NUMANINPORTS) {
+ return &aIn[portNum];
+ } else {
+ return NULL;
+ }
+}
+
sSound* MBEDSystem::createNewSoundAction() {
MBEDSound *tmpSound = new MBEDSound();
return tmpSound;
@@ -374,13 +406,70 @@
}
//-----------------------------------------------------
+MBEDAnalogOut::MBEDAnalogOut() {
+
+}
+
+void MBEDAnalogOut::init(int pin) {
+ if (pin < NUMANOUTPORTS) {
+ outpin = new AnalogOut(aOutPins[pin]);
+ pinExists = true;
+ }
+}
+
+int MBEDAnalogOut::read() {
+
+ if (pinExists) {
+ return outpin->read()*3300.0; //read value is a fload between 0 and 1.0 (max voltage). Convert to mV integer value.
+
+ } else {
+ return 0;
+ }
+
+}
+
+void MBEDAnalogOut::write(int value) {
+
+ if (pinExists) {
+
+ outpin->write((float)value / 3300.0);//should be a float input (percentage). We convert from integer mV value.
+ }
+
+
+}
+//--------------------------------------------------------
+
+MBEDAnalogIn::MBEDAnalogIn() {
+
+}
+
+void MBEDAnalogIn::init(int pin) {
+
+ if (pin < NUMANINPORTS) {
+ inpin = new AnalogIn(aInPins[pin]);
+ pinExists = true;
+ }
+
+}
+
+int MBEDAnalogIn::read() {
+
+ if (pinExists) {
+ return inpin->read()*3300; //read value is a fload between 0 and 1.0 (max voltage). Convert to mV integer value.
+ } else {
+ return 0;
+ }
+}
+
+
+//-----------------------------------------------------
MBEDDigitalOut::MBEDDigitalOut() {
pinExists = false;
}
void MBEDDigitalOut::init(int pin) {
- if (pin < NUMOUTPORTS) {
- outpin = new DigitalOut(outPins[pin]);
+ if (pin < NUMDIGOUTPORTS) {
+ outpin = new DigitalOut(dOutPins[pin]);
pinExists = true;
}
}
@@ -407,9 +496,9 @@
void MBEDDigitalIn::init(int pin) {
- if (pin < NUMINPORTS) {
- inpin = new DigitalIn(inPins[pin]);
- inpin_interrupt = new InterruptIn(inPins[pin]);
+ if (pin < NUMDIGINPORTS) {
+ inpin = new DigitalIn(dInPins[pin]);
+ inpin_interrupt = new InterruptIn(dInPins[pin]);
inpin->mode(PullDown);
//Set up callbacks for the port interrupts
inpin_interrupt->rise(this, &MBEDDigitalIn::interrupt_up_callback);