Merge branch 'master' of github.com:r0ket/r0ket
This commit is contained in:
commit
c01a8e7e82
|
@ -7,6 +7,7 @@
|
|||
#include "lcd/allfonts.h"
|
||||
|
||||
#include "filesystem/ff.h"
|
||||
#include "filesystem/select.h"
|
||||
#include "funk/nrf24l01p.h"
|
||||
#include "usb/usbmsc.h"
|
||||
|
||||
|
@ -75,35 +76,22 @@ void f_init(void){
|
|||
lcdPrintln("Done.");
|
||||
};
|
||||
|
||||
|
||||
static FONT fonts[] = {
|
||||
&Font_7x8,
|
||||
&Font_Ubuntu18pt,
|
||||
&Font_Ubuntu29pt,
|
||||
&Font_Ubuntu36pt,
|
||||
&Font_Orbitron14pt,
|
||||
&Font_3x6,
|
||||
&Font_5x8,
|
||||
&Font_8x8,
|
||||
&Font_8x8Thin,
|
||||
&Font_Invaders
|
||||
};
|
||||
|
||||
char fontname[15];
|
||||
|
||||
void f_nick(void){
|
||||
static char ctr=0;
|
||||
char key;
|
||||
signed char x=10;
|
||||
signed char y=10;
|
||||
static signed char x=10;
|
||||
static signed char y=10;
|
||||
while (1) {
|
||||
lcdClear();
|
||||
lcdFill(255);
|
||||
|
||||
font=fonts[ctr%10];
|
||||
DoString(x,y,nickname);
|
||||
// lcdSafeSetPixel(x,y,1);
|
||||
setExtFont(fontname);
|
||||
|
||||
font=&Font_7x8;
|
||||
DoString(x,y,nickname);
|
||||
|
||||
setIntFont(&Font_7x8);
|
||||
lcdSetCrsr(50,50);
|
||||
lcdPrintInt(x);
|
||||
lcdPrint("x");
|
||||
|
@ -135,6 +123,23 @@ void f_nick(void){
|
|||
};
|
||||
};
|
||||
|
||||
void f_font(void){
|
||||
|
||||
if( selectFile(fontname,"F0N") != 0){
|
||||
lcdPrintln("No file selected.");
|
||||
return;
|
||||
};
|
||||
|
||||
lcdClear();
|
||||
lcdPrintln(fontname);
|
||||
setExtFont(fontname);
|
||||
lcdPrintln("PUabc€");
|
||||
setIntFont(&Font_7x8);
|
||||
lcdPrintln("done.");
|
||||
lcdDisplay();
|
||||
while(!getInputRaw())delayms(10);
|
||||
};
|
||||
|
||||
/***********************************************************************/
|
||||
|
||||
void gotoISP(void) {
|
||||
|
@ -178,7 +183,7 @@ void msc_menu(void){
|
|||
const struct MENU_DEF menu_ISP = {"Invoke ISP", &gotoISP};
|
||||
const struct MENU_DEF menu_init = {"F Init", &f_init};
|
||||
const struct MENU_DEF menu_nick = {"F Nick", &f_nick};
|
||||
//const struct MENU_DEF menu_snd = {"F Send", &f_send};
|
||||
const struct MENU_DEF menu_font = {"F sel", &f_font};
|
||||
const struct MENU_DEF menu_mirror = {"Mirror", &lcd_mirror};
|
||||
const struct MENU_DEF menu_invert = {"Invert", &lcd_invert};
|
||||
const struct MENU_DEF menu_volt = {"Akku", &adc_check};
|
||||
|
@ -188,7 +193,7 @@ const struct MENU_DEF menu_nop = {"---", NULL};
|
|||
static menuentry menu[] = {
|
||||
&menu_init,
|
||||
&menu_nick,
|
||||
// &menu_snd,
|
||||
&menu_font,
|
||||
&menu_nop,
|
||||
&menu_mirror,
|
||||
&menu_invert,
|
||||
|
|
|
@ -227,7 +227,7 @@ void main_funk(void) {
|
|||
backlightInit();
|
||||
font=&Font_7x8;
|
||||
|
||||
openbeaconSetup(0x5ec);
|
||||
openbeaconSetup();
|
||||
while (1) {
|
||||
lcdFill(0); // clear display buffer
|
||||
lcdDisplay();
|
||||
|
|
|
@ -58,7 +58,6 @@ int receiveKey(uint8_t type, uint8_t *x, uint8_t *y)
|
|||
uint8_t n;
|
||||
|
||||
n = nrf_rcv_pkt_time(1000, 32, buf);
|
||||
lcdPrint("pkt:"); lcdPrintInt(n);lcdPrintln(""); lcdRefresh();
|
||||
if( n == 32 && buf[0] == type && buf[1] == 'X' ){
|
||||
for(int i=0; i<NUMWORDS*4; i++)
|
||||
x[i] = buf[i+2];
|
||||
|
@ -116,7 +115,7 @@ int sendKeys(void)
|
|||
char key;
|
||||
while( !done ){
|
||||
lcdClear();
|
||||
lcdPrintln("Sending key");lcdRefresh();
|
||||
lcdPrintln("Sending PUBKEY");lcdRefresh();
|
||||
sendPublicKey(Px,Py);
|
||||
sendMac();
|
||||
lcdPrintln("Done");
|
||||
|
@ -146,7 +145,7 @@ int receiveKeys(uint8_t *px, uint8_t *py, uint8_t *mac)
|
|||
char key;
|
||||
while( !done ){
|
||||
lcdClear();
|
||||
lcdPrintln("Receiving key");
|
||||
lcdPrintln("Recv. PUBKEY");
|
||||
lcdPrintln("Down=Abort");
|
||||
lcdRefresh();
|
||||
key = getInput();
|
||||
|
@ -156,11 +155,11 @@ int receiveKeys(uint8_t *px, uint8_t *py, uint8_t *mac)
|
|||
}
|
||||
if( receivePublicKey(px,py) )
|
||||
continue;
|
||||
lcdPrintln("Got PUBKEY");
|
||||
lcdRefresh();
|
||||
if( receiveMac(mac) )
|
||||
continue;
|
||||
lcdPrintln("Done");
|
||||
lcdClear();
|
||||
lcdPrintln("Got PUBKEY"); lcdRefresh();
|
||||
lcdPrintln("Hash:");
|
||||
lcdPrintln("Right=OK");
|
||||
lcdPrintln("Left=Retry");
|
||||
lcdPrintln("Down=Abort");
|
||||
|
@ -203,27 +202,16 @@ void receiveFile(void)
|
|||
}
|
||||
if( receiveR(rx,ry) )
|
||||
continue;
|
||||
lcdPrintln("Got R");
|
||||
lcdPrintln("Creating key");
|
||||
lcdRefresh();
|
||||
ECIES_decryptkeygen(rx, ry, k1, k2, Priv);
|
||||
#if 0
|
||||
lcdClear();
|
||||
for(int i=0; i<16; i++){
|
||||
lcdPrintCharHex(k1[i]);
|
||||
if((i+1)%4==0)
|
||||
lcdPrintln("");
|
||||
}
|
||||
lcdRefresh();
|
||||
#else
|
||||
uint32_t k[4] = {0xffff,0xffff,0xffff,0xffff};
|
||||
if( filetransfer_receive(mac,(uint32_t*)k) )
|
||||
if( filetransfer_receive(mac,(uint32_t*)k1) < 0 )
|
||||
continue;
|
||||
lcdPrintln("Done");
|
||||
lcdPrintln("Right=OK");
|
||||
lcdPrintln("Left=Retry");
|
||||
lcdPrintln("Down=Abort");
|
||||
lcdRefresh();
|
||||
#endif
|
||||
|
||||
while(1){
|
||||
key = getInput();
|
||||
delayms(20);
|
||||
|
@ -237,7 +225,6 @@ void receiveFile(void)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void sendFile(char *filename)
|
||||
|
@ -252,31 +239,20 @@ void sendFile(char *filename)
|
|||
uint8_t key;
|
||||
|
||||
uint8_t k1[16], k2[16], rx[4*NUMWORDS], ry[4*NUMWORDS];
|
||||
|
||||
lcdClear();
|
||||
lcdPrintln("Creating key"); lcdRefresh();
|
||||
ECIES_encyptkeygen(px, py, k1, k2, rx, ry);
|
||||
|
||||
while( !done ){
|
||||
lcdClear();
|
||||
lcdPrintln("Sending file");lcdRefresh();
|
||||
sendR(rx,ry);
|
||||
lcdPrintln("Sent R");
|
||||
lcdRefresh();
|
||||
#if 0
|
||||
lcdClear();
|
||||
for(int i=0; i<16; i++){
|
||||
lcdPrintCharHex(k1[i]);
|
||||
if((i+1)%4==0)
|
||||
lcdPrintln("");
|
||||
}
|
||||
#else
|
||||
delayms(3000);
|
||||
uint32_t k[4] = {0xffff,0xffff,0xffff,0xffff};
|
||||
filetransfer_send((uint8_t*)filename, 0, mac, (uint32_t*)k);
|
||||
filetransfer_send((uint8_t*)filename, 0, mac, (uint32_t*)k1);
|
||||
lcdPrintln("Done");
|
||||
lcdPrintln("Right=OK");
|
||||
lcdPrintln("Left=Retry");
|
||||
#endif
|
||||
lcdRefresh();
|
||||
|
||||
while(1){
|
||||
key = getInput();
|
||||
delayms(20);
|
||||
|
@ -287,6 +263,7 @@ void sendFile(char *filename)
|
|||
break;
|
||||
}
|
||||
}
|
||||
lcdClear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -307,45 +284,25 @@ void main_vcard(void) {
|
|||
while (1) {
|
||||
key= getInput();
|
||||
delayms(20);
|
||||
|
||||
// Easy flashing
|
||||
if(key==BTN_LEFT){
|
||||
DoString(0,8,"Enter ISP!");
|
||||
lcdDisplay();
|
||||
ISPandReset();
|
||||
}else if(key==BTN_UP){
|
||||
//lcdClear();
|
||||
//lcdPrintln("Generating...");
|
||||
//lcdRefresh();
|
||||
char file[13];
|
||||
selectFile(file,"TXT");
|
||||
sendFile(file);
|
||||
//uint8_t k1[16], k2[16], Rx[4*NUMWORDS], Ry[4*NUMWORDS];
|
||||
//ECIES_encyptkeygen("1c56d302cf642a8e1ba4b48cc4fbe2845ee32dce7",
|
||||
// "45f46eb303edf2e62f74bd68368d979e265ee3c03",
|
||||
// k1, k2, Rx, Ry);
|
||||
//nrf_snd_pkt_crc(30, k1);
|
||||
lcdPrintln("Done");
|
||||
lcdRefresh();
|
||||
}else if(key==BTN_DOWN){
|
||||
lcdClear();
|
||||
lcdPrintln("Generating...");
|
||||
lcdRefresh();
|
||||
receiveFile();
|
||||
//uint8_t k1[16], k2[16], Rx[4*NUMWORDS], Ry[4*NUMWORDS];
|
||||
//ECIES_encyptkeygen("1c56d302cf642a8e1ba4b48cc4fbe2845ee32dce7",
|
||||
// "45f46eb303edf2e62f74bd68368d979e265ee3c03",
|
||||
// k1, k2, Rx, Ry);
|
||||
//nrf_snd_pkt_crc(30, k1);
|
||||
lcdPrintln("Done");
|
||||
lcdRefresh();
|
||||
}else if(key==BTN_RIGHT){
|
||||
DoString(0,8,"MSC Enabled.");
|
||||
lcdDisplay();
|
||||
usbMSCInit();
|
||||
while(!getInputRaw())delayms(10);
|
||||
DoString(0,16,"MSC Disabled.");
|
||||
usbMSCOff();
|
||||
}
|
||||
|
||||
//encryption_decryption_demo("This is encrypted",
|
||||
// "1c56d302cf642a8e1ba4b48cc4fbe2845ee32dce7",
|
||||
// "45f46eb303edf2e62f74bd68368d979e265ee3c03",
|
||||
// "0e10e787036941e6c78daf8a0e8e1dbfac68e26d2");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -126,12 +126,7 @@ void rbInit() {
|
|||
gpioIntEnable(RB_BUSINT);
|
||||
// add this to catch interrupt:
|
||||
/*
|
||||
void PIOINT3_IRQHandler(void) {
|
||||
if (gpioIntStatus(RB_BUSINT)) {
|
||||
// do something
|
||||
gpioIntClear(RB_BUSINT);
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
//nrf_init();
|
||||
|
@ -139,3 +134,17 @@ void rbInit() {
|
|||
font=&Font_7x8;
|
||||
ECIES_setup();
|
||||
}
|
||||
#define WEAK_ALIAS(f) __attribute__ ((weak, alias (#f)));
|
||||
void interrupt_undefined(void) {
|
||||
}
|
||||
|
||||
void businterrupt(void) WEAK_ALIAS(interrupt_undefined);
|
||||
|
||||
|
||||
void PIOINT3_IRQHandler(void) {
|
||||
if (gpioIntStatus(RB_BUSINT)) {
|
||||
gpioIntClear(RB_BUSINT);
|
||||
businterrupt();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -172,5 +172,4 @@ struct MENU {
|
|||
|
||||
|
||||
void handleMenu(const struct MENU *the_menu);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,14 +1,24 @@
|
|||
#include "lpc134x.h"
|
||||
#include "sysdefs.h"
|
||||
#include "basic.h"
|
||||
#include "xxtea.h"
|
||||
|
||||
#include "core/iap/iap.h"
|
||||
|
||||
uint32_t GetUUID32(void){
|
||||
IAP_return_t iap_return;
|
||||
iap_return = iapReadSerialNumber();
|
||||
|
||||
return iap_return.Result[1];
|
||||
if (iap_return.ReturnCode == 0){
|
||||
uint32_t block[4];
|
||||
uint32_t k[4] = {1,2,3,4};
|
||||
block[0] = iap_return.Result[0];
|
||||
block[1] = iap_return.Result[1];
|
||||
block[2] = iap_return.Result[2];
|
||||
block[3] = iap_return.Result[3];
|
||||
xxtea_encode_words(block, 4, k);
|
||||
return block[0];
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
// What OpenBeacon used. Do we want this?
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef _UUID_H_
|
||||
#define _UUID_H_
|
||||
#include <stdint.h>
|
||||
|
||||
uint32_t GetUUID32(void);
|
||||
|
||||
#endif
|
||||
|
|
@ -17,6 +17,7 @@ int filetransfer_send(uint8_t *filename, uint16_t size,
|
|||
FRESULT res;
|
||||
UINT readbytes;
|
||||
|
||||
|
||||
if( size > MAXSIZE )
|
||||
return 1; //File to big
|
||||
|
||||
|
@ -25,6 +26,9 @@ int filetransfer_send(uint8_t *filename, uint16_t size,
|
|||
return res;
|
||||
|
||||
//res = f_read(&file, (char *)buf, size, &readbytes);
|
||||
for(uint16_t i=0; i<MAXSIZE; i++)
|
||||
buf[i] = 0;
|
||||
|
||||
res = f_read(&file, (char *)buf, MAXSIZE, &readbytes);
|
||||
size = readbytes;
|
||||
|
||||
|
@ -59,6 +63,7 @@ int filetransfer_receive(uint8_t *mac, uint32_t const k[4])
|
|||
{
|
||||
uint8_t buf[MAXSIZE+1];
|
||||
uint16_t size;
|
||||
uint8_t n;
|
||||
|
||||
UINT written = 0;
|
||||
FIL file;
|
||||
|
@ -69,7 +74,9 @@ int filetransfer_receive(uint8_t *mac, uint32_t const k[4])
|
|||
uint8_t metadata[32];
|
||||
|
||||
//nrf_set_rx_mac(0, 32, 5, mac);
|
||||
nrf_rcv_pkt_time_encr(3000, 32, metadata, k);
|
||||
n = nrf_rcv_pkt_time_encr(3000, 32, metadata, k);
|
||||
if( n != 32 )
|
||||
return 1; //timeout
|
||||
//nrf_set_rx_mac(0, 32, 5, macbuf);
|
||||
//lcdPrintln("got meta"); lcdRefresh();
|
||||
metadata[19] = 0; //enforce termination
|
||||
|
@ -79,7 +86,7 @@ int filetransfer_receive(uint8_t *mac, uint32_t const k[4])
|
|||
if( size > MAXSIZE ) return 1; //file to big
|
||||
//if(fileexists(metadata)) return 1; //file already exists
|
||||
|
||||
lcdPrint("open"); lcdPrintln((const char*)metadata); lcdRefresh();
|
||||
//lcdPrint("open"); lcdPrintln((const char*)metadata); lcdRefresh();
|
||||
res = f_open(&file, (const char*)metadata, FA_OPEN_ALWAYS|FA_WRITE);
|
||||
|
||||
//lcdPrintln("file opened"); lcdRefresh();
|
||||
|
@ -90,9 +97,18 @@ int filetransfer_receive(uint8_t *mac, uint32_t const k[4])
|
|||
uint16_t wordcount = (size+3)/4;
|
||||
|
||||
//nrf_set_rx_mac(0, 32, 5, mac);
|
||||
lcdPrintln("get file"); lcdRefresh();
|
||||
rftransfer_receive(buf, wordcount*4, 1000);
|
||||
lcdPrintln("got file"); lcdRefresh();
|
||||
//lcdPrintln("get file"); lcdRefresh();
|
||||
int fres = rftransfer_receive(buf, wordcount*4, 1000);
|
||||
if( fres == -1 ){
|
||||
lcdPrintln("checksum wrong");
|
||||
}else if( fres == -2 ){
|
||||
lcdPrintln("timeout");
|
||||
}else{
|
||||
//lcdPrintln("got file");
|
||||
}
|
||||
lcdRefresh();
|
||||
if( fres < 0 )
|
||||
return;
|
||||
//nrf_set_rx_mac(0, 32, 5, macbuf);
|
||||
|
||||
xxtea_decode_words((uint32_t *)buf, wordcount, k);
|
||||
|
@ -103,6 +119,8 @@ int filetransfer_receive(uint8_t *mac, uint32_t const k[4])
|
|||
return res;
|
||||
if( written != size )
|
||||
return 1; //error while writing
|
||||
lcdClear();
|
||||
lcdPrintln("Received"); lcdPrintln((const char*)metadata); lcdRefresh();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "basic/byteorder.h"
|
||||
#include "sysdefs.h"
|
||||
#include "filesystem/ff.h"
|
||||
#include "basic/uuid.h"
|
||||
|
||||
//const uint32_t key[4] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF};
|
||||
const uint32_t openbeaconkey[4] = { 0xB4595344,0xD3E119B6,0xA814D0EC,0xEFF5A24E };
|
||||
|
@ -59,9 +60,9 @@ void openbeaconRead()
|
|||
}
|
||||
|
||||
|
||||
void openbeaconSetup(uint32_t id)
|
||||
void openbeaconSetup(void)
|
||||
{
|
||||
oid = id;
|
||||
oid = GetUUID32();
|
||||
strength = 0;
|
||||
openbeaconRead();
|
||||
openbeaconSaveBlock();
|
||||
|
|
|
@ -16,7 +16,6 @@ void rftransfer_send(uint16_t size, uint8_t *data)
|
|||
buf[3] = rand >> 8;
|
||||
buf[4] = rand & 0xFF;
|
||||
|
||||
//nrf_snd_pkt_crc(5,buf); //setup packet
|
||||
nrf_snd_pkt_crc(32,buf); //setup packet
|
||||
delayms(20);
|
||||
uint16_t index = 0;
|
||||
|
@ -29,7 +28,7 @@ void rftransfer_send(uint16_t size, uint8_t *data)
|
|||
buf[2] = index & 0xFF;
|
||||
buf[3] = rand >> 8;
|
||||
buf[4] = rand & 0xFF;
|
||||
for(i=5; i<MAXPACKET && size>0; i++,size--){
|
||||
for(i=5; i<MAXPACKET-2 && size>0; i++,size--){
|
||||
buf[i] = *data++;
|
||||
}
|
||||
index++;
|
||||
|
@ -42,12 +41,11 @@ void rftransfer_send(uint16_t size, uint8_t *data)
|
|||
buf[2] = crc & 0xFF;
|
||||
buf[3] = rand >> 8;
|
||||
buf[4] = rand & 0xFF;
|
||||
//nrf_snd_pkt_crc(5,buf); //crc packet
|
||||
nrf_snd_pkt_crc(32,buf); //setup packet
|
||||
delayms(20);
|
||||
}
|
||||
|
||||
uint16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout)
|
||||
int16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout)
|
||||
{
|
||||
uint8_t buf[MAXPACKET];
|
||||
uint8_t state = 0;
|
||||
|
@ -56,7 +54,7 @@ uint16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout)
|
|||
unsigned int currentTick = systickGetTicks();
|
||||
unsigned int startTick = currentTick;
|
||||
|
||||
while(currentTick < (startTick+timeout) ){//this fails if either overflows
|
||||
while(systickGetTicks() < (startTick+timeout) ){//this fails if either overflows
|
||||
n = nrf_rcv_pkt_time(1000, MAXPACKET, buf);
|
||||
switch(state){
|
||||
case 0:
|
||||
|
@ -66,45 +64,45 @@ uint16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout)
|
|||
seq = 0;
|
||||
pos = 0;
|
||||
if( size <= maxlen ){
|
||||
lcdClear();
|
||||
lcdPrintln("got l"); lcdRefresh();
|
||||
//lcdClear();
|
||||
//lcdPrint("got l="); lcdPrintInt(size);
|
||||
//lcdPrintln(""); lcdRefresh();
|
||||
state = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if( n == 32 && buf[0] == 'D' && ((buf[3]<<8)|buf[4])==rand ){
|
||||
lcdPrint("got d"); lcdRefresh();
|
||||
//lcdPrint("got d"); lcdRefresh();
|
||||
if( seq == ((buf[1]<<8)|buf[2]) ){
|
||||
lcdPrintln(" in seq"); lcdRefresh();
|
||||
//if( (pos + n - 5)<maxlen ){
|
||||
//for(i=5; i<n; i++,pos++){
|
||||
for(i=5; i<n && pos<size; i++,pos++){
|
||||
//lcdPrintln(" in seq"); lcdRefresh();
|
||||
for(i=5; i<n-2 && pos<size; i++,pos++){
|
||||
buffer[pos] = buf[i];
|
||||
}
|
||||
seq++;
|
||||
//}
|
||||
}
|
||||
}
|
||||
if( pos == size ){
|
||||
lcdPrintln("got all"); lcdRefresh();
|
||||
//lcdPrintln("got all"); lcdRefresh();
|
||||
crc = crc16(buffer, size);
|
||||
state = 2;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if( n == 32 && buf[0] == 'C' && ((buf[3]<<8)|buf[4])==rand){
|
||||
lcdPrint("got crc"); lcdRefresh();
|
||||
//lcdPrint("got crc"); lcdRefresh();
|
||||
if( crc == ((buf[1]<<8)|buf[2]) ){
|
||||
lcdPrintln(" ok"); lcdRefresh();
|
||||
//lcdPrintln(" ok"); lcdRefresh();
|
||||
return size;
|
||||
}else{
|
||||
state = 0;
|
||||
//lcdPrintln(" nok"); lcdRefresh();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
};
|
||||
}
|
||||
return 0;
|
||||
//lcdPrintln("Timeout"); lcdRefresh();
|
||||
return -2;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <stdint.h>
|
||||
|
||||
void rftransfer_send(uint16_t size, uint8_t *data);
|
||||
uint16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout);
|
||||
int16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
#include <fonts.h>
|
||||
#include <render.h>
|
||||
|
||||
#define MAXCHR (30*20)
|
||||
static uint8_t buf[MAXCHR];
|
||||
|
||||
// Local function: Get next nibble.
|
||||
int ctr=0; // offset for next nibble
|
||||
int hilo=0; // 0= high nibble next, 1=low nibble next
|
||||
|
@ -15,7 +12,11 @@ static uint8_t buf[MAXCHR];
|
|||
ctr++;
|
||||
hilo=1-hilo;
|
||||
if(hilo==1){
|
||||
if(efont.type==FONT_EXTERNAL){
|
||||
byte=_getFontData(GET_DATA,0);
|
||||
}else{
|
||||
byte=data[ctr];
|
||||
};
|
||||
val=byte>>4;
|
||||
}else{
|
||||
val=byte&0x0f;
|
||||
|
@ -44,7 +45,7 @@ uint8_t * pk_decode(const uint8_t * ldata,int * len){
|
|||
int length=*len; // Length of character bytestream
|
||||
int height; // Height of character in bytes
|
||||
int hoff; // bit position for non-integer heights
|
||||
uint8_t * bufptr=buf; // Output buffer for decoded character
|
||||
uint8_t * bufptr=charBuf; // Output buffer for decoded character
|
||||
|
||||
height=(font->u8Height-1)/8+1;
|
||||
hoff=font->u8Height%8;
|
||||
|
@ -55,10 +56,17 @@ uint8_t * pk_decode(const uint8_t * ldata,int * len){
|
|||
int pos=0; // Decoder internal: current bit position (0..7)
|
||||
int nyb; // Decoder internal: current nibble / value
|
||||
|
||||
if(efont.type==FONT_EXTERNAL){
|
||||
if(_getFontData(PEEK_DATA,0)>>4 == 14){ // Char starts with 1-bits.
|
||||
gnn();
|
||||
curbit=1;
|
||||
};
|
||||
}else{
|
||||
if(data[ctr]>>4 == 14){ // Char starts with 1-bits.
|
||||
gnn();
|
||||
curbit=1;
|
||||
};
|
||||
};
|
||||
|
||||
while(ctr<length){ /* Iterate the whole input stream */
|
||||
|
||||
|
@ -89,14 +97,14 @@ uint8_t * pk_decode(const uint8_t * ldata,int * len){
|
|||
*bufptr|=1<<(7-pos);
|
||||
};
|
||||
pos++;
|
||||
if(((bufptr-buf)%height)==(height-1) && (pos==hoff)){
|
||||
if(((bufptr-charBuf)%height)==(height-1) && (pos==hoff)){
|
||||
// Finish incomplete last byte per column
|
||||
pos=8;
|
||||
};
|
||||
|
||||
if(pos==8){
|
||||
bufptr++;
|
||||
if((bufptr-buf)%height==0){ // End of column?
|
||||
if((bufptr-charBuf)%height==0){ // End of column?
|
||||
while(repeat>0){
|
||||
for(int y=0;y<height;y++){
|
||||
bufptr[0]=bufptr[-height];
|
||||
|
@ -111,6 +119,6 @@ uint8_t * pk_decode(const uint8_t * ldata,int * len){
|
|||
curbit=1-curbit;
|
||||
};
|
||||
|
||||
*len=(bufptr-buf)/height; // return size of output buffer.
|
||||
return buf;
|
||||
*len=(bufptr-charBuf)/height; // return size of output buffer.
|
||||
return charBuf;
|
||||
};
|
||||
|
|
|
@ -20,17 +20,19 @@ struct FONT_DEF {
|
|||
const uint16_t *charExtra; /* Pointer to array of extra char info */
|
||||
};
|
||||
|
||||
struct EXTFONT {
|
||||
char type; // 0: none, 1: static, 2: loaded
|
||||
char name[13];
|
||||
struct FONT_DEF def;
|
||||
};
|
||||
|
||||
typedef const struct FONT_DEF * FONT;
|
||||
|
||||
/* interesting / exported stuff */
|
||||
|
||||
#define FONT_DIR_LTR 0
|
||||
#define FONT_DIR_RTL 1
|
||||
// Not implemented
|
||||
// #define FONT_DIR_UP 2
|
||||
// #define FONT_DIR_DOWN 3
|
||||
#define FONT_DEFAULT 0
|
||||
#define FONT_INTERNAL 1
|
||||
#define FONT_EXTERNAL 2
|
||||
|
||||
extern const struct FONT_DEF * font;
|
||||
extern char font_direction;
|
||||
extern struct EXTFONT efont;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,16 +1,193 @@
|
|||
#include <string.h>
|
||||
|
||||
#include <sysdefs.h>
|
||||
#include <render.h>
|
||||
#include <decoder.h>
|
||||
#include <fonts.h>
|
||||
#include "basic/basic.h"
|
||||
#include "fonts/smallfonts.h"
|
||||
|
||||
#include "filesystem/ff.h"
|
||||
|
||||
/* Global Variables */
|
||||
const struct FONT_DEF * font = NULL;
|
||||
char font_direction = FONT_DIR_LTR;
|
||||
|
||||
struct EXTFONT efont;
|
||||
|
||||
FIL file; /* current font file */
|
||||
|
||||
/* Exported Functions */
|
||||
|
||||
void setIntFont(const struct FONT_DEF * font){
|
||||
memcpy(&efont.def,font,sizeof(struct FONT_DEF));
|
||||
efont.type=FONT_INTERNAL;
|
||||
font=NULL;
|
||||
};
|
||||
|
||||
void setExtFont(const char *fname){
|
||||
if(strlen(fname)>8+4)
|
||||
return;
|
||||
strcpy(efont.name,fname);
|
||||
// memcpy(efont.name+strlen(fname),".f0n",5);
|
||||
|
||||
efont.type=FONT_EXTERNAL;
|
||||
font=NULL;
|
||||
};
|
||||
|
||||
|
||||
int _getFontData(int type, int offset){
|
||||
UINT readbytes;
|
||||
UINT res;
|
||||
static uint16_t extras;
|
||||
static uint16_t character;
|
||||
static const void * ptr;
|
||||
|
||||
if(efont.type == FONT_EXTERNAL){
|
||||
|
||||
if (type == START_FONT){
|
||||
res = f_read(&file, &efont.def.u8Width, sizeof(uint8_t), &readbytes);
|
||||
res = f_read(&file, &efont.def.u8Height, sizeof(uint8_t), &readbytes);
|
||||
res = f_read(&file, &efont.def.u8FirstChar, sizeof(uint8_t), &readbytes);
|
||||
res = f_read(&file, &efont.def.u8LastChar, sizeof(uint8_t), &readbytes);
|
||||
res = f_read(&file, &extras, sizeof(uint16_t), &readbytes);
|
||||
return 0;
|
||||
};
|
||||
if (type == SEEK_EXTRAS){
|
||||
f_lseek(&file,6);
|
||||
return 0;
|
||||
};
|
||||
if(type == GET_EXTRAS){
|
||||
uint16_t word;
|
||||
res = f_read(&file, &word, sizeof(uint16_t), &readbytes);
|
||||
return word;
|
||||
};
|
||||
if (type == SEEK_WIDTH){
|
||||
f_lseek(&file,6+(extras*sizeof(uint16_t)));
|
||||
return 0;
|
||||
};
|
||||
if(type == GET_WIDTH || type == GET_DATA){
|
||||
uint8_t width;
|
||||
res = f_read(&file, &width, sizeof(uint8_t), &readbytes);
|
||||
return width;
|
||||
};
|
||||
if(type == SEEK_DATA){
|
||||
character=offset;
|
||||
f_lseek(&file,6+
|
||||
(extras*sizeof(uint16_t))+
|
||||
((extras+font->u8LastChar-font->u8FirstChar)*sizeof(uint8_t))+
|
||||
(offset*sizeof(uint8_t))
|
||||
);
|
||||
return 0;
|
||||
};
|
||||
if(type == PEEK_DATA){
|
||||
uint8_t width;
|
||||
res = f_read(&file, &width, sizeof(uint8_t), &readbytes);
|
||||
f_lseek(&file,6+
|
||||
(extras*sizeof(uint16_t))+
|
||||
((extras+font->u8LastChar-font->u8FirstChar)*sizeof(uint8_t))+
|
||||
(character*sizeof(uint8_t))
|
||||
);
|
||||
return width;
|
||||
};
|
||||
#ifdef NOTYET
|
||||
}else{ // efont.type==FONT_INTERNAL
|
||||
|
||||
if (type == START_FONT){
|
||||
memcpy(&efont.def,font,sizeof(struct FONT_DEF));
|
||||
return 0;
|
||||
};
|
||||
if (type == SEEK_EXTRAS){
|
||||
ptr=efont.def.charExtra;
|
||||
return 0;
|
||||
};
|
||||
if(type == GET_EXTRAS){
|
||||
uint16_t word;
|
||||
word=*(uint16_t*)ptr;
|
||||
ptr=((uint16_t*)ptr)+1;
|
||||
return word;
|
||||
};
|
||||
if (type == SEEK_WIDTH){
|
||||
ptr=efont.def.charInfo;
|
||||
return 0;
|
||||
};
|
||||
if(type == GET_WIDTH || type == GET_DATA){
|
||||
uint8_t width;
|
||||
width=*(uint8_t*)ptr;
|
||||
ptr=((uint8_t*)ptr)+1;
|
||||
return width;
|
||||
};
|
||||
if(type == SEEK_DATA){
|
||||
if(offset==REPEAT_LAST_CHARACTER)
|
||||
offset=character;
|
||||
else
|
||||
character=offset;
|
||||
|
||||
ptr=efont.def.au8FontTable;
|
||||
return 0;
|
||||
};
|
||||
#endif
|
||||
};
|
||||
|
||||
/* NOTREACHED */
|
||||
return 0;
|
||||
};
|
||||
|
||||
int _getIndex(int c){
|
||||
#define ERRCHR (font->u8FirstChar+1)
|
||||
/* Does this font provide this character? */
|
||||
if(c<font->u8FirstChar)
|
||||
c=ERRCHR;
|
||||
if(c>font->u8LastChar && efont.type!=FONT_EXTERNAL && font->charExtra == NULL)
|
||||
c=ERRCHR;
|
||||
|
||||
if(c>font->u8LastChar && (efont.type==FONT_EXTERNAL || font->charExtra != NULL)){
|
||||
if(efont.type==FONT_EXTERNAL){
|
||||
_getFontData(SEEK_EXTRAS,0);
|
||||
int cc=0;
|
||||
int cache;
|
||||
while( (cache=_getFontData(GET_EXTRAS,0)) < c)
|
||||
cc++;
|
||||
if( cache > c)
|
||||
c=ERRCHR;
|
||||
else
|
||||
c=font->u8LastChar+cc+1;
|
||||
}else{
|
||||
int cc=0;
|
||||
while( font->charExtra[cc] < c)
|
||||
cc++;
|
||||
if(font->charExtra[cc] > c)
|
||||
c=ERRCHR;
|
||||
else
|
||||
c=font->u8LastChar+cc+1;
|
||||
};
|
||||
};
|
||||
c-=font->u8FirstChar;
|
||||
return c;
|
||||
};
|
||||
|
||||
uint8_t charBuf[MAXCHR];
|
||||
|
||||
int DoChar(int sx, int sy, int c){
|
||||
|
||||
// font=NULL;
|
||||
if(font==NULL){
|
||||
if(efont.type==FONT_INTERNAL){
|
||||
font=&efont.def;
|
||||
}else if (efont.type==FONT_EXTERNAL){
|
||||
UINT res;
|
||||
res=f_open(&file, efont.name, FA_OPEN_EXISTING|FA_READ);
|
||||
if(res){
|
||||
efont.type=0;
|
||||
font=&Font_7x8;
|
||||
}else{
|
||||
_getFontData(START_FONT,0);
|
||||
font=&efont.def;
|
||||
};
|
||||
}else{
|
||||
font=&Font_7x8;
|
||||
};
|
||||
};
|
||||
|
||||
/* how many bytes is it high? */
|
||||
char height=(font->u8Height-1)/8+1;
|
||||
char hoff=(8-(font->u8Height%8))%8;
|
||||
|
@ -18,39 +195,64 @@ int DoChar(int sx, int sy, int c){
|
|||
const uint8_t * data;
|
||||
int width,preblank=0,postblank=0;
|
||||
do { /* Get Character data */
|
||||
/* Does this font provide this character? */
|
||||
if(c<font->u8FirstChar)
|
||||
c=font->u8FirstChar+1; // error
|
||||
if(c>font->u8LastChar && font->charExtra == NULL)
|
||||
c=font->u8FirstChar+1; // error
|
||||
|
||||
if(c>font->u8LastChar && font->charExtra != NULL){
|
||||
int cc=0;
|
||||
while( font->charExtra[cc] < c)
|
||||
cc++;
|
||||
if(font->charExtra[cc] > c)
|
||||
c=font->u8FirstChar+1; // error
|
||||
else
|
||||
c=font->u8LastChar+cc+1;
|
||||
};
|
||||
/* Get intex into character list */
|
||||
c=_getIndex(c);
|
||||
|
||||
/* starting offset into character source data */
|
||||
int toff=0;
|
||||
|
||||
if(font->u8Width==0){
|
||||
for(int y=0;y<c-font->u8FirstChar;y++)
|
||||
if(efont.type == FONT_EXTERNAL){
|
||||
_getFontData(SEEK_WIDTH,0);
|
||||
for(int y=0;y<c;y++)
|
||||
toff+=_getFontData(GET_WIDTH,0);
|
||||
width=_getFontData(GET_WIDTH,0);
|
||||
|
||||
_getFontData(SEEK_DATA,toff);
|
||||
UINT res;
|
||||
UINT readbytes;
|
||||
res = f_read(&file, charBuf, width*height, &readbytes);
|
||||
if(res != FR_OK || readbytes<width*height)
|
||||
return sx;
|
||||
data=charBuf;
|
||||
}else{
|
||||
for(int y=0;y<c;y++)
|
||||
toff+=font->charInfo[y].widthBits;
|
||||
width=font->charInfo[c-font->u8FirstChar].widthBits;
|
||||
width=font->charInfo[c].widthBits;
|
||||
|
||||
toff*=height;
|
||||
data=&font->au8FontTable[toff];
|
||||
};
|
||||
postblank=1;
|
||||
}else if(font->u8Width==1){ // NEW CODE
|
||||
if(efont.type == FONT_EXTERNAL){
|
||||
_getFontData(SEEK_WIDTH,0);
|
||||
for(int y=0;y<c;y++)
|
||||
toff+=_getFontData(GET_WIDTH,0);
|
||||
width=_getFontData(GET_WIDTH,0);
|
||||
_getFontData(SEEK_DATA,toff);
|
||||
UINT res;
|
||||
UINT readbytes;
|
||||
uint8_t testbyte;
|
||||
res = f_read(&file, &testbyte, sizeof(uint8_t), &readbytes);
|
||||
if(testbyte>>4 ==15){
|
||||
res = f_read(&file, &preblank, sizeof(uint8_t), &readbytes);
|
||||
res = f_read(&file, &postblank, sizeof(uint8_t), &readbytes);
|
||||
width-=3;
|
||||
width/=height;
|
||||
res = f_read(&file, charBuf, width*height, &readbytes);
|
||||
if(res != FR_OK || readbytes<width*height)
|
||||
return sx;
|
||||
data=charBuf;
|
||||
}else{
|
||||
_getFontData(SEEK_DATA,toff);
|
||||
data=pk_decode(NULL,&width); // Hackety-hack
|
||||
};
|
||||
}else{
|
||||
// Find offset and length for our character
|
||||
for(int y=0;y<c-font->u8FirstChar;y++)
|
||||
for(int y=0;y<c;y++)
|
||||
toff+=font->charInfo[y].widthBits;
|
||||
width=font->charInfo[c-font->u8FirstChar].widthBits;
|
||||
|
||||
width=font->charInfo[c].widthBits;
|
||||
if(font->au8FontTable[toff]>>4 == 15){ // It's a raw character!
|
||||
preblank = font->au8FontTable[toff+1];
|
||||
postblank= font->au8FontTable[toff+2];
|
||||
|
@ -59,8 +261,10 @@ int DoChar(int sx, int sy, int c){
|
|||
}else{
|
||||
data=pk_decode(&font->au8FontTable[toff],&width);
|
||||
}
|
||||
};
|
||||
|
||||
}else{
|
||||
toff=(c-font->u8FirstChar)*font->u8Width*height;
|
||||
toff=(c)*font->u8Width*height;
|
||||
width=font->u8Width;
|
||||
data=&font->au8FontTable[toff];
|
||||
};
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define __RENDER_H_
|
||||
|
||||
#include "display.h"
|
||||
#include "fonts.h"
|
||||
|
||||
/*
|
||||
#badge <s> 96x68
|
||||
|
@ -33,5 +34,21 @@ int DoIntXn(int sx, int sy, unsigned int num, unsigned int maxlen);
|
|||
int DoIntX(int sx, int sy, unsigned int num);
|
||||
int DoCharX(int sx, int sy, unsigned char num);
|
||||
int DoShortX(int sx, int sy, uint16_t num);
|
||||
void setIntFont(const struct FONT_DEF * font);
|
||||
void setExtFont(const char *file);
|
||||
|
||||
#define START_FONT 0
|
||||
#define SEEK_EXTRAS 1
|
||||
#define GET_EXTRAS 2
|
||||
#define SEEK_WIDTH 3
|
||||
#define GET_WIDTH 4
|
||||
#define SEEK_DATA 5
|
||||
#define GET_DATA 6
|
||||
#define PEEK_DATA 7
|
||||
|
||||
int _getFontData(int type, int offset);
|
||||
|
||||
#define MAXCHR (30*20)
|
||||
extern uint8_t charBuf[MAXCHR];
|
||||
|
||||
#endif
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue