This section is a concise reference guide for Superconference hackers short on time. It will continue growing through Supercon weekend to be a programming FAQ as needed.
HOWTO: Get an overview of badge code
- main.c: Most of this file is a large comment block describing overall project layout.
HOWTO: Free up memory to make room for big projects.
- badge_settings.h
- Data memory: USE_RAM_IMAGE_NEW and USE_RAMDISK
- Program memory: USE_ROMDISK and USE_ROMDISK2
- Frees up memory at the cost of degrading/disabling badge's Z80 emulator running CP/M.
HOWTO: Upload new badge firmware faster.
- Free up program memory, see above. Smaller program memory means less data to transfer to the badge on every firmware upload.
HOWTO: Manage memory at runtime.
- The default badge firmware uses only compile-time memory allocation. (There is no call to malloc()) This avoids memory leaks, heap fragmentation, etc.
- The following blocks of memory, allocated at compile time, may be available.
- ram[]: 64 kb available when not running Z80 emulator. See splash.c for an example of how to use it.
- Advanced challenge: code injection into Z80 emulator memory using ram[].
- flash_buff[]: Available when not interacting with flash storage
- bprog[]: Available when not running BASIC
- disp_buffer[] color_buffer[]: Available if not printing text on screen
- ram[]: 64 kb available when not running Z80 emulator. See splash.c for an example of how to use it.
HOWTO: Draw a bitmap to screen.
- tft_set_write_area(x,y,width,height); //Set the drawing area
- IMPORTANT: Drawing area is INCLUSIVE. This means to draw the entire screen width of 320 pixels, "x" would be zero, and "width" is 319. NOT 320.
- TFT_24_7789_Write_Command(0x2C); // Begin bitmap data transfer.
- TFT_24_7789_Write_Data3(red, green, blue); // RGB value for one pixel, repeat until drawing area is filled.
Example 1: disp.c: void tft_fill_area() fills an area with a single color.
Example 2: nyancat.c: nyancat() renders animation frame line-by-line.
HOWTO: Stop automatic redraw of text buffer on screen.
- enable_display_scanning(0);
HOWTO: Read/write nonvolatile (flash) memory.
- hwz.c: fl_read_4k(), fl_erase_4k(), fl_write_4k()
- badge_settings.h has a comment block laying out how flash memory is organized.
- Example usage in badge.c: basic_load_program() and basic_save_program()
HOWTO: Generate sounds which aren't musical notes.
- hw.c: sound_set_generator()
HOWTO: Read keyboard directly.
- hw.c: keyb_tasks()
- stdio_get() can get confused when multiple keys are pressed simultaneously so certain key combinations require direct reading. (Example: a game that needs to know a user pressed "Up" and "Right" simultaneously for a diagonal move.)
HOWTO: See under the hood of a BASIC command.
- basic/ubasic.c: static void statement(void)
- When the BASIC interpreter sees a recognized command (in the form of a token) statement() will call a corresponding C function to do the actual work.
HOWTO: Add a new BASIC command.
- tokenizer_generate/ubasic.re
- This is the input file for re2c to generate a new high speed BASIC tokenizer.
HOWTO: I2C
(Added in version 1.21)
- hw.c: iic_init(), iic_start(), etc
- user_program_temp.c is not part of the badge firmware build, but serves as sample program demonstrating interaction with Si7020 temperature sensor over I2C.
HOWTO: PWM
- Easy way: Take over one of the three audio voice timers (Timer2/3/4) and, instead of always inverting one of the audio generator pins, count duty cycle and output to one of the expansion port pins accordingly.
- hw.c: Timer2Handler(), etc.
- Proper way: Use the PIC32 Output Compare peripheral to do basically the same thing, but using high performance dedicated hardware.
HOWTO: Solve the badge puzzle challenge
- LOL No.
The following tasks have no direct support in default firmware. If someone steps up and write a piece of code to do it, please message Roger Cheng to add a link here.
HOWTO: SPI
- It will take bit-banging code to communicate SPI over expansion header.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.