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 27
27
static int write_resolution = 8 ;
28
28
static int read_resolution = 10 ;
29
29
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
+
30
45
void analogWrite (PinName pin, int val)
31
46
{
32
47
pin_size_t idx = PinNameToIndex (pin);
@@ -45,6 +60,12 @@ void analogWrite(pin_size_t pin, int val)
45
60
if (pin >= PINS_COUNT) {
46
61
return ;
47
62
}
63
+ #ifdef DAC
64
+ if (pin == DAC) {
65
+ analogWriteDAC (digitalPinToPinName (pin), val);
66
+ return ;
67
+ }
68
+ #endif
48
69
float percent = (float )val/(float )(1 << write_resolution);
49
70
mbed::PwmOut* pwm = digitalPinToPwm (pin);
50
71
if (pwm == NULL ) {
Original file line number Diff line number Diff line change @@ -39,6 +39,9 @@ static const uint8_t A5 = PIN_A5;
39
39
static const uint8_t A6 = PIN_A6 ;
40
40
#define ADC_RESOLUTION 12
41
41
42
+ //DACs
43
+ #define DAC (A6)
44
+
42
45
// Serial
43
46
#define PIN_SERIAL_RX (13ul)
44
47
#define PIN_SERIAL_TX (14ul)
@@ -97,6 +100,6 @@ void _ontouch1200bps_();
97
100
#define SPI_MOSI (digitalPinToPinName(PIN_SPI_MOSI))
98
101
#define SPI_SCK (digitalPinToPinName(PIN_SPI_SCK))
99
102
100
- #define digitalPinToPort (P ) (digitalPinToPinName(P)/32 )
103
+ #define digitalPinToPort (P ) (digitalPinToPinName(P)/16 )
101
104
102
105
#endif //__PINS_ARDUINO__
Original file line number Diff line number Diff line change @@ -39,6 +39,9 @@ static const uint8_t A5 = PIN_A5;
39
39
static const uint8_t A6 = PIN_A6 ;
40
40
#define ADC_RESOLUTION 12
41
41
42
+ //DACs
43
+ #define DAC (A6)
44
+
42
45
// Serial
43
46
#define PIN_SERIAL_RX (13ul)
44
47
#define PIN_SERIAL_TX (14ul)
@@ -91,7 +94,6 @@ void _ontouch1200bps_();
91
94
#define I2C_SDA1 I2C_SDA_INTERNAL
92
95
#define I2C_SCL1 I2C_SCL_INTERNAL
93
96
94
-
95
97
#define SPI_HOWMANY 1
96
98
97
99
#define SPI_MISO (digitalPinToPinName(PIN_SPI_MISO))
You can’t perform that action at this time.
0 commit comments