Skip to content

Commit 22995a0

Browse files
committed
Compile test as its own
Remove the depedency of emu Makefile. Ready to move it out of target folder.
1 parent 804d51c commit 22995a0

9 files changed

Lines changed: 454 additions & 7 deletions

File tree

src/target/test/Makefile.inc

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,33 @@ FILESYSTEMS := common base_fonts 320x240x16
33
FONTS = filesystem/$(FILESYSTEM)/media/15normal.fon \
44
filesystem/$(FILESYSTEM)/media/23bold.fon
55
LANGUAGE := devo8
6-
CFLAGS += -DTEST --coverage -g -O0 -fPIC
7-
include target/common/emu/Makefile.inc
86

7+
CFLAGS += -DTEST --coverage -g -O0 -fPIC
98
ifndef BUILD_TARGET
10-
SRC_CXX =
11-
SRC_C += objs/test/AllTests.c
9+
10+
SRC_C = $(wildcard $(SDIR)/target/$(TARGET)/*.c) \
11+
$(wildcard $(SDIR)/target/common/filesystems/*.c)
12+
13+
ifdef USE_INTERNAL_FS
14+
SRC_C += $(wildcard $(SDIR)/target/common/filesystems/devofs/*.c) \
15+
$(wildcard $(SDIR)/target/common/filesystems/petit_fat/*.c)
16+
CFLAGS = -DEMULATOR=USE_INTERNAL_FS
1217
else
18+
CFLAGS = -DEMULATOR=USE_NATIVE_FS
19+
endif
20+
21+
CFLAGS += -I$(SDIR)/target/common/filesystems
22+
23+
ALL = $(TARGET).$(EXEEXT)
24+
25+
TYPE ?= dev
26+
27+
SRC_C += objs/test/AllTests.c
28+
29+
else #BUILD_TARGET
30+
CFLAGS += -DFILESYSTEM_DIR="\"filesystem/$(FILESYSTEM)\""
31+
1332
objs/test/AllTests.c: target/test/make-tests.sh tests/*.c
1433
sh target/test/make-tests.sh > $(ODIR)/AllTests.c
15-
endif
34+
35+
endif #BUILD_TARGET

src/target/test/channels.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
along with Deviation. If not, see <http://www.gnu.org/licenses/>.
1414
*/
1515
#include "common.h"
16-
#include "../common/emu/fltk.h"
16+
#include "emu.h"
1717
#include "mixer.h"
1818

1919
void TEST_CHAN_SetChannelValue(int channel, s32 value)

src/target/test/emu.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,66 @@
11
#ifndef _EMU_H_
22
#define _EMU_H_
33

4+
#include "gui/gui.h"
5+
46
#define LCD_WIDTH_MULT 1
57
#define LCD_HEIGHT_MULT 1
68
#define EMU_STRING "Unittest"
79
#endif
10+
11+
#ifndef PIXELS_PER_LOGICAL_X
12+
#define PIXELS_PER_LOGICAL_X 1
13+
#endif
14+
#ifndef PIXELS_PER_LOGICAL_Y
15+
#define PIXELS_PER_LOGICAL_Y 1
16+
#endif
17+
#if !defined ZOOM_X || !defined ZOOM_Y
18+
#define ZOOM_X 1
19+
#define ZOOM_Y 1
20+
#endif
21+
22+
#define IMAGE_X LCD_WIDTH * PIXELS_PER_LOGICAL_X
23+
#define IMAGE_Y LCD_HEIGHT * PIXELS_PER_LOGICAL_Y
24+
25+
#define SCREEN_X (IMAGE_X * ZOOM_X)
26+
#define SCREEN_Y (IMAGE_Y * ZOOM_Y)
27+
28+
#define SCREEN_RESIZE (IMAGE_X != SCREEN_X || IMAGE_Y != SCREEN_Y)
29+
30+
struct Gui {
31+
u16 xstart, xend, ystart, yend;
32+
u16 x, y;
33+
s8 dir;
34+
u32 buttons;
35+
int throttle;
36+
int rudder;
37+
int elevator;
38+
int aileron;
39+
int aux2;
40+
int aux3;
41+
int aux4;
42+
int aux5;
43+
int aux6;
44+
int aux7;
45+
int rud_dr;
46+
int ail_dr;
47+
int ele_dr;
48+
int dr; /* for emu_devo6 */
49+
int gear;
50+
int mix;
51+
int fmod;
52+
int hold;
53+
int trn;
54+
55+
u8 powerdown;
56+
u8 mouse;
57+
u16 mousex, mousey;
58+
u32 last_redraw;
59+
u8 image[IMAGE_X*IMAGE_Y*3];
60+
#if SCREEN_RESIZE
61+
u8 scaled_img[SCREEN_X*SCREEN_Y*3];
62+
#endif
63+
u8 init;
64+
} gui;
65+
66+

src/target/test/file.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
#include <string.h>
4+
#include <unistd.h>
5+
#include <dirent.h>
6+
7+
#include "common.h"
8+
9+
#if EMULATOR == USE_NATIVE_FS
10+
void SPIFlash_Init() {}
11+
void fempty(FILE *fh)
12+
{
13+
fseek(fh, 0, SEEK_END);
14+
long pos = ftell(fh);
15+
int fd = fileno(fh);
16+
ftruncate(fd, 0);
17+
ftruncate(fd, pos);
18+
fseek(fh, 0, SEEK_SET);
19+
}
20+
21+
int FS_Mount(void *FAT, const char *drive) {
22+
(void)FAT;
23+
(void)drive;
24+
printf("Changing directory to: '%s'\n", FILESYSTEM_DIR);
25+
return ! chdir(FILESYSTEM_DIR);
26+
}
27+
28+
static DIR *dh;
29+
int FS_OpenDir(const char *path)
30+
{
31+
dh = opendir(path);
32+
return (dh != NULL);
33+
}
34+
int FS_ReadDir(char *path)
35+
{
36+
struct dirent *dir = readdir(dh);
37+
if (! dir)
38+
return 0;
39+
strlcpy(path, dir->d_name, 13);
40+
return 1;
41+
}
42+
43+
void FS_CloseDir() {
44+
closedir(dh);
45+
}
46+
#endif //USE_NATIVE_FS

src/target/test/lcd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
#include "common.h"
17-
#include "../common/emu/fltk.h"
17+
#include "emu.h"
1818

1919
void LCD_DrawPixel(unsigned int color)
2020
{

src/target/test/protospi.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef _SPIPROTO_H_
2+
#define _SPIPROTO_H_
3+
4+
u8 PROTOSPI_read3wire();
5+
u8 PROTOSPI_xfer(u8 byte);
6+
#define PROTOSPI_pin_set(io) if(0) {}
7+
#define PROTOSPI_pin_clear(io) if(0) {}
8+
#define _NOP() if(0) {}
9+
10+
#define _SPI_CYRF_RESET_PIN {0, 0}
11+
#define _SPI_AVR_RESET_PIN {0, 0}
12+
#pragma weak A7105_Reset
13+
#pragma weak CC2500_Reset
14+
#pragma weak CYRF_Reset
15+
#endif // _SPIPROTO_H_

src/target/test/radio.c

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*
2+
This project is free software: you can redistribute it and/or modify
3+
it under the terms of the GNU General Public License as published by
4+
the Free Software Foundation, either version 3 of the License, or
5+
(at your option) any later version.
6+
7+
Deviation is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License
13+
along with Deviation. If not, see <http://www.gnu.org/licenses/>.
14+
*/
15+
16+
#include "common.h"
17+
#include "protocol/interface.h"
18+
#include "config/model.h"
19+
#include "config/tx.h"
20+
21+
#include <stdlib.h>
22+
23+
#define GPIOA 0xAAAAAAAA
24+
#define GPIOB 0xBBBBBBBB
25+
#define GPIOC 0xCCCCCCCC
26+
#define GPIOD 0xDDDDDDDD
27+
#define GPIOE 0xEEEEEEEE
28+
#define GPIOF 0xFFFFFFFF
29+
#define GPIOG 0xABCDEFAB
30+
void SPI_ProtoInit() {}
31+
void MCU_InitModules() {
32+
Transmitter.module_enable[CYRF6936].port = GPIOB;
33+
Transmitter.module_enable[CYRF6936].pin = 1 << 12;
34+
Transmitter.module_poweramp = 1;
35+
};
36+
int MCU_SetPin(struct mcu_pin *port, const char *name) {
37+
switch(name[0]) {
38+
case 'A':
39+
case 'a':
40+
port->port = GPIOA; break;
41+
case 'B':
42+
case 'b':
43+
port->port = GPIOB; break;
44+
case 'C':
45+
case 'c':
46+
port->port = GPIOC; break;
47+
case 'D':
48+
case 'd':
49+
port->port = GPIOD; break;
50+
case 'E':
51+
case 'e':
52+
port->port = GPIOE; break;
53+
case 'F':
54+
case 'f':
55+
port->port = GPIOF; break;
56+
case 'G':
57+
case 'g':
58+
port->port = GPIOG; break;
59+
case 'S':
60+
case 's':
61+
port->port = SWITCH_ADDRESS; break;
62+
default:
63+
if(strcasecmp(name, "None") == 0) {
64+
port->port = 0;
65+
port->pin = 0;
66+
return 1;
67+
}
68+
return 0;
69+
}
70+
if (port->port != SWITCH_ADDRESS) {
71+
int x = atoi(name+1);
72+
if (x > 15)
73+
return 0;
74+
port->pin = 1 << x;
75+
} else {
76+
port->pin = strtol(name+1,NULL, 16);
77+
}
78+
if(port == &Transmitter.module_enable[0]) {
79+
printf("Set CYRF6936 Enable: %s ", name);
80+
} else if(port == &Transmitter.module_enable[1]) {
81+
printf("Set A7105 Enable: %s ", name);
82+
} else if(port == &Transmitter.module_enable[2]) {
83+
printf("Set CC2500 Enable: %s ", name);
84+
} else if(port == &Transmitter.module_enable[3]) {
85+
printf("Set NRF24L01 Enable: %s ", name);
86+
} else {
87+
return 0;
88+
}
89+
printf("port: %08x pin: %04x\n", port->port, port->pin);
90+
return 1;
91+
}
92+
93+
const char *MCU_GetPinName(char *str, struct mcu_pin *port)
94+
{
95+
switch(port->port) {
96+
case GPIOA: str[0] = 'A'; break;
97+
case GPIOB: str[0] = 'B'; break;
98+
case GPIOC: str[0] = 'C'; break;
99+
case GPIOD: str[0] = 'D'; break;
100+
case GPIOE: str[0] = 'E'; break;
101+
case GPIOF: str[0] = 'F'; break;
102+
case GPIOG: str[0] = 'G'; break;
103+
default: return "None"; break;
104+
}
105+
for(int i = 0; i < 16; i++) {
106+
if(port->pin == (1uL << i)) {
107+
sprintf(str+1, "%d", i);
108+
return str;
109+
}
110+
}
111+
return "None";
112+
}
113+
114+
int SPI_ConfigSwitch(unsigned csn_high, unsigned csn_low) {
115+
(void)csn_high;
116+
(void)csn_low;
117+
return 1;
118+
}
119+
120+
int SPI_ProtoGetPinConfig(int module, int state) {
121+
(void)module;
122+
(void)state;
123+
return 0;
124+
}
125+
126+
u8 PROTOSPI_read3wire() { return 0x00; }
127+
128+
u8 PROTOSPI_xfer(u8 byte) { return byte; }
129+
130+
#ifdef PROTO_HAS_A7105
131+
int A7105_Reset() { return 1; }
132+
#endif
133+
134+
#ifdef PROTO_HAS_CC2500
135+
int CC2500_Reset() { return 1;}
136+
#endif //PROTO_HAS_CC2500
137+
/* CYRF */
138+
int CYRF_Reset() {return 1;}
139+
140+
void SPI_AVRProgramInit() {}
141+
void PWM_Initialize() {}
142+
void PWM_Stop() {}
143+
void PPM_Enable(unsigned low_time, volatile u16 *pulses) {
144+
int i;
145+
printf("PPM: low=%d ", (int)low_time);
146+
for(i = 0; pulses[i]; i++)
147+
printf("%04d ", pulses[i]);
148+
printf("\n");
149+
}

src/target/test/sound.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
*
3+
* This program uses the PortAudio Portable Audio Library.
4+
* For more information see: http://www.portaudio.com/
5+
* Copyright (c) 1999-2000 Ross Bencina and Phil Burk
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining
8+
* a copy of this software and associated documentation files
9+
* (the "Software"), to deal in the Software without restriction,
10+
* including without limitation the rights to use, copy, modify, merge,
11+
* publish, distribute, sublicense, and/or sell copies of the Software,
12+
* and to permit persons to whom the Software is furnished to do so,
13+
* subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be
16+
* included in all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
22+
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23+
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25+
*/
26+
#include <stdio.h>
27+
#include <math.h>
28+
#include "common.h"
29+
30+
#define SAMPLE_RATE (44100)
31+
#define FRAMES_PER_BUFFER (64)
32+
33+
#ifndef M_PI
34+
#define M_PI (3.14159265)
35+
#endif
36+
37+
#define TABLE_SIZE (250)
38+
39+
void SOUND_SetFrequency(unsigned freq, unsigned volume) {(void)freq; (void)volume;}
40+
void SOUND_Init() {}
41+
void SOUND_Start(unsigned msec, u16(*next_note_cb)(), u8 vibrate) {
42+
(void)msec;
43+
(void)next_note_cb;
44+
(void)vibrate;
45+
printf("beep\n");
46+
}
47+
void SOUND_StartWithoutVibrating(unsigned msec, u16(*next_note_cb)()) {
48+
(void)msec;
49+
(void)next_note_cb;
50+
printf("beep\n");
51+
}
52+
void SOUND_Stop() {}

0 commit comments

Comments
 (0)