Skip to content

Commit

Permalink
All major features are now gated by CONFIG preprocessor directives, s…
Browse files Browse the repository at this point in the history
…o we can disable their symbol requirements when porting to a new target. #181
  • Loading branch information
travisgoodspeed committed Jul 19, 2016
1 parent 12eccb4 commit d98cd53
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 20 deletions.
8 changes: 4 additions & 4 deletions applet/Makefile.s13.020
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#SRCS = main.o usb.o gfx.o dmr.o printf.o dmesg.o stm32f4xx_it.o system_stm32f4xx.o
#SRCS += os.o menu.o aes.o ambe.o spiflash.o usersdb.o addl_config.o beep_process.o
#SRCS += rtc_timer.o i2c.o display.o
SRCS = main.o usb.o gfx.o dmr.o printf.o dmesg.o stm32f4xx_it.o system_stm32f4xx.o
SRCS += os.o menu.o aes.o ambe.o spiflash.o usersdb.o addl_config.o beep_process.o
SRCS += rtc_timer.o i2c.o display.o

#Minimal set
SRCS = main.o usb.o stm32f4xx_it.o system_stm32f4xx.o printf.o dmesg.o
#SRCS = main.o usb.o stm32f4xx_it.o system_stm32f4xx.o printf.o dmesg.o
PROJ_NAME=main


Expand Down
4 changes: 4 additions & 0 deletions applet/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#define CONFIG_SPIFLASH
#define CONFIG_GRAPHICS
#define CONFIG_SPIC5000
#define CONFIG_AMBE
#define CONFIG_DMR
#define CONFIG_MENU
#define CONFIG_AES


/* Uncomment this to print AMBE frames for decoding with DSD. You
Expand Down
2 changes: 2 additions & 0 deletions applet/src/addl_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,7 @@ void init_global_addl_config_struct() {
void init_global_addl_config_hook(void) {
init_global_addl_config_struct();

#ifdef CONFIG_MENU
md380_create_main_meny_entry();
#endif
}
2 changes: 2 additions & 0 deletions applet/src/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const char* getmotorolabasickey(int i){
might (or might not) be related to the ALPU-MP chip.
*/
void aes_startup_check_hook(){
#ifdef CONFIG_AES
printf("Performing AES startup check.\n");
//Call back to the original function.
int *toret=aes_startup_check();
Expand All @@ -121,6 +122,7 @@ void aes_startup_check_hook(){
//Force the correct value.
*((char*)0x2001d39b)=0x42;
}
#endif //CONFIG_AES
}

