From d2c3f3770c4099d536ff5ea0e9a432541707c0d2 Mon Sep 17 00:00:00 2001 From: Kizarm Date: Sun, 10 Mar 2024 17:40:00 +0100 Subject: [PATCH] fix BUG (constructors ?) --- ch32v003/gcc.mk | 4 ++-- midi/main.cpp | 5 +++++ midi/mid/demo10.mid | Bin 0 -> 4154 bytes midi/mid/joy.mid | Bin 4810 -> 0 bytes midi/midiplayer.cpp | 15 +++++++++++---- midi/midiplayer.h | 7 ++++--- midi/pwmconfig.h | 8 ++++++++ 7 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 midi/mid/demo10.mid delete mode 100644 midi/mid/joy.mid diff --git a/ch32v003/gcc.mk b/ch32v003/gcc.mk index 713da29..a13e1d2 100644 --- a/ch32v003/gcc.mk +++ b/ch32v003/gcc.mk @@ -7,11 +7,11 @@ SIZE = $(PREFIX)size DUMP = $(PREFIX)objdump COPY = $(PREFIX)objcopy OBJS += startup.o system.o -CFLAGS+= -Os -flto +CFLAGS+= -Os CCPU = -march=rv32ec -mabi=ilp32e MCPU = $(CCPU) CFLAGS+= $(MCPU) LFLAGS+= -Wl,--Map=$(@:%.elf=%.map),--gc-sections #LFLAGS+= -Wl,--print-sysroot -- chyba ld ? -LFLAGS+= -flto -O3 $(MCPU) -nostartfiles -nostdlib +LFLAGS+= -O3 $(MCPU) -nostartfiles -nostdlib LDLIBS+= -lgcc -L./$(TARGET) -T generated_ch32v003.ld diff --git a/midi/main.cpp b/midi/main.cpp index 0f68daf..062738d 100644 --- a/midi/main.cpp +++ b/midi/main.cpp @@ -7,10 +7,15 @@ static PcmDma pcm; int main (void) { pcm.attach (player); for (;;) { + player.pass(); /* BUG: * Do smyčky nejde přidat jakýkoli další kód. * Proč, neumím vysvětlit, ale lze to izolovat. * Je zajímavé, že ADC postavené podobně to nedělá. + * + * FIX: 1. Vynechat LTO optimalizaci. Optimalizuje asi moc, ale zase tak moc neušetří. + * 2. Činnost nechat v metodě pass() hlavní třídy. + * Zřejmě je tam nějaký problém s voláním konstruktorů. * */ } return 0; diff --git a/midi/mid/demo10.mid b/midi/mid/demo10.mid new file mode 100644 index 0000000000000000000000000000000000000000..d7cb2e2d628e6e42c54e0c411a840b14efcabcda GIT binary patch literal 4154 zcmeHIJ#W)s5Waq+3gj$Ehy_b5MJ3HZrGBZ^iyYH9#Ayp1h!7%g6O%-3YRfUSok&^% zBLVRTSeSvC0r(~S12)!hXS=UMYq@npDh52A@4b8OxqIFZeZ5)+fKeELk%1rjy1j{i zyU-cDu9()IU8__bd7^Yf-o;N2Tp4q#Y}n8lyR6s-cZ{;Uu_xa%8%BlOWn&u`u2mh! znop&6c6O$0u~2{7sFkKlW<3R+wV|>1GISmc4-a0saPSj4De&u0LuW|J7*xC=n@{B1 zTXhZ}#~C~V7%Rg=fX=}9w&@tMWAoBxckbwyc)5slRnD7^Q`@dod0p0tpq%Co-{1`c zR}=T=?<$IH-MT41t8rPq17EYy&J|i#GsmEvRa=Q>mKEDt;Q*Q%8mhYgys0uC7>qoO zJd~wk*0PGmG8!5gnujAH4sYkwmqkP_w(}I6$E6&___ZvIakCO`t(=NQDOe>#MI%dD z6qBK>3>u=AN>nLEp%}^`gz_o4(geY;fc#QMmCukwLwQ{5~1&dnIT1f6DQ7B7sb#F;-I?gaw z7ak63A)ywWwD9-{9MmFC7g1WANGzl}X+dLIqfXachG>vF!h@&D>m4_Mgd2cPf$tH3 zVydE3+~E@LaE^N(0qN|lP>B^ZmdT)L2oGv;c)omOF&_aav=Bu_Os;QT1ho!NE_%E> z0f~9H1fE<^y)qEHGFi z4&mPOVs~CpK!HQEPE(^eeXa zsfHu;i*M9Cqt-(ByjvBw|KNw?xBsW^+y7hgp!g=KwX9YW@5(b+laxD2xq%fQZ-P)J y&c-0RTEHr>qBFu){|>)^L9`XdAj}uA3aqfW)B2)W1*@mU3s?o#vD~(WyY)A)+(V%N literal 0 HcmV?d00001 diff --git a/midi/mid/joy.mid b/midi/mid/joy.mid deleted file mode 100644 index 10d72aa7f6c1c62c3b5e3a92f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<>1PKsTtl{fR?WJ+^&C9 zWzbz*SNQBChwCM^H?x-@MxfYX^Wb>1a0?^dGx^9lTCLN?6B8>V#H6; zFeHa|hNyrhugoHE*qxxOb;C;5y;`w4)|4-q)Vd#cge#ei0@#YGo998QdYw`ROC-DQ zPv{F{DqW3*lU84kkI`?wz+?1#d5lg^@EUzHIX*vqeKK|bXt+B*NZs&9x6+1rIkznd zn{Ua$?Bq%rY|b^6!b%z_>dX~LdV61RPI;XjG>5s8;@0qGSQM5rIF;AKoK?-)(3~+D z3}osKT{A}kS4bpBPw0P11fEBao|#ja!|`E|Wn8pLj-K~}utQI<&*s`T2;}Yi-d%s+ zts1_EU!xQNaDH(UOCvGI!no@<+zQ=PnAap`d8OS{W-`0MrEx(-Y?q?ivDq2mCA#ul zyD77>O+MFG+o_%A*LT?DKo>inwSoaZ1=u{n;lXc`DA+~X09n|wys46oTg`||8Ifmm zeb0hG?dm5Zh^SVAeg6&A+BxvQu}Ub2ostlvH)V< zt@~9Z6cw?o(JkJ`Iji0BuTn;6ja6^?9mT(ic4J*Hh+BU04qI;3M!U3vsH0C+S{=tE z$IxepKB+aYSj}q+e@Zq`<{{&t(h57eV28A{pMbe(NlDdkJE53IR)>n#AwlwpNlV3!VQoZO%MxsCHcErfn{y8Nxig$qt}5Oh9F=n>oJ_V#3^7 zhBR{z)xL&mUwok2aU`l8k)aC05bseQl~8 zd;x*LhiZoqnDb~8Ii+u z0#Jg`%SN^Hl&XDUs+}29wbO=bCw{7SkSnU4$5id~P1TOdh-zn0sCK4|H2Vm^;VP-U znY{!t@-ed6t7y|k1zeZMNbMBn&Z7s;o@_d(cJ>-jjQA-UCTXZLLHjxU48K}`Y*A%5EK9a diff --git a/midi/midiplayer.cpp b/midi/midiplayer.cpp index 497cfa6..6773fcc 100644 --- a/midi/midiplayer.cpp +++ b/midi/midiplayer.cpp @@ -48,12 +48,18 @@ static unsigned pwm_sd (const int input) { /******************************************************************/ /// Konstruktor -MidiPlayer::MidiPlayer() noexcept : OneWay() { +MidiPlayer::MidiPlayer() noexcept : OneWay(), led (LED_CFG), passcnt (0u) { index = 0; pause = 0; melody = scores[index++]; running = true; } +void MidiPlayer::pass() { + const bool b = passcnt & 0x10000; + led << b; + passcnt += 1u; +} + 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 @@ -69,11 +75,12 @@ unsigned MidiPlayer::Send (uint16_t * const ptr, const unsigned len) { return len; } void MidiPlayer::stop (void) { -//running = false; // cyklicky, furt +//running = false; // na konci každé melodie stop melody = scores[index++]; if (!melody) { - index = 0; - melody = scores[index++]; + index = 0; + melody = scores[index++]; + running = false; // test bez tlačítka } } void MidiPlayer::ToneChange (void) { diff --git a/midi/midiplayer.h b/midi/midiplayer.h index 60a1efc..7774756 100644 --- a/midi/midiplayer.h +++ b/midi/midiplayer.h @@ -10,8 +10,8 @@ class MidiPlayer : public OneWay { /// Konstruktor explicit MidiPlayer () noexcept; unsigned Send (uint16_t * const ptr, const unsigned len) override; - //bool send (uint16_t * ptr, const int len) override; - void stop (); + void stop (); + void pass (); protected: // Chráněné metody /// Obsluha tónu @@ -19,7 +19,8 @@ class MidiPlayer : public OneWay { /// Obsluha vzorku short nextSample (void); private: - //GpioClass but; + GpioClass led; + unsigned passcnt; volatile bool running; unsigned char const * melody; unsigned index; diff --git a/midi/pwmconfig.h b/midi/pwmconfig.h index 2ef2bb7..0fac579 100644 --- a/midi/pwmconfig.h +++ b/midi/pwmconfig.h @@ -4,4 +4,12 @@ static constexpr unsigned HALF_LEN = 0x80u; static constexpr unsigned MAXPWM = 2000u; +#ifdef __riscv +#define LED_CFG GPIOD,4 +#elif __arm__ +#define LED_CFG GpioPortA,0 +#else +#error "bad target" +#endif + #endif // CONFIG_H