From 08438dd6b611fe65b6acbf2fcb7e65a650e0b2f6 Mon Sep 17 00:00:00 2001 From: flo Date: Sat, 25 Feb 2017 17:22:24 +0100 Subject: [PATCH] libs --- include/sound4calc.h | 3 ++- src/main.c | 26 ++++---------------------- src/sound4calc.c | 31 ++++++++++++++++++++++++++++--- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/include/sound4calc.h b/include/sound4calc.h index adbe13a..dee04af 100644 --- a/include/sound4calc.h +++ b/include/sound4calc.h @@ -18,7 +18,8 @@ #define SH7337_PGDR 0xA400012C #define SH7337_SCPDR 0xA4000136 -void SwitchPinState(); +void SwitchPinState(char level); +void PlayNote(); void InitPorts(); #endif diff --git a/src/main.c b/src/main.c index d959573..8d1ddcd 100644 --- a/src/main.c +++ b/src/main.c @@ -9,31 +9,13 @@ unsigned char bincod[25] = {0}; unsigned char place = 0; - -static struct { - int freq; - int length_ms; -} seq[] = { - { 352, 500 }, - { 412, 375 }, - { 352, 250 }, - { 352, 125 }, - { 475, 250 }, - { 352, 250 }, - { 316, 250 }, - { -1, -1 }, - }; - +unsigned char range = 0; void lect() { - static unsigned char range = 0; - - if(bincod[range%place] != bincod[(range+1)%place]) - { - SwitchPinState(); - } - range++; + SwitchPinState(bincod[range]=='-'); + range++; + if(!(bincod[range])) range=0; } int main(void) diff --git a/src/sound4calc.c b/src/sound4calc.c index 651ea22..47966a0 100644 --- a/src/sound4calc.c +++ b/src/sound4calc.c @@ -1,18 +1,43 @@ #include "sound4calc.h" #include // from Gint +#include //from Gint -void SwitchPinState() +unsigned char* signal = {"----_____"}; + +/* + SwitchPinState() + put the pin at the level +*/ +void SwitchPinState(char level) { +level = !!level; + if(isSH3()) { - *(volatile unsigned char*)SH7337_SCPDR ^= 0x01; + *(volatile unsigned char*)SH7337_SCPDR = (*(volatile unsigned char*)SH7337_SCPDR & 0xFE) | level ; } else { - *(volatile unsigned char*)SH7305_PJDR ^= 0x04; + *(volatile unsigned char*)SH7305_PJDR = (*(volatile unsigned char*)SH7305_PJDR & 0xF3) | (0x1<<(2+level)); } } +/* + PlayNote() + allow to make different waveforms with '-' and '_' +*/ +void PlayNote() +{ +static x = 0; +SwitchPinState(signal[x]=='-'); +x = x + 1; +if(!(signal[x])) x = 0; +} + +/* + InitPorts(); + Init ports to output +*/ void InitPorts() { if(isSH3())