Improved docu
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#define BYTES_PER_PIXEL 2
|
#define BYTES_PER_PIXEL 2
|
||||||
|
|
||||||
uint16_t bitmap_draw( unsigned int width, unsigned int height,
|
int8_t bitmap_draw( unsigned int width, unsigned int height,
|
||||||
unsigned int bytes_per_pixel,
|
unsigned int bytes_per_pixel,
|
||||||
const unsigned char *pixel_data){
|
const unsigned char *pixel_data){
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,10 @@
|
|||||||
* @param width Bitmap width
|
* @param width Bitmap width
|
||||||
* @param height Bitmap height
|
* @param height Bitmap height
|
||||||
* @param bytes_per_pixel Bytes per pixel
|
* @param bytes_per_pixel Bytes per pixel
|
||||||
* @param color 16-Bit color bitmap
|
* @param pixel_data uint16_t Bitmap data array
|
||||||
* @param *pixel_data uint16_t Bitmap data array
|
|
||||||
* @return -1 if error 0 else
|
* @return -1 if error 0 else
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
uint16_t bitmap_draw(unsigned int width, unsigned int height, unsigned int bytes_per_pixel, const unsigned char *pixel_data);
|
int8_t bitmap_draw(unsigned int width, unsigned int height, unsigned int bytes_per_pixel, const unsigned char *pixel_data);
|
||||||
|
|
||||||
#endif /* DRAW_H */
|
#endif /* DRAW_H */
|
||||||
|
|||||||
5
src/io.h
5
src/io.h
@@ -34,8 +34,13 @@ bool io_button_has_edge(uint8_t btnnumber);
|
|||||||
uint16_t read_adc();
|
uint16_t read_adc();
|
||||||
|
|
||||||
|
|
||||||
|
//Mask for the ADC value (to cut away bits which cannot be valid)
|
||||||
#define ADC_MASK 0x3FF
|
#define ADC_MASK 0x3FF
|
||||||
|
|
||||||
|
//Value that should be threated as maximum
|
||||||
#define ADC_MAX 0x3A0
|
#define ADC_MAX 0x3A0
|
||||||
|
|
||||||
|
//Tolerance value. Changes below this value will be ignored.
|
||||||
#define ADC_TOLERANCE 0x08
|
#define ADC_TOLERANCE 0x08
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
15
src/io.s
15
src/io.s
@@ -11,10 +11,10 @@ typedef struct pin_s {
|
|||||||
.set OFFSET_PIN_PINMASK, 4
|
.set OFFSET_PIN_PINMASK, 4
|
||||||
|
|
||||||
|
|
||||||
//--------Local Functions ------------------
|
//--------Functions ------------------
|
||||||
|
//See the doxygen comments in the headerfiles for the parameter documentation of the following functions
|
||||||
.text
|
.text
|
||||||
|
|
||||||
|
|
||||||
//void pin_create(pin_t* pin, GPIO_TypeDef* GPIO, uint8_t pinnr)
|
//void pin_create(pin_t* pin, GPIO_TypeDef* GPIO, uint8_t pinnr)
|
||||||
.global pin_create
|
.global pin_create
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ pin_create:
|
|||||||
.set GPIO_PuPd_UP, 1
|
.set GPIO_PuPd_UP, 1
|
||||||
.set GPIO_OType_OD, 1
|
.set GPIO_OType_OD, 1
|
||||||
|
|
||||||
PUSH {r4,r5,r6,lr}
|
PUSH {r4,r5,r6,lr} //Save registers
|
||||||
|
|
||||||
LSL r4, r2, #1 //r4 = pinnr*2
|
LSL r4, r2, #1 //r4 = pinnr*2
|
||||||
MOV r5, #3 //r5 = 3
|
MOV r5, #3 //r5 = 3
|
||||||
@@ -72,7 +72,7 @@ pin_create:
|
|||||||
//pin->pinmask=0x01<<pinnr; // Insert the pinmask
|
//pin->pinmask=0x01<<pinnr; // Insert the pinmask
|
||||||
STRH r5, [r0, #OFFSET_PIN_PINMASK]
|
STRH r5, [r0, #OFFSET_PIN_PINMASK]
|
||||||
|
|
||||||
POP {r4, r5, r6, pc}
|
POP {r4, r5, r6, pc} //Restore registers
|
||||||
|
|
||||||
end_pin_create:
|
end_pin_create:
|
||||||
|
|
||||||
@@ -84,7 +84,9 @@ end_pin_create:
|
|||||||
pin_get:
|
pin_get:
|
||||||
|
|
||||||
.set GPIO_IDR, 0x10
|
.set GPIO_IDR, 0x10
|
||||||
//return ((pin->GPIO->IDR & pin->pinmask) > 0);
|
|
||||||
|
//C-Code (one liner) return ((pin->GPIO->IDR & pin->pinmask) > 0);
|
||||||
|
|
||||||
LDR r1, [r0, #OFFSET_PIN_GPIO] //r1 = pin->GPIO
|
LDR r1, [r0, #OFFSET_PIN_GPIO] //r1 = pin->GPIO
|
||||||
LDR r1, [r1,#GPIO_IDR] // r1 = pin->GPIO->IDR
|
LDR r1, [r1,#GPIO_IDR] // r1 = pin->GPIO->IDR
|
||||||
LDRH r2, [r0, #OFFSET_PIN_PINMASK] // r2 = pin->pinmask
|
LDRH r2, [r0, #OFFSET_PIN_PINMASK] // r2 = pin->pinmask
|
||||||
@@ -93,13 +95,14 @@ pin_get:
|
|||||||
|
|
||||||
MOV r0, #1 //return 1
|
MOV r0, #1 //return 1
|
||||||
MOV pc, lr
|
MOV pc, lr
|
||||||
|
|
||||||
pin_get_eq:
|
pin_get_eq:
|
||||||
MOV r0, #0 //return 0
|
MOV r0, #0 //return 0
|
||||||
MOV pc, lr
|
MOV pc, lr
|
||||||
|
|
||||||
end_pin_get:
|
end_pin_get:
|
||||||
|
|
||||||
|
|
||||||
//-------Global Functions-------------------
|
|
||||||
//void adc_init(void);
|
//void adc_init(void);
|
||||||
.global adc_init
|
.global adc_init
|
||||||
|
|
||||||
|
|||||||
38
src/io_c.c
38
src/io_c.c
@@ -2,42 +2,44 @@
|
|||||||
#include <carme_io2.h>
|
#include <carme_io2.h>
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
|
|
||||||
|
//Structure which holds the configuration for one (input) pin (GPIO).
|
||||||
typedef struct pin_s {
|
typedef struct pin_s {
|
||||||
GPIO_TypeDef* GPIO;
|
GPIO_TypeDef* GPIO; //GPIO port which is used
|
||||||
uint16_t pinmask;
|
uint16_t pinmask; //Pin Nr (0..15)
|
||||||
} pin_t;
|
} pin_t;
|
||||||
|
|
||||||
// Local variables
|
// Local variables
|
||||||
|
// Pin structs for the pins T0..T3
|
||||||
static pin_t pin_t0;
|
static pin_t pin_t0;
|
||||||
static pin_t pin_t1;
|
static pin_t pin_t1;
|
||||||
static pin_t pin_t2;
|
static pin_t pin_t2;
|
||||||
static pin_t pin_t3;
|
static pin_t pin_t3;
|
||||||
static uint8_t new = 0;
|
|
||||||
static uint8_t old = 0;
|
//Variables for the edge detection
|
||||||
static volatile uint8_t edg = 0;
|
static uint8_t old = 0; //old state of the buttons
|
||||||
|
static volatile uint8_t edg = 0; //detected edges
|
||||||
|
|
||||||
//Function prototypes of functions that are implemented in asm
|
//Function prototypes of functions that are implemented in asm
|
||||||
void pin_create(pin_t* pin, GPIO_TypeDef* GPIO, uint8_t pinnr);
|
void pin_create(pin_t* pin, GPIO_TypeDef* GPIO, uint8_t pinnr); //Initializes the pin structure and the gpio with the passed data.
|
||||||
bool pin_get(pin_t* pin);
|
bool pin_get(pin_t* pin); //Returns the current state of the pin (true = pin is "high")
|
||||||
bool adc_init();
|
bool adc_init(); //Initializes the adc and configures the channel
|
||||||
|
|
||||||
|
|
||||||
void io_process(void) {
|
void io_process(void) {
|
||||||
new = pin_get(&pin_t0) |
|
//Save the current state of the 4 pins in the lower nibble
|
||||||
pin_get(&pin_t1) << 1 |
|
uint8_t new = pin_get(&pin_t0) |
|
||||||
pin_get(&pin_t2) << 2 |
|
pin_get(&pin_t1) << 1 |
|
||||||
pin_get(&pin_t3) << 3;
|
pin_get(&pin_t2) << 2 |
|
||||||
|
pin_get(&pin_t3) << 3;
|
||||||
|
|
||||||
edg |= (new ^ old) & new; // detect positive edge
|
edg |= (new ^ old) & new; // detect positive edge
|
||||||
old = new;
|
old = new; //store current state, for later edge detection
|
||||||
}
|
}
|
||||||
|
|
||||||
bool io_button_has_edge(uint8_t btnnumber) {
|
bool io_button_has_edge(uint8_t btnnumber) {
|
||||||
uint8_t bm = (1 << btnnumber); // create bitmask
|
uint8_t bm = (1 << btnnumber); // create bitmask
|
||||||
bool status = ((edg & bm) > 0); // check if button is pressed
|
bool status = ((edg & bm) > 0); // check if button is pressed
|
||||||
|
|
||||||
if(status){
|
if(status) { // if button is pressed
|
||||||
edg &= ~bm; // clear edge bit
|
edg &= ~bm; // clear edge bit
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,14 +47,16 @@ bool io_button_has_edge(uint8_t btnnumber) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void io_init(void){
|
void io_init(void){
|
||||||
|
//Enable clock for gpio
|
||||||
//RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC,ENABLE); // Enable gpio clock source
|
//RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC,ENABLE); // Enable gpio clock source
|
||||||
RCC->AHB1ENR|= RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOI;
|
RCC->AHB1ENR|= RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOI;
|
||||||
|
|
||||||
// Create player pins
|
// Create player pins
|
||||||
pin_create(&pin_t0, GPIOC, 7); // create pin_t0
|
pin_create(&pin_t0, GPIOC, 7); // create pin_t0
|
||||||
pin_create(&pin_t1, GPIOB, 15); // create pin_t1
|
pin_create(&pin_t1, GPIOB, 15); // create pin_t1
|
||||||
pin_create(&pin_t2, GPIOB, 14); // create pin_t2
|
pin_create(&pin_t2, GPIOB, 14); // create pin_t2
|
||||||
pin_create(&pin_t3, GPIOI, 0); // create pin_t3
|
pin_create(&pin_t3, GPIOI, 0); // create pin_t3
|
||||||
|
|
||||||
adc_init();
|
adc_init(); //Initialize adc
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
22
src/main.c
22
src/main.c
@@ -31,18 +31,21 @@
|
|||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
|
|
||||||
|
//Game Object, which contains the entire state of the game
|
||||||
|
//Exchange this object via Uart, to have remote players
|
||||||
game_t gameobj;
|
game_t gameobj;
|
||||||
|
|
||||||
uint64_t ticks;
|
volatile uint64_t ticks = 0; //Ticks since reset
|
||||||
uint64_t lastTicks;
|
uint64_t lastTicks = 0; //Last tick
|
||||||
|
|
||||||
|
//SysTick Handler that will be called several times per second (see TICKS_PER_SECOND). This is an interrupt.
|
||||||
void SysTick_Handler() {
|
void SysTick_Handler() {
|
||||||
ticks++;
|
ticks++;
|
||||||
io_process();
|
io_process(); //Process button presses
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SYSCLK 168e6
|
#define SYSCLK 168e6 //System frequency
|
||||||
#define TICKS_PER_SECOND 1000
|
#define TICKS_PER_SECOND 1000 //Number of SysTick interrupts that should occour ( = number of times SysTick_Handler calls per sec)
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
@@ -50,13 +53,14 @@ int main(void)
|
|||||||
while(1); //sleep forever
|
while(1); //sleep forever
|
||||||
}
|
}
|
||||||
|
|
||||||
game_init(&gameobj, TICKS_PER_SECOND);
|
game_init(&gameobj, TICKS_PER_SECOND); //Init game state
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
uint64_t curTicks = ticks;
|
uint64_t curTicks = ticks;
|
||||||
if(game_step(&gameobj,curTicks-lastTicks)) { //calculate next game step, and pass it the delta time
|
if(game_step(&gameobj,curTicks-lastTicks)) { //calculate next game step, and pass it the delta time. Returns true if function was blocking
|
||||||
lastTicks = ticks;
|
lastTicks = ticks; //Save actual ticks
|
||||||
} else {
|
} else {
|
||||||
lastTicks = curTicks;
|
lastTicks = curTicks; //Save ticks from before calling game_step
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user