|
@@ -140,17 +140,27 @@ bool digitalRead(int pin) {
|
140
|
140
|
return LPC_GPIO(pin_map[pin].port)->FIOPIN & LPC_PIN(pin_map[pin].pin) ? 1 : 0;
|
141
|
141
|
}
|
142
|
142
|
|
143
|
|
-void analogWrite(int pin, int pin_status) { //todo: Hardware PWM
|
144
|
|
- /*
|
145
|
|
- if (pin == P2_4) {
|
146
|
|
- LPC_PWM1->MR5 = pin_status; // set value
|
147
|
|
- LPC_PWM1->LER = _BV(5); // set latch
|
148
|
|
- }
|
149
|
|
- else if (pin == P2_5) {
|
150
|
|
- LPC_PWM1->MR6 = pin_status;
|
151
|
|
- LPC_PWM1->LER = _BV(6);
|
|
143
|
+void analogWrite(int pin, int pwm_value) {
|
|
144
|
+/*
|
|
145
|
+ if (!WITHIN(pin, 0, NUM_DIGITAL_PINS - 1) || pin_map[pin].port == 0xFF)
|
|
146
|
+ return;
|
|
147
|
+
|
|
148
|
+ int old_pin = pin;
|
|
149
|
+ int old_value = pwm_value;
|
|
150
|
+
|
|
151
|
+ if(old_value != 0) {
|
|
152
|
+ for(uint16_t x = 0; x <= 5000; x++) {
|
|
153
|
+ LPC_GPIO(pin_map[pin].port)->FIOSET = LPC_PIN(pin_map[pin].pin);
|
|
154
|
+ //digitalWrite(old_pin, HIGH);
|
|
155
|
+ delayMicroseconds(old_value);
|
|
156
|
+ LPC_GPIO(pin_map[pin].port)->FIOCLR = LPC_PIN(pin_map[pin].pin);
|
|
157
|
+ //pinMode(pin, OUTPUT);
|
|
158
|
+ //digitalWrite(old_pin, LOW);
|
|
159
|
+ delayMicroseconds(255 - old_value);
|
|
160
|
+ }
|
152
|
161
|
}
|
153
|
|
- */
|
|
162
|
+*/
|
|
163
|
+
|
154
|
164
|
}
|
155
|
165
|
|
156
|
166
|
extern bool HAL_adc_finished();
|
|
@@ -175,7 +185,6 @@ void eeprom_read_block (void *__dst, const void *__src, size_t __n) { }
|
175
|
185
|
|
176
|
186
|
void eeprom_update_block (const void *__src, void *__dst, size_t __n) { }
|
177
|
187
|
|
178
|
|
-/***/
|
179
|
188
|
char *dtostrf (double __val, signed char __width, unsigned char __prec, char *__s) {
|
180
|
189
|
char format_string[20];
|
181
|
190
|
snprintf(format_string, 20, "%%%d.%df", __width, __prec);
|
|
@@ -195,4 +204,8 @@ void randomSeed(uint32_t value) {
|
195
|
204
|
srand(value);
|
196
|
205
|
}
|
197
|
206
|
|
|
207
|
+int map(uint16_t x, uint16_t in_min, uint16_t in_max, uint16_t out_min, uint16_t out_max) {
|
|
208
|
+ return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
|
209
|
+}
|
|
210
|
+
|
198
|
211
|
#endif // TARGET_LPC1768
|