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.
Dependents: kl25z-tinyshell-demo tsi_slider_light_senso_LED frdm_tsi_slider_led_blend demo_slider ... more
Revision 4:f64097679f27, committed 2014-08-04
- Comitter:
- bjo3rn
- Date:
- Mon Aug 04 07:43:15 2014 +0000
- Parent:
- 3:20ffa9b18488
- Child:
- 5:14f1557e02a0
- Child:
- 6:f269379b60c5
- Commit message:
- Added constructors that take pin names, not just tsi channels
Changed in this revision
| tsi_sensor.cpp | Show annotated file Show diff for this revision Revisions of this file |
| tsi_sensor.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/tsi_sensor.cpp Sun Feb 23 18:31:58 2014 +0000
+++ b/tsi_sensor.cpp Mon Aug 04 07:43:15 2014 +0000
@@ -24,9 +24,16 @@
void tsi_irq(void);
TSIAnalogSlider *TSIAnalogSlider::_instance;
+TSIAnalogSlider::TSIAnalogSlider(PinName pin0, PinName pin1, uint32_t range): _elec0(pin0), _elec1(pin1), _range(range) {
+ initObject();
+}
TSIAnalogSlider::TSIAnalogSlider(uint32_t elec0, uint32_t elec1,
uint32_t range)
: _elec0(elec0), _elec1(elec1), _range(range) {
+ initObject();
+}
+
+void TSIAnalogSlider::initObject(void) {
_instance = this;
_current_elec = &_elec0;
SIM->SCGC5 |= SIM_SCGC5_TSI_MASK;
--- a/tsi_sensor.h Sun Feb 23 18:31:58 2014 +0000
+++ b/tsi_sensor.h Mon Aug 04 07:43:15 2014 +0000
@@ -52,6 +52,12 @@
public:
/** Initialize electrode.
*/
+ TSIElectrode(PinName pin) : _threshold(100) {
+ _channel = getTSIChannel(pin);
+ }
+
+ /** Initialize electrode.
+ */
TSIElectrode(uint32_t tsi_channel) : _threshold(100) {
_channel = (uint8_t)tsi_channel;
}
@@ -100,6 +106,38 @@
uint32_t getChannel() {
return _channel;
}
+ /** Get TSI Channel for PinName.
+ *
+ * @returns TSI channel ID for use in constructor of TSIAnalogSlider and TSIElectrode.
+ * @throws compile-time error if target is not supported, or runtime error if pin does not match any channel.
+ */
+ static uint8_t getTSIChannel(PinName pin) {
+#if defined (TARGET_KL25Z)
+ switch(pin) {
+ //these are
+ case PTA0: return 1;
+ case PTA1: return 2;
+ case PTA2: return 3;
+ case PTA3: return 4;
+ case PTA4: return 5;
+ case PTB0: return 0;
+ case PTB1: return 6;
+ case PTB2: return 7;
+ case PTB3: return 8;
+ case PTB16: return 9;
+ case PTB17: return 10;
+ case PTB18: return 11;
+ case PTB19: return 12;
+ case PTC0: return 13;
+ case PTC1: return 14;
+ default: error("PinName provided to TSIElectrode::getTSIChannel() does not correspond to any known TSI channel.");
+ }
+# else
+ #error "Unknown target for TSIElectrode::getTSIChannel() - only supports KL25Z so far."
+# endif
+ return 0xFF; //should never get here
+ }
+
private:
uint8_t _channel;
uint16_t _signal;
@@ -112,6 +150,11 @@
class TSIAnalogSlider {
public:
/**
+ *
+ * Initialize the TSI Touch Sensor with the given PinNames
+ */
+ TSIAnalogSlider(PinName elec0, PinName elec1, uint32_t range);
+ /**
* Initialize the TSI Touch Sensor
*/
TSIAnalogSlider(uint32_t elec0, uint32_t elec1, uint32_t range);
@@ -167,6 +210,7 @@
return _instance;
}
private:
+ void initObject(void); //shared constructor code
void sliderRead(void);
void selfCalibration(void);
void setSliderPercPosition(uint32_t elec_num, uint32_t position) {