/* This hook intercepts calls to aes_loadkey(), so that AES keys can
Expand Down
16 changes: 11 additions & 5 deletions applet/src/ambe.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ uint32_t ambe_encode_frame_cnt;

int ambe_encode_thing_hook(char *a1, int a2, int *a3, int a4,
short a5, short a6, short a7, int a8){

#ifdef CONFIG_AMBE
short *s8;
int i=0;
int max=0;
Expand All @@ -40,6 +40,9 @@ int ambe_encode_thing_hook(char *a1, int a2, int *a3, int a4,
ambe_encode_frame_cnt++;
return ambe_encode_thing(a1,a2,a3,a4,
a5,a6,a7,a8);
#else
return 0xdeadbeef;
#endif
}


Expand All @@ -65,8 +68,9 @@ int ambe_unpack_hook(int a1, int a2, char length, int a4){
md380_putc(NULL,'\n');
#endif //AMBECORRECTEDPRINT

#ifdef CONFIG_AMBE
ambe_unpack(a1,a2,length,a4);
#endif //CONFIG_AMBE

/* Dump the new, uncorrected AMBE frame. Bits won't make sense
until after decoding. */
Expand Down Expand Up @@ -117,10 +121,12 @@ int ambe_decode_wav_hook(int *a1, signed int eighty, char *bitbuffer,
OS_EXIT_CRITICAL(ambestate);
#endif //AMBEPRINT


int toret=0xdeadbeef;
#ifdef CONFIG_AMBE
//First we call the original function.
int toret=ambe_decode_wav(a1, eighty, bitbuffer,
a4, a5, a6, a7);
toret=ambe_decode_wav(a1, eighty, bitbuffer,
a4, a5, a6, a7);
#endif

/* Print the parameters
printf("ambe_decode_wav(0x%08x, %d, 0x%08x,\n"
Expand Down
8 changes: 4 additions & 4 deletions applet/src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
// workaround flipped display phenomenon

void display_init_hook_1(void) { // from 0x8033586 @ D003.020
#ifdef CONFIG_GRAPHICS
if ( md380_radio_config[0x1d] & 1) // offset 0x1d from
// 0x08033586 @ D003.020
Write_Data_2display(0x48); // md390, no gps, config
else
Write_Data_2display(0x8); // orginal MD380
#endif
}

void display_init_hook_2(void) {
#ifdef CONFIG_GRAPHICS
if ( md380_radio_config[0x1d] & 1)
Write_Data_2display(0x4f);
else
Write_Data_2display(0x40);
#endif
}





12 changes: 12 additions & 0 deletions applet/src/dmr.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ void *dmr_call_start_hook(char *pkt){


void dmr_apply_squelch_hook(OS_EVENT *event, char * mode){
#ifdef CONFIG_DMR
/* The *mode byte is 0x09 for an unmuted call and 0x08 for a muted
call.
*/
Expand All @@ -149,9 +150,11 @@ void dmr_apply_squelch_hook(OS_EVENT *event, char * mode){
do. --Travis
*/
md380_OSMboxPost(event, mode);
#endif
}

void dmr_apply_privsquelch_hook(OS_EVENT *event, char *mode){
#ifdef CONFIG_DMR
/* The *mode byte is 0x09 for an unmuted call and 0x08 for a muted
call.
*/
Expand All @@ -165,10 +168,12 @@ void dmr_apply_privsquelch_hook(OS_EVENT *event, char *mode){
dmr_before_squelch();
}
md380_OSMboxPost(event, mode);
#endif
}


void *dmr_handle_data_hook(char *pkt, int len){
#ifdef CONFIG_DMR
/* This hook handles the dmr_contact_check() function, calling
back to the original function where appropriate.
Expand All @@ -185,10 +190,14 @@ void *dmr_handle_data_hook(char *pkt, int len){

//Forward to the original function.
return dmr_handle_data(pkt,len);
#else
return 0xdeadbeef;
#endif
}


void *dmr_sms_arrive_hook(void *pkt){
#ifdef CONFIG_DMR
/* This hooks the SMS arrival routine, but as best I can tell,
dmr_sms_arrive() only handles the header and not the actual
data payload, which is managed by dmr_handle_data() in each
Expand Down Expand Up @@ -222,4 +231,7 @@ SMS header: 08 6a 02 40 00 00 63 30 05 54 88 00 83 0c

//Forward to the original function.
return dmr_sms_arrive(pkt);
#else
return 0xdeadbeef;
#endif
}
13 changes: 11 additions & 2 deletions applet/src/gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ const gfx_bitmap bmp_eye = { 12, 12, 6, 4, eye_pix, &eye_pal, 0};
//! Draws text at an address by calling back to the MD380 function.
void drawtext(wchar_t *text,
int x, int y){
#ifdef CONFIG_GRAPHICS
gfx_drawtext(text,
0,0,
x,y,
15); //strlen(text));
#endif
}
//! Draws text at an address by calling back to the MD380 function.
void drawascii(char *ascii,
Expand All @@ -48,11 +50,13 @@ void drawascii(char *ascii,
for(int i=0;i<15;i++)
wide[i]=ascii[i];

#ifdef CONFIG_GRAPHICS
//Draw the wide string, not the original.
gfx_drawtext(wide,
0,0,
x,y,
15); //strlen(text));
#endif
}

void drawascii2(char *ascii,
Expand All @@ -65,7 +69,9 @@ void drawascii2(char *ascii,
if (ascii[i]=='\0')
break;
}
#ifdef CONFIG_GRAPHICS
gfx_drawtext2(wide, x, y, 0);
#endif
}

void green_led(int on) {
Expand Down Expand Up @@ -99,6 +105,7 @@ void lcd_background_led(int on) {


void print_date_hook(void) { // copy from the md380 code
#ifdef CONFIG_GRAPHICS
wchar_t wide[40];
RTC_DateTypeDef RTC_DateStruct;
md380_RTC_GetDate(RTC_Format_BCD, &RTC_DateStruct);
Expand All @@ -124,12 +131,14 @@ void print_date_hook(void) { // copy from the md380 code


// gfx_drawbmp((char *) &bmp_eye, 20, 2);

#endif //CONFIG_GRAPHICS
}

void print_ant_sym_hook(char *bmp, int x, int y) {
#ifdef CONFIG_GRAPHICS
gfx_drawbmp(bmp, x, y);
if(global_addl_config.promtg==1) {
gfx_drawbmp((char *) &bmp_eye, 65, 1);
}
}
#endif
}
1 change: 1 addition & 0 deletions applet/src/md380.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <stdio.h>
#include <stdint.h>

#include "config.h"
#include "os.h"
#include "peripherals/stm32f4xx_rtc.h"

Expand Down
Loading

0 comments on commit d98cd53

Please sign in to comment.