mirror of
https://github.com/DashyFox/MusicRing.git
synced 2025-05-04 13:30:16 +00:00
stm
This commit is contained in:
parent
45771f8f5f
commit
3dd1f7828b
5
.vscode/arduino.json
vendored
5
.vscode/arduino.json
vendored
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"port": "COM3",
|
"port": "COM3",
|
||||||
"board": "arduino:avr:uno",
|
"board": "STMicroelectronics:stm32:GenF4",
|
||||||
"sketch": "MusicRing.ino"
|
"sketch": "MusicRing.ino",
|
||||||
|
"configuration": "pnum=BLACKPILL_F411CE,upload_method=swdMethod,xserial=generic,usb=CDCgen,xusb=FS,opt=osstd,dbg=none,rtlib=nano"
|
||||||
}
|
}
|
@ -5,35 +5,30 @@
|
|||||||
#include "./implement/Display__Adafruit_SSD1306.h"
|
#include "./implement/Display__Adafruit_SSD1306.h"
|
||||||
#include "./misc/bitmaps.h"
|
#include "./misc/bitmaps.h"
|
||||||
|
|
||||||
LED_Ring_PINOUT pinout { 5, 6, 7, 8, 9 };
|
LED_Ring_PINOUT pinout { PA4, PA3, PA5, PA1, PA2 };
|
||||||
|
|
||||||
LED_Ring ring(32, pinout);
|
LED_Ring ring(32, pinout);
|
||||||
Screen screen(128, 32, Display::Ori_HORIZONTAL);
|
|
||||||
|
void ISR() { ring.isr(); }
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
ring.begin();
|
ring.begin(ISR);
|
||||||
screen.begin();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
screen.adafruit->drawBitmap(0, 0, DashyFox_logo, 128, 32, WHITE);
|
|
||||||
screen.adafruit->display();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ISR(TIMER1_COMPA_vect) { ring.isr(); }
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
if (Serial.available())
|
||||||
static uint32_t tmr;
|
{
|
||||||
static uint8_t arr[6] = { 0x3f >> 1, 0xf0 ,0x7f >> 3, 0xf8, 0x3f >> 1, 0xf0 };
|
uint8_t input = Serial.parseInt();
|
||||||
static uint8_t arr2[6] = { 0 };
|
ring.setFrec(input);
|
||||||
static bool f = false;
|
|
||||||
if (millis() - tmr > 350) {
|
|
||||||
screen.adafruit->drawBitmap(105, 23, arr, 16, 3, f);
|
|
||||||
screen.adafruit->display();
|
|
||||||
tmr = millis();
|
|
||||||
f = !f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -3,15 +3,17 @@
|
|||||||
|
|
||||||
struct LED_Ring_PINOUT {
|
struct LED_Ring_PINOUT {
|
||||||
uint8_t
|
uint8_t
|
||||||
Data,
|
Data, // yellow
|
||||||
CLK_inside,
|
CLK_inside, // red
|
||||||
CLK_outside,
|
CLK_outside, // orange
|
||||||
RESET,
|
RESET, // green
|
||||||
OutputEnable;
|
OutputEnable; // pur
|
||||||
};
|
};
|
||||||
|
|
||||||
class LED_Ring {
|
class LED_Ring {
|
||||||
private:
|
private:
|
||||||
|
HardwareTimer *MyTim = nullptr;
|
||||||
|
|
||||||
LED_Ring_PINOUT pinOut;
|
LED_Ring_PINOUT pinOut;
|
||||||
uint16_t ledCount;
|
uint16_t ledCount;
|
||||||
uint16_t updateFrec;
|
uint16_t updateFrec;
|
||||||
@ -35,7 +37,7 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void begin() {
|
void begin(void(*func)(void)) {
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
@ -58,7 +60,7 @@ public:
|
|||||||
delay(del);
|
delay(del);
|
||||||
}
|
}
|
||||||
|
|
||||||
timerIni(frec);
|
timerIni(frec, func);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -96,7 +98,7 @@ public:
|
|||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void isr() {
|
void isr() {
|
||||||
if (position >= ledCount) {
|
if (position > ledCount) {
|
||||||
point_ini(1);
|
point_ini(1);
|
||||||
position = 1;
|
position = 1;
|
||||||
} else shift(1);
|
} else shift(1);
|
||||||
@ -104,36 +106,47 @@ public:
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void timerIni(uint16_t _frec) { //TODO: Сделать возможность выбора таймеров
|
void timerIni(uint16_t _frec, void(*func)(void)) {
|
||||||
period = F_CPU / 8 / ledCount / _frec;
|
// Определяем таймер, например, используем TIM2
|
||||||
// инициализация Timer1
|
MyTim = new HardwareTimer(TIM2);
|
||||||
cli(); // отключить глобальные прерывания
|
|
||||||
TCCR1A = 0; // установить регистры в 0
|
|
||||||
TCCR1B = 0;
|
|
||||||
|
|
||||||
OCR1A = period; // установка регистра совпадения
|
// Рассчитываем период
|
||||||
TCCR1B |= (1 << WGM12); // включение в CTC режим
|
uint32_t prescaler = 8; // Делитель
|
||||||
|
period = (SystemCoreClock / (prescaler * _frec)) - 1;
|
||||||
|
|
||||||
// Установка битов CS на коэффициент деления 8
|
// Останавливаем таймер перед настройкой
|
||||||
TCCR1B |= 0b00000010;
|
MyTim->pause();
|
||||||
|
|
||||||
TIMSK1 |= (1 << OCIE1A); // включение прерываний по совпадению
|
// Настраиваем предделитель (делитель частоты)
|
||||||
sei(); // включить глобальные прерывания
|
MyTim->setPrescaleFactor(prescaler);
|
||||||
}
|
|
||||||
|
|
||||||
void setFrec(uint8_t frec) {
|
|
||||||
period = F_CPU / 8 / ledCount / frec;
|
|
||||||
cli();
|
|
||||||
OCR1A = period; // установка регистра совпадения
|
|
||||||
sei();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setPeriod(uint8_t per) {
|
// Настраиваем таймер в режиме CTC (count-to-clear)
|
||||||
period = per;
|
MyTim->setOverflow(period);
|
||||||
cli();
|
MyTim->attachInterrupt(func);
|
||||||
OCR1A = period; // установка регистра совпадения
|
MyTim->resume();
|
||||||
sei();
|
}
|
||||||
}
|
|
||||||
|
void setFrec(uint16_t frec) {
|
||||||
|
uint32_t prescaler = 8; // Делитель
|
||||||
|
period = (SystemCoreClock / (prescaler * frec)) - 1;
|
||||||
|
|
||||||
|
// Останавливаем таймер перед изменением периода
|
||||||
|
MyTim->pause();
|
||||||
|
MyTim->setOverflow(period);
|
||||||
|
MyTim->refresh(); // Обновление настроек таймера
|
||||||
|
MyTim->resume();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setPeriod(uint32_t per) {
|
||||||
|
period = per;
|
||||||
|
|
||||||
|
// Останавливаем таймер перед изменением периода
|
||||||
|
MyTim->pause();
|
||||||
|
MyTim->setOverflow(period);
|
||||||
|
MyTim->refresh(); // Обновление настроек таймера
|
||||||
|
MyTim->resume();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user