1
0
Fork 0

Update to arm_atsam wait and timer routines

Microsecond (us) delays are now handled by a busy wait loop according to MCU frequency. This replaces the system counter method which had an overhead of around 12us.
TC5 device and supporting routines removed as it was the old us delay counter.
wait_ms is now properly a macro to CLK_delay_ms.
wait_us is now properly a macro to CLK_delay_us.
Removed CLK_get_us as it has no use.
All calls to CLK_get_ms() have been replaced by timer_read64() with corrected typing.
All calls to CLK_delay_ms() have been replaced by wait_ms().
All calls to CLK_delay_us() have been replaced by wait_us() and timings verified or updated as needed after review on scope.
Corrected typing of variables using 64bit ms timer readings if needed.
This commit is contained in:
patrickmt 2018-12-18 15:21:25 -05:00 committed by Drashna Jaelre
parent 2898699804
commit 6e984a8b5e
12 changed files with 61 additions and 133 deletions

View file

@ -79,8 +79,6 @@ void matrix_init(void)
matrix_init_quantum();
}
#define MATRIX_SCAN_DELAY 10 //Delay after setting a col to output (in us)
uint64_t mdebouncing = 0;
uint8_t matrix_scan(void)
{
@ -89,9 +87,7 @@ uint8_t matrix_scan(void)
uint8_t col;
uint32_t scans[2]; //PA PB
if (CLK_get_ms() < mdebouncing) return 1; //mdebouncing == 0 when no debouncing active
//DBG_1_OFF; //Profiling scans
if (timer_read64() < mdebouncing) return 1; //mdebouncing == 0 when no debouncing active
memset(mlatest, 0, MATRIX_ROWS * sizeof(matrix_row_t)); //Zero the result buffer
@ -99,7 +95,7 @@ uint8_t matrix_scan(void)
{
PORT->Group[col_ports[col]].OUTSET.reg = 1 << col_pins[col]; //Set col output
CLK_delay_us(MATRIX_SCAN_DELAY); //Delay for output
wait_us(1); //Delay for output
scans[PA] = PORT->Group[PA].IN.reg & row_masks[PA]; //Read PA row pins data
scans[PB] = PORT->Group[PB].IN.reg & row_masks[PB]; //Read PB row pins data
@ -132,11 +128,9 @@ uint8_t matrix_scan(void)
else
{
//Begin or extend debounce on change
mdebouncing = CLK_get_ms() + DEBOUNCING_DELAY;
mdebouncing = timer_read64() + DEBOUNCING_DELAY;
}
//DBG_1_ON; //Profiling scans
matrix_scan_quantum();
return 1;