mirror of
https://github.com/supleed2/ELEC60013-ES-CW2.git
synced 2024-12-22 05:35:51 +00:00
P1 complete
This commit is contained in:
parent
1223947839
commit
65033439bd
|
@ -13,5 +13,6 @@ platform = ststm32
|
||||||
board = nucleo_l432kc
|
board = nucleo_l432kc
|
||||||
framework = arduino
|
framework = arduino
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
lib_deps =
|
lib_deps =
|
||||||
olikraus/U8g2@^2.32.10
|
olikraus/U8g2@^2.32.10
|
||||||
|
stm32duino/STM32duino FreeRTOS@^10.3.1
|
||||||
|
|
78
src/main.cpp
78
src/main.cpp
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <U8g2lib.h>
|
#include <U8g2lib.h>
|
||||||
|
#include <STM32FreeRTOS.h>
|
||||||
|
|
||||||
volatile int32_t currentStepSize;
|
volatile int32_t currentStepSize;
|
||||||
volatile uint8_t keyArray[7];
|
volatile uint8_t keyArray[7];
|
||||||
|
@ -90,7 +91,6 @@ uint16_t getTopKey(volatile uint8_t array[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Serial.println(topKey);
|
|
||||||
return topKey;
|
return topKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,12 +102,40 @@ void sampleISR(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void scanKeysTask(void * pvParameters){
|
void scanKeysTask(void * pvParameters){
|
||||||
for (uint8_t i = 0; i < 3; i++) {
|
const TickType_t xFrequency = 50/portTICK_PERIOD_MS;
|
||||||
|
TickType_t xLastWakeTime = xTaskGetTickCount();
|
||||||
|
while(1){
|
||||||
|
vTaskDelayUntil(&xLastWakeTime, xFrequency);
|
||||||
|
for (uint8_t i = 0; i < 3; i++) {
|
||||||
|
setRow(i);
|
||||||
|
delayMicroseconds(3);
|
||||||
|
keyArray[i] = readCols();
|
||||||
|
}
|
||||||
|
for (uint8_t i = 3; i < 7; i++) {
|
||||||
setRow(i);
|
setRow(i);
|
||||||
delayMicroseconds(3);
|
delayMicroseconds(3);
|
||||||
keyArray[i] = readCols();
|
keyArray[i] = readCols();
|
||||||
}
|
}
|
||||||
__atomic_store_n(¤tStepSize, stepSizes[getTopKey(keyArray)], __ATOMIC_RELAXED);
|
__atomic_store_n(¤tStepSize, stepSizes[getTopKey(keyArray)], __ATOMIC_RELAXED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void displayUpdateTask(void * pvParameters){
|
||||||
|
const TickType_t xFrequency = 100/portTICK_PERIOD_MS;
|
||||||
|
TickType_t xLastWakeTime = xTaskGetTickCount();
|
||||||
|
while(1){
|
||||||
|
vTaskDelayUntil(&xLastWakeTime, xFrequency);
|
||||||
|
u8g2.clearBuffer(); // clear the internal memory
|
||||||
|
u8g2.setFont(u8g2_font_profont12_mf); // choose a suitable font
|
||||||
|
u8g2.setCursor(2, 10); // set the cursor position
|
||||||
|
u8g2.print(currentStepSize); // Print the current frequency
|
||||||
|
digitalToggle(LED_BUILTIN);
|
||||||
|
u8g2.setCursor(2, 20);
|
||||||
|
for (uint8_t i = 0; i < 7; i++) {
|
||||||
|
u8g2.print(keyArray[i], HEX);
|
||||||
|
}
|
||||||
|
u8g2.sendBuffer(); // transfer internal memory to the display
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
@ -144,28 +172,26 @@ void setup() {
|
||||||
sampleTimer->setOverflow(samplingRate, HERTZ_FORMAT);
|
sampleTimer->setOverflow(samplingRate, HERTZ_FORMAT);
|
||||||
sampleTimer->attachInterrupt(sampleISR);
|
sampleTimer->attachInterrupt(sampleISR);
|
||||||
sampleTimer->resume();
|
sampleTimer->resume();
|
||||||
|
|
||||||
|
TaskHandle_t scanKeysHandle = NULL;
|
||||||
|
TaskHandle_t displayUpdateHandle = NULL;
|
||||||
|
xTaskCreate(
|
||||||
|
scanKeysTask, /* Function that implements the task */
|
||||||
|
"scanKeys", /* Text name for the task */
|
||||||
|
64, /* Stack size in words, not bytes */
|
||||||
|
NULL, /* Parameter passed into the task */
|
||||||
|
2, /* Task priority */
|
||||||
|
&scanKeysHandle /* Pointer to store the task handle */
|
||||||
|
);
|
||||||
|
xTaskCreate(
|
||||||
|
displayUpdateTask, /* Function that implements the task */
|
||||||
|
"displayUpdate", /* Text name for the task */
|
||||||
|
256, /* Stack size in words, not bytes */
|
||||||
|
NULL, /* Parameter passed into the task */
|
||||||
|
1, /* Task priority */
|
||||||
|
&displayUpdateHandle /* Pointer to store the task handle */
|
||||||
|
);
|
||||||
|
vTaskStartScheduler();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {}
|
||||||
static uint32_t next = millis();
|
|
||||||
for (uint8_t i = 3; i < 7; i++) {
|
|
||||||
setRow(i);
|
|
||||||
delayMicroseconds(3);
|
|
||||||
keyArray[i] = readCols();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (millis() > next) {
|
|
||||||
next += interval;
|
|
||||||
u8g2.clearBuffer(); // clear the internal memory
|
|
||||||
u8g2.setFont(u8g2_font_profont12_mf); // choose a suitable font
|
|
||||||
u8g2.setCursor(2, 10); // set the cursor position
|
|
||||||
scanKeysTask(NULL);
|
|
||||||
u8g2.print(currentStepSize); // Print the current frequency
|
|
||||||
digitalToggle(LED_BUILTIN);
|
|
||||||
u8g2.setCursor(2, 20);
|
|
||||||
for (uint8_t i = 0; i < 7; i++) {
|
|
||||||
u8g2.print(keyArray[i], HEX);
|
|
||||||
}
|
|
||||||
u8g2.sendBuffer(); // transfer internal memory to the display
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue