@@ -41,8 +41,16 @@ uint8_t gSoftwareSerialNumObjs = 0;
41
41
42
42
SoftwareSerial *ap3_serial_handle = 0 ;
43
43
44
+ // Uncomment to enable debug pulses and Serial.prints
45
+ #define DEBUG
46
+
47
+ #ifdef DEBUG
48
+ #define SS_DEBUG_PIN 8
49
+ ap3_gpio_pad_t debugPad = ap3_gpio_pin2pad(SS_DEBUG_PIN);
50
+ #endif
51
+
44
52
// Software Serial ISR (To attach to pin change interrupts)
45
- void _software_serial_isr (void )
53
+ /* void _software_serial_isr(void)
46
54
{
47
55
uint64_t gpio_int_mask = 0x00;
48
56
am_hal_gpio_interrupt_status_get(true, &gpio_int_mask);
@@ -59,6 +67,10 @@ void _software_serial_isr(void)
59
67
obj->rxBit();
60
68
}
61
69
}
70
+ }*/
71
+ inline void _software_serial_isr (void )
72
+ {
73
+ ap3_serial_handle->rxBit ();
62
74
}
63
75
64
76
// Constructor
@@ -151,6 +163,20 @@ void SoftwareSerial::begin(uint32_t baudRate, HardwareSerial_Config_e SSconfig)
151
163
attachInterrupt (digitalPinToInterrupt (_rxPin), _software_serial_isr, CHANGE);
152
164
}
153
165
166
+ int SoftwareSerial::available ()
167
+ {
168
+ return (rxBufferHead + AP3_SS_BUFFER_SIZE - rxBufferTail) % AP3_SS_BUFFER_SIZE;
169
+ }
170
+
171
+ uint8_t SoftwareSerial::read ()
172
+ {
173
+ if (available () == 0 ) return (-1 );
174
+
175
+ rxBufferTail++;
176
+ rxBufferTail %= AP3_SS_BUFFER_SIZE;
177
+ return (rxBuffer[rxBufferTail]);
178
+ }
179
+
154
180
ap3_err_t SoftwareSerial::softwareserialSetConfig (HardwareSerial_Config_e SSconfig)
155
181
{
156
182
ap3_err_t retval = AP3_OK;
@@ -294,7 +320,7 @@ void SoftwareSerial::rxBit(void)
294
320
uint32_t bitTime = CTIMER->STTMR ; // Capture current system time
295
321
296
322
#ifdef DEBUG
297
- am_hal_gpio_output_set (triggerPad );
323
+ am_hal_gpio_output_set (debugPad );
298
324
#endif
299
325
300
326
if (lastBitTime == 0 )
@@ -360,7 +386,7 @@ void SoftwareSerial::rxBit(void)
360
386
}
361
387
362
388
#ifdef DEBUG
363
- am_hal_gpio_output_clear (triggerPad );
389
+ am_hal_gpio_output_clear (debugPad );
364
390
#endif
365
391
}
366
392
@@ -415,8 +441,8 @@ void SoftwareSerial::endOfByte()
415
441
else
416
442
{
417
443
#ifdef DEBUG
418
- am_hal_gpio_output_set (triggerPad );
419
- am_hal_gpio_output_clear (triggerPad );
444
+ am_hal_gpio_output_set (debugPad );
445
+ am_hal_gpio_output_clear (debugPad );
420
446
#endif
421
447
_rxBufferOverflow = true ;
422
448
}
@@ -433,7 +459,7 @@ void SoftwareSerial::endOfByte()
433
459
extern " C" void am_stimer_cmpr7_isr (void )
434
460
{
435
461
#ifdef DEBUG
436
- am_hal_gpio_output_set (triggerPad );
462
+ am_hal_gpio_output_set (debugPad );
437
463
#endif
438
464
439
465
uint32_t ui32Status = am_hal_stimer_int_status_get (false );
@@ -445,6 +471,6 @@ extern "C" void am_stimer_cmpr7_isr(void)
445
471
}
446
472
447
473
#ifdef DEBUG
448
- am_hal_gpio_output_clear (triggerPad );
474
+ am_hal_gpio_output_clear (debugPad );
449
475
#endif
450
476
}
0 commit comments