File tree Expand file tree Collapse file tree 3 files changed +28
-2
lines changed
Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 2727static int write_resolution = 8 ;
2828static int read_resolution = 10 ;
2929
30+ #if DEVICE_ANALOGOUT
31+ #include " mbed/drivers/AnalogOut.h"
32+ mbed::AnalogOut* dac = NULL ;
33+ void analogWriteDAC (PinName pin, int val) {
34+ if (dac == NULL ) {
35+ dac = new mbed::AnalogOut (pin);
36+ }
37+ float percent = (float )val/(float )(1 << write_resolution);
38+ if (percent > 1 .0f ) {
39+ percent = 1 .0f ;
40+ }
41+ dac->write (percent);
42+ }
43+ #endif
44+
3045void analogWrite (PinName pin, int val)
3146{
3247 pin_size_t idx = PinNameToIndex (pin);
@@ -45,6 +60,12 @@ void analogWrite(pin_size_t pin, int val)
4560 if (pin >= PINS_COUNT) {
4661 return ;
4762 }
63+ #ifdef DAC
64+ if (pin == DAC) {
65+ analogWriteDAC (digitalPinToPinName (pin), val);
66+ return ;
67+ }
68+ #endif
4869 float percent = (float )val/(float )(1 << write_resolution);
4970 mbed::PwmOut* pwm = digitalPinToPwm (pin);
5071 if (pwm == NULL ) {
Original file line number Diff line number Diff line change @@ -39,6 +39,9 @@ static const uint8_t A5 = PIN_A5;
3939static const uint8_t A6 = PIN_A6 ;
4040#define ADC_RESOLUTION 12
4141
42+ //DACs
43+ #define DAC (A6)
44+
4245// Serial
4346#define PIN_SERIAL_RX (13ul)
4447#define PIN_SERIAL_TX (14ul)
@@ -97,6 +100,6 @@ void _ontouch1200bps_();
97100#define SPI_MOSI (digitalPinToPinName(PIN_SPI_MOSI))
98101#define SPI_SCK (digitalPinToPinName(PIN_SPI_SCK))
99102
100- #define digitalPinToPort (P ) (digitalPinToPinName(P)/32 )
103+ #define digitalPinToPort (P ) (digitalPinToPinName(P)/16 )
101104
102105#endif //__PINS_ARDUINO__
Original file line number Diff line number Diff line change @@ -39,6 +39,9 @@ static const uint8_t A5 = PIN_A5;
3939static const uint8_t A6 = PIN_A6 ;
4040#define ADC_RESOLUTION 12
4141
42+ //DACs
43+ #define DAC (A6)
44+
4245// Serial
4346#define PIN_SERIAL_RX (13ul)
4447#define PIN_SERIAL_TX (14ul)
@@ -91,7 +94,6 @@ void _ontouch1200bps_();
9194#define I2C_SDA1 I2C_SDA_INTERNAL
9295#define I2C_SCL1 I2C_SCL_INTERNAL
9396
94-
9597#define SPI_HOWMANY 1
9698
9799#define SPI_MISO (digitalPinToPinName(PIN_SPI_MISO))
You can’t perform that action at this time.
0 commit comments