Skip to content

Commit 1c34d80

Browse files
committed
Merge branch 'work-0200' of github.com:alvieboy/ZPUino into work-0200
2 parents 48c0c57 + 2c89827 commit 1c34d80

File tree

28 files changed

+3418
-7
lines changed

28 files changed

+3418
-7
lines changed

hardware/zpuino/zpu/libraries/VGA/examples/Bricks_Example/Bricks_Example.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void setup_pin_select() {
8383
void setup() {
8484

8585
//Uncomment this if you are using the pinselect variant
86-
//setup_pin_select();
86+
setup_pin_select();
8787

8888
/* For simulation, test only */
8989
clear();

hardware/zpuino/zpu/libraries/VGA/examples/Color_Bar/Color_Bar.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void setup_pin_select() {
7777
void setup() {
7878

7979
//Uncomment this if you are using the pinselect variant
80-
//setup_pin_select();
80+
setup_pin_select();
8181

8282
int width = VGA.getHSize();
8383
int height = VGA.getVSize();

hardware/zpuino/zpu/libraries/VGA/examples/Hello_World/Hello_World.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void setup_pin_select() {
7474
void setup() {
7575

7676
//Uncomment this if you are using the pinselect variant
77-
//setup_pin_select();
77+
setup_pin_select();
7878

7979
VGA.clear();
8080
VGA.setBackgroundColor(BLACK);

hardware/zpuino/zpu/libraries/VGA/examples/Load_Image/Load_Image.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void setup_pin_select() {
7575
void setup() {
7676

7777
//Uncomment this if you are using the pinselect variant
78-
//setup_pin_select();
78+
setup_pin_select();
7979

8080
VGA.clear();
8181

hardware/zpuino/zpu/libraries/VGALiquidCrystal/examples/LCD_Demo/LCD_Demo.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void setup_pin_select() {
7777
void setup() {
7878

7979
//Uncomment this if you are using the pinselect variant
80-
//setup_pin_select();
80+
setup_pin_select();
8181
VGA.clear();
8282

8383
// set up the LCD's number of columns and rows:

hardware/zpuino/zpu/libraries/VGALiquidCrystal/examples/spaceinvaders_image/spaceinvaders_image.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ void hd44780_draw()
459459
void setup() {
460460

461461
//Uncomment this if you are using the pinselect variant
462-
//setup_pin_select();
462+
setup_pin_select();
463463
VGA.clear();
464464

465465
//Background Image

hardware/zpuino/zpu/libraries/VGALiquidCrystal/examples/spaceinvaders_simple/spaceinvaders_simple.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ byte charSP12b[8] = {
420420
void setup() {
421421

422422
//Uncomment this if you are using the pinselect variant
423-
//setup_pin_select();
423+
setup_pin_select();
424424
VGA.clear();
425425
/* pinMode(AH7, OUTPUT); //Set contrast to GND
426426
digitalWrite(AH7, LOW); //Set contrast to GND
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#ifndef __LOGICSTART_H__
2+
#define __LOGICSTART_H__
3+
4+
#include <zpuino.h>
5+
6+
#define LS_ADC_SEL 0
7+
8+
#define LS_JOY_RIGHT 1
9+
#define LS_JOY_LEFT 2
10+
#define LS_JOY_DOWN 3
11+
#define LS_JOY_UP 4
12+
#define LS_JOY_SELECT 5
13+
14+
#define LS_SWITCH0 6
15+
#define LS_SWITCH1 7
16+
#define LS_SWITCH2 8
17+
#define LS_SWITCH3 9
18+
#define LS_SWITCH4 10
19+
#define LS_SWITCH5 11
20+
#define LS_SWITCH6 12
21+
#define LS_SWITCH7 13
22+
23+
#define LS_LED0 14
24+
#define LS_LED1 15
25+
#define LS_LED2 16
26+
#define LS_LED3 17
27+
#define LS_LED4 18
28+
#define LS_LED5 19
29+
#define LS_LED6 20
30+
#define LS_LED7 21
31+
32+
#define SEVENSEGBASE IO_SLOT(9)
33+
34+
#define SEGA 1
35+
#define SEGB 2
36+
#define SEGC 4
37+
#define SEGD 8
38+
#define SEGE 16
39+
#define SEGF 32
40+
#define SEGG 64
41+
42+
#define ADC_BITS 12
43+
44+
static inline void LS_setAllLeds(unsigned values)
45+
{
46+
values &= 0xFF;
47+
unsigned old = GPIODATA(0);
48+
old &= ~((0xFF)<<LS_LED0);
49+
old |= values<<LS_LED0;
50+
GPIODATA(0) = old;
51+
}
52+
53+
static inline unsigned LS_readAllSwitches()
54+
{
55+
return (GPIODATA(0) >> LS_SWITCH0) & 0xFF;
56+
}
57+
58+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
#include "LogicStart.h"
2+
#include <SmallFS.h>
3+
#include "VGAZX.h"
4+
#include "fixedpoint.h"
5+
#include "cbuffer.h"
6+
#include "ptplay.h"
7+
8+
#define USPIDATA16 *((&USPIDATA)+2)
9+
10+
static SmallFSFile modfile;
11+
static char buf[128];
12+
static pt_mod_s * mod;
13+
static CircularBuffer<unsigned,7> audioBuffer;
14+
15+
extern pt_mod_s *pt_init_smallfs(SmallFSFile &file);
16+
17+
static int timeout=0;
18+
19+
void _zpu_interrupt()
20+
{
21+
// Play
22+
if (audioBuffer.hasData()) {
23+
unsigned v = audioBuffer.pop();
24+
SIGMADELTADATA = v;
25+
}
26+
if (timeout!=0)
27+
timeout--;
28+
TMR0CTL &= ~(BIT(TCTLIF));
29+
}
30+
31+
void setup()
32+
{
33+
LS_setAllLeds(0);
34+
digitalWrite(LS_ADC_SEL, 0);
35+
VGAZX.begin();
36+
SmallFS.begin();
37+
38+
SmallFSFile f = SmallFS.open("scr1");
39+
if (f.valid())
40+
VGAZX.loadscr(f);
41+
42+
Serial.begin(115200);
43+
44+
modfile = SmallFS.open("music.mod");
45+
46+
mod = pt_init_smallfs(modfile);
47+
SIGMADELTACTL=0x3;
48+
TMR0CTL = 0;
49+
TMR0CNT = 0;
50+
TMR0CMP = ((CLK_FREQ/2) / FREQ )- 1;
51+
TMR0CTL = _BV(TCTLENA)|_BV(TCTLCCM)|_BV(TCTLDIR)|
52+
_BV(TCTLCP0) | _BV(TCTLIEN);
53+
54+
INTRMASK = BIT(INTRLINE_TIMER0); // Enable Timer0 interrupt
55+
56+
USPICTL=BIT(SPICPOL)|BIT(SPISRE)|BIT(SPIEN)|BIT(SPIBLOCK)|BIT(SPICP2)|BIT(SPICP0);
57+
58+
INTRCTL=1;
59+
60+
61+
}
62+
63+
static unsigned char table7seg[16] =
64+
{
65+
0x3F, //00111111, 0
66+
0x06, //00000110, 1
67+
0x5B, //01011011 2
68+
0x4F, //01001111 3
69+
0x66, //01100110 4
70+
0x6D, //01101101 5
71+
0x7D, //01111101 6
72+
0x07, //00000111 7
73+
0x7F, //01111111 8
74+
0x6F, //01101111 9
75+
0x00,
76+
0x00,
77+
0x00,
78+
0x00,
79+
0x00,
80+
0x00
81+
};
82+
83+
static int int_to_7seg(int v)
84+
{
85+
return table7seg[v%16];
86+
}
87+
88+
int cnt = 0;
89+
int extcnt = 0;
90+
int mode = 0;
91+
unsigned channel=0;
92+
93+
static void set_sevenseg_value(int v, unsigned bindots)
94+
{
95+
REGISTER( SEVENSEGBASE, 7 ) = int_to_7seg(v%10) | (bindots&8 ? 0x80:0x00);
96+
REGISTER( SEVENSEGBASE, 6 ) = int_to_7seg((v/10)%10) | (bindots&4 ? 0x80:0x00);
97+
REGISTER( SEVENSEGBASE, 5 ) = int_to_7seg((v/100)%10) | (bindots&2 ? 0x80:0x00);
98+
REGISTER( SEVENSEGBASE, 4 ) = int_to_7seg((v/1000)%10) | (bindots&1 ? 0x80:0x00);
99+
}
100+
101+
static void test()
102+
{
103+
REGISTER( SEVENSEGBASE, 7 ) = int_to_7seg(channel);
104+
REGISTER( SEVENSEGBASE, 6 ) = 0;
105+
REGISTER( SEVENSEGBASE, 5 ) = SEGF|SEGE|SEGB|SEGC|SEGG;
106+
REGISTER( SEVENSEGBASE, 4 ) = SEGA|SEGF|SEGE|SEGD;
107+
}
108+
109+
static void hello()
110+
{
111+
REGISTER( SEVENSEGBASE, 7 ) = SEGA|SEGF|SEGB|SEGE|SEGC|SEGD;
112+
REGISTER( SEVENSEGBASE, 6 ) = SEGF|SEGE|SEGD;
113+
REGISTER( SEVENSEGBASE, 5 ) = SEGA|SEGF|SEGE|SEGD|SEGG;
114+
REGISTER( SEVENSEGBASE, 4 ) = SEGF|SEGE|SEGB|SEGC|SEGG;
115+
}
116+
117+
118+
void loop()
119+
{
120+
unsigned char lpwm;
121+
unsigned switches = LS_readAllSwitches();
122+
unsigned adcvalue = USPIDATA16;
123+
int i;
124+
const fp32_16_16 adcv = 5000;
125+
126+
if ((extcnt & 0x17) == 0) {
127+
adcvalue &= 0xffff;
128+
adcvalue <<= 4;
129+
adcvalue += ((1<<4)-1);
130+
131+
if (adcvalue>0x10000)
132+
adcvalue=0x10000;
133+
134+
adcvalue &= 0x1ffff;
135+
136+
fp32_16_16 adcf(adcvalue,1);
137+
adcf *= adcv;
138+
139+
adcvalue = adcf.asInt();
140+
141+
142+
lpwm = 0xf - (switches& 0xf);
143+
144+
LS_setAllLeds(switches);
145+
146+
REGISTER( SEVENSEGBASE, 0 ) = 0xF | (lpwm<<16);
147+
148+
if (!digitalRead(LS_JOY_SELECT)) {
149+
hello();
150+
} else {
151+
if (timeout==0) {
152+
if (mode==0) {
153+
if ((cnt & 0x3F)==0)
154+
set_sevenseg_value(adcvalue,1);
155+
} else {
156+
set_sevenseg_value(cnt,1);
157+
}
158+
}
159+
}
160+
161+
USPIDATA16 = channel<<(8+3);
162+
163+
/* Check for mode change */
164+
if (!digitalRead(LS_JOY_LEFT))
165+
mode=0;
166+
else if (!digitalRead(LS_JOY_RIGHT))
167+
mode=1;
168+
169+
if (timeout==0) {
170+
if (!digitalRead(LS_JOY_UP)) {
171+
if (channel<7)
172+
channel++;
173+
/* Print something and add timeout */
174+
timeout = 17000;
175+
test();
176+
} else if (!digitalRead(LS_JOY_DOWN)) {
177+
if (channel!=0)
178+
channel--;
179+
timeout = 17000;
180+
test();
181+
}
182+
}
183+
184+
cnt++;
185+
}
186+
extcnt++;
187+
188+
pt_render(modfile, mod, buf, NULL, 2, 16 /* Samples */, 1, 16, 1);
189+
for (i=0;i<32;i+=2) {
190+
unsigned v = buf[i];
191+
v += buf[i+1]<<8;
192+
//v += buf[i]<<16;
193+
//v += buf[i+1]<<24;
194+
v+=0x8000;
195+
196+
while (audioBuffer.isFull());
197+
audioBuffer.push(v);
198+
}
199+
}

0 commit comments

Comments
 (0)