[O] (Experimental) switch to stm32

This commit is contained in:
Hykilpikonna
2023-04-10 18:50:21 -04:00
parent 23decb6c75
commit cc5c2ae6cb
5 changed files with 39 additions and 13 deletions
+1 -1
View File
@@ -30,4 +30,4 @@ add_custom_target(
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_executable(Z_DUMMY_TARGET ${SRC_LIST} src/macros.h src/config.h)
add_executable(Z_DUMMY_TARGET ${SRC_LIST})
+16 -4
View File
@@ -13,16 +13,28 @@
;board = wemos_d1_uno32
;framework = arduino
[env:s2]
platform = espressif32
board = lolin_s2_mini
framework = arduino
; ESP32-S2 and C3 both has a problem where the ADC jumps around a LOT
;[env:s2]
;platform = espressif32
;board = lolin_s2_mini
;framework = arduino
;[env:c3]
;platform = espressif32
;board = dfrobot_beetle_esp32c3
;framework = arduino
; YD STM32F411CEU6
[env:stm32f411ce]
platform = ststm32
board = blackpill_f411ce
framework = arduino
;upload_protocol = stlink
; Flash using yd-link
;debug_tool = cmsis-dap
upload_protocol = cmsis-dap
; Arduino nano is good but too few pins
;[env:n328p]
;platform = atmelavr
;board = nanoatmega328
+8 -3
View File
@@ -1,19 +1,24 @@
#ifndef FIRMWARE_CONFIG_H
#define FIRMWARE_CONFIG_H
#include "stm32f4xx_hal.h"
// ========================================
// Configuration
// Pin Configuration
// ========================================
// LED indicator for pulling update
const int LED_REFRESH = PA13;
// 4 1:16 Multiplexers: GPIO pins for each analog multiplexer that handles 12 sensors of an octave
// Notes are connected in order: Mux #1 (0-11), Mux #2 (12-23), Mux #3 (24-35), Mux #4 (36-47), Mux #5 (48-59)
const int NUM_MUX = 5;
const int PINS_PER_MUX = 12;
const int MUX_IN[NUM_MUX] = {34, 34, 35, 34, 34}; // Analog signal input
const int MUX_IN[NUM_MUX] = {PA0, PA1, PA2, PA3, PA4}; // Analog signal input
// Select pins for every multiplexer, each multiplexer has 4 select pins, all sel0 are connected to 14, etc.
const int NUM_MUX_SEL = 4;
const int MUX_SEL_OUT[NUM_MUX_SEL] = {14, 27, 16, 17};
const int MUX_SEL_OUT[NUM_MUX_SEL] = {PB4, PB5, PB6, PB7};
// 3 1:8 Multiplexers for the midi panel
const int P_NUM_MUX = 3;
+2 -1
View File
@@ -5,7 +5,8 @@
#define u16 uint16_t
#define u32 uint32_t
#define u64 uint64_t
#define timeMillis() std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count()
//#define timeMillis() std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count()
#define timeMillis() HAL_GetTick()
#define min(a, b) ((a) < (b) ? (a) : (b))
#define let auto
#define val const auto
+12 -4
View File
@@ -4,6 +4,8 @@
#include "macros.h"
#include "config.h"
#include "stm32f4xx_hal.h"
// ========================================
// Code
// ========================================
@@ -26,15 +28,19 @@ const Note notes[] = {
{"C7", 96}
};
int lasts[NUM_NOTES]; // variable to store the value coming from the sensor
u32 lasts[NUM_NOTES]; // variable to store the value coming from the sensor
u64 last_hit_times[NUM_NOTES];
val max_sensor = 4096;
val max_threshold = 2000;
val active_threshold = 100; // Minimum value to be considered as a hit
let led_refresh_on = false;
void setup()
{
HAL_Init();
// Initialize pin and serial
for (int pin: MUX_IN) pinMode(pin, INPUT);
for (int pin: MUX_SEL_OUT) pinMode(pin, OUTPUT);
@@ -49,7 +55,7 @@ void setup()
*
* @param id Sensor index
*/
void on_sensor_update(int id, u64 time, int last, int current)
void on_sensor_update(int id, u64 time, u32 last, u32 current)
{
// If the last value is larger than the current value, check timeout
if (last > current && last > active_threshold)
@@ -77,6 +83,8 @@ void loop()
u64 time = timeMillis();
u64 elapsed = time - start_time;
// Toggle LED refresh indicator
digitalWrite(LED_REFRESH, led_refresh_on = !led_refresh_on);
// Serial.printf("%" PRIu64 "=============\r\n", elapsed);
// Loop through each multiplexer state
@@ -96,11 +104,11 @@ void loop()
if (note_id >= NUM_NOTES) break;
// Read the analog input
int v = analogRead(MUX_IN[j]);
u32 v = analogRead(MUX_IN[j]);
if (v != lasts[note_id])
{
// Serial prints are really slow, so don't use them in debug mode
Serial.printf("%s %d\r\n", notes[note_id].name, v);
Serial.printf("%s %d\r\n", notes[note_id].name, v);
on_sensor_update(note_id, time, lasts[note_id], v);
}
lasts[note_id] = v;