mirror of
https://github.com/supleed2/ELEC60013-ES-CW2.git
synced 2025-01-07 21:22:01 +00:00
P2S5 done
This commit is contained in:
parent
65033439bd
commit
5b0661e77f
24
src/main.cpp
24
src/main.cpp
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
volatile int32_t currentStepSize;
|
volatile int32_t currentStepSize;
|
||||||
volatile uint8_t keyArray[7];
|
volatile uint8_t keyArray[7];
|
||||||
volatile uint8_t *keyArrayPtr = keyArray;
|
SemaphoreHandle_t keyArrayMutex;
|
||||||
|
|
||||||
#pragma region Config Values
|
#pragma region Config Values
|
||||||
const uint32_t interval = 10; // Display update interval
|
const uint32_t interval = 10; // Display update interval
|
||||||
|
@ -23,7 +23,6 @@ const int32_t stepSizes[] = {0,
|
||||||
107980982, 114401866, 121204555, 12841175, 136047513, 144137319, 152708170,
|
107980982, 114401866, 121204555, 12841175, 136047513, 144137319, 152708170,
|
||||||
161788670, 171409125, 181601642, 192400238}; // Step sizes for each note
|
161788670, 171409125, 181601642, 192400238}; // Step sizes for each note
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
#pragma region Pin Definitions
|
#pragma region Pin Definitions
|
||||||
// Row select and enable
|
// Row select and enable
|
||||||
const int RA0_PIN = D3;
|
const int RA0_PIN = D3;
|
||||||
|
@ -102,21 +101,23 @@ void sampleISR(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void scanKeysTask(void * pvParameters){
|
void scanKeysTask(void * pvParameters){
|
||||||
|
uint8_t keyArrayCopy[7];
|
||||||
const TickType_t xFrequency = 50/portTICK_PERIOD_MS;
|
const TickType_t xFrequency = 50/portTICK_PERIOD_MS;
|
||||||
TickType_t xLastWakeTime = xTaskGetTickCount();
|
TickType_t xLastWakeTime = xTaskGetTickCount();
|
||||||
while(1){
|
while(1){
|
||||||
vTaskDelayUntil(&xLastWakeTime, xFrequency);
|
vTaskDelayUntil(&xLastWakeTime, xFrequency);
|
||||||
for (uint8_t i = 0; i < 3; i++) {
|
xSemaphoreTake(keyArrayMutex, portMAX_DELAY);
|
||||||
|
memcpy(keyArrayCopy, (void*)keyArray, 7);
|
||||||
|
xSemaphoreGive(keyArrayMutex);
|
||||||
|
for (uint8_t i = 0; i < 7; i++) {
|
||||||
setRow(i);
|
setRow(i);
|
||||||
delayMicroseconds(3);
|
delayMicroseconds(3);
|
||||||
keyArray[i] = readCols();
|
keyArrayCopy[i] = readCols();
|
||||||
}
|
}
|
||||||
for (uint8_t i = 3; i < 7; i++) {
|
xSemaphoreTake(keyArrayMutex, portMAX_DELAY);
|
||||||
setRow(i);
|
memcpy((void*)keyArray, keyArrayCopy, 7);
|
||||||
delayMicroseconds(3);
|
xSemaphoreGive(keyArrayMutex);
|
||||||
keyArray[i] = readCols();
|
__atomic_store_n(¤tStepSize, stepSizes[getTopKey(keyArrayCopy)], __ATOMIC_RELAXED);
|
||||||
}
|
|
||||||
__atomic_store_n(¤tStepSize, stepSizes[getTopKey(keyArray)], __ATOMIC_RELAXED);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,6 +192,9 @@ void setup() {
|
||||||
1, /* Task priority */
|
1, /* Task priority */
|
||||||
&displayUpdateHandle /* Pointer to store the task handle */
|
&displayUpdateHandle /* Pointer to store the task handle */
|
||||||
);
|
);
|
||||||
|
|
||||||
|
keyArrayMutex = xSemaphoreCreateMutex();
|
||||||
|
|
||||||
vTaskStartScheduler();
|
vTaskStartScheduler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue