midi melody start on button PD3/GND
This commit is contained in:
parent
db0af9c275
commit
e39352208d
5 changed files with 23 additions and 7 deletions
|
@ -14,6 +14,11 @@ enum GPIO_CNF : uint32_t {
|
|||
GPIO_UPDI_MPPO = 2u << 2,
|
||||
GPIO_none_MPDO = 3u << 2,
|
||||
};
|
||||
enum GPIOPuPd_TypeDef {
|
||||
GPIO_PuPd_NOPULL = 0x00,
|
||||
GPIO_PuPd_UP = 0x01,
|
||||
GPIO_PuPd_DOWN = 0x02
|
||||
};
|
||||
|
||||
class GpioClass {
|
||||
GPIOA_Type & port;
|
||||
|
@ -42,6 +47,10 @@ class GpioClass {
|
|||
operator bool () const {
|
||||
return port.INDR.R & (1u << pin);
|
||||
}
|
||||
void setPuPd (GPIOPuPd_TypeDef p) {
|
||||
if (p != GPIO_PuPd_UP) return;
|
||||
port.OUTDR.R |= 1u << pin;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _GPIO_CLASS_H_
|
||||
|
|
|
@ -48,11 +48,12 @@ static unsigned pwm_sd (const int input) {
|
|||
|
||||
/******************************************************************/
|
||||
/// Konstruktor
|
||||
MidiPlayer::MidiPlayer() noexcept : OneWay(), led (LED_CFG), passcnt (0u) {
|
||||
MidiPlayer::MidiPlayer() noexcept : OneWay(), led (LED_CFG), but (BUT_CFG), passcnt (0u) {
|
||||
index = 0;
|
||||
pause = 0;
|
||||
melody = scores[index++];
|
||||
running = true;
|
||||
running = false;
|
||||
but.setPuPd (GPIO_PuPd_UP);
|
||||
}
|
||||
void MidiPlayer::pass() {
|
||||
const bool b = passcnt & 0x10000;
|
||||
|
@ -61,7 +62,8 @@ void MidiPlayer::pass() {
|
|||
}
|
||||
|
||||
unsigned MidiPlayer::Send (uint16_t * const ptr, const unsigned len) {
|
||||
//if (!but.get()) running = true; // případně spouštět tlačítkem, není implementováno
|
||||
const bool b = but;
|
||||
if (!b and !running) running = true;
|
||||
|
||||
if (!running) {
|
||||
for (unsigned n=0; n<len; n++) ptr [n] = MAXPWM >> 1;
|
||||
|
@ -75,7 +77,7 @@ unsigned MidiPlayer::Send (uint16_t * const ptr, const unsigned len) {
|
|||
return len;
|
||||
}
|
||||
void MidiPlayer::stop (void) {
|
||||
//running = false; // na konci každé melodie stop
|
||||
running = false; // na konci každé melodie stop
|
||||
melody = scores[index++];
|
||||
if (!melody) {
|
||||
index = 0;
|
||||
|
|
|
@ -19,7 +19,7 @@ class MidiPlayer : public OneWay {
|
|||
/// Obsluha vzorku
|
||||
short nextSample (void);
|
||||
private:
|
||||
GpioClass led;
|
||||
GpioClass led, but;
|
||||
unsigned passcnt;
|
||||
volatile bool running;
|
||||
unsigned char const * melody;
|
||||
|
|
|
@ -4,10 +4,12 @@
|
|||
static constexpr unsigned HALF_LEN = 0x80u;
|
||||
static constexpr unsigned MAXPWM = 2000u;
|
||||
|
||||
#ifdef __riscv
|
||||
#if __riscv
|
||||
#define LED_CFG GPIOD,4
|
||||
#define BUT_CFG GPIOD,3,(GPIO_Speed_In | GPIO_UPDI_MPPO)
|
||||
#elif __arm__
|
||||
#define LED_CFG GpioPortA,0
|
||||
#define BUT_CFG GpioPortA,3,GPIO_Mode_IN
|
||||
#else
|
||||
#error "bad target"
|
||||
#endif
|
||||
|
|
|
@ -91,13 +91,16 @@ class GpioClass {
|
|||
/// Načti logickou hodnotu na pinu
|
||||
const bool get (void) const {
|
||||
if (io->IDR.R & pos) return true;
|
||||
else return false;
|
||||
else return false;
|
||||
};
|
||||
/// A to samé jako operátor
|
||||
const GpioClass& operator>> (bool& b) const {
|
||||
b = get();
|
||||
return *this;
|
||||
}
|
||||
operator bool () const {
|
||||
return get();
|
||||
}
|
||||
//![Gpio example]
|
||||
void setMode (GPIOMode_TypeDef p) {
|
||||
uint32_t dno = num * 2;
|
||||
|
|
Loading…
Add table
Reference in a new issue