Commit b6469f50 authored by Sergi Hernandez's avatar Sergi Hernandez
Browse files

Undefined macros generate error (instead of default values).

All registers definitions and read/write functions in a single module.
Removed the low level hardware interface.
Added all the pattern modules.
Created a frame_buffer module to handle the associated memory.
Created a frame_buffer_control module to handle all patterns.
parent dd3065b7
......@@ -11,6 +11,8 @@ COMPILE_OPTS_M0 = -mfloat-abi=softfp -mcpu=cortex-m0
COMPILE_OPTS_M0plus = -mfloat-abi=softfp -mcpu=cortex-m0plus
COMPILE_OPTS_M3 = -mfloat-abi=softfp -mcpu=cortex-m3
MACROS = -DFB_MAX_BUFFER_LEN=16384 -DFBC_MAX_PATTERN_FUNC=16 -DFBC_MAX_DATA_PATTERN_LEN=32 -D FBC_MAX_COPY_FUNC=4 -DIMG_MAX_NUM_IMAGES=3 -DIMG_MAX_IMAGE_WIDTH=15 -DIMG_MAX_IMAGE_HEIGHT=15 -DMTN_X_LED_SPACING=10 -DMTN_Y_LED_SPACING=10
INCLUDE_DIRS = -I./include/ -I../memory/include -I../scheduler/include
DOC_DIR = ./doc
......@@ -49,13 +51,13 @@ PATTERN_FB_M3_OBJS = $(patsubst %,$(PATTERN_FB_M3_OBJ_DIR)%,$(PATTERN_FB_M3_OBJS
all: $(PATTERN_FB_OUT_M4_FPU) $(PATTERN_FB_OUT_M0) $(PATTERN_FB_OUT_M0plus) $(PATTERN_FB_OUT_M3)
$(PATTERN_FB_M4_FPU_OBJ_DIR)%.o: $(SRC_DIR)%.c
$(CC) -c $(CFLAGS) $(COMPILE_OPTS_M4_FPU) -o $@ $<
$(CC) -c $(CFLAGS) $(COMPILE_OPTS_M4_FPU) $(MACROS) -o $@ $<
$(PATTERN_FB_M0_OBJ_DIR)%.o: $(SRC_DIR)%.c
$(CC) -c $(CFLAGS) $(COMPILE_OPTS_M0) -o $@ $<
$(CC) -c $(CFLAGS) $(COMPILE_OPTS_M0) $(MACROS) -o $@ $<
$(PATTERN_FB_M0plus_OBJ_DIR)%.o: $(SRC_DIR)%.c
$(CC) -c $(CFLAGS) $(COMPILE_OPTS_M0plus) -o $@ $<
$(CC) -c $(CFLAGS) $(COMPILE_OPTS_M0plus) $(MACROS) -o $@ $<
$(PATTERN_FB_M3_OBJ_DIR)%.o: $(SRC_DIR)%.c
$(CC) -c $(CFLAGS) $(COMPILE_OPTS_M3) -o $@ $<
$(CC) -c $(CFLAGS) $(COMPILE_OPTS_M3) $(MACROS) -o $@ $<
mkdir_build:
mkdir -p build/m4_fpu
mkdir -p build/m0
......
......@@ -5,17 +5,25 @@
extern "C" {
#endif
#include "memory.h"
#include "frame_buffer_registers.h"
#ifndef FB_MAX_BUFFER_LEN
#define FB_MAX_BUFFER_LEN 16*1024
#error "Please, specify the maximum frame buffer length with the FB_MAX_BUFFER_LEN macro"
#endif
#define BYTES_PER_PIXEL 3
#define LEDS_BYTES_PER_PIXEL 12
unsigned char frame_buffer_init(TFrameBuffer *fb,TMemory *memory);
#define FB_BYTES_PER_PIXEL 3
typedef struct
{
unsigned short int ram_base_address;
unsigned short int eeprom_base_address;
unsigned short int num_rows;
unsigned short int num_pixels_per_row;
unsigned short int num_buffers;
unsigned short int buffer_size;
unsigned short int free_mem;
unsigned char pixel_buffer[FB_MAX_BUFFER_LEN];
}TFrameBuffer;
void frame_buffer_init(TFrameBuffer *fb,unsigned short int ram_base_address,unsigned short int eeprom_base_address);
void frame_buffer_set_num_rows(TFrameBuffer *fb,unsigned short int rows);
unsigned short int frame_buffer_get_num_rows(TFrameBuffer *fb);
void frame_buffer_set_pixels_per_row(TFrameBuffer *fb,unsigned short int pixels);
......@@ -23,10 +31,8 @@ unsigned short int frame_buffer_get_pixels_per_row(TFrameBuffer *fb);
void frame_buffer_set_num_buffers(TFrameBuffer *fb,unsigned char num);
unsigned char frame_buffer_get_num_buffers(TFrameBuffer *fb);
unsigned short int frame_buffer_get_free_memory(TFrameBuffer *fb);
unsigned char frame_buffer_update_buffer(TFrameBuffer *fb);
unsigned char *frame_buffer_get_pixel_buffer(TFrameBuffer *fb);
void frame_buffer_set_pixel_buffer(TFrameBuffer *fb,unsigned char *buffer);
void frame_buffer_set_pixel(TFrameBuffer *fb,unsigned char R,unsigned char G,unsigned char B,unsigned short int row,unsigned short int col, unsigned char *buffer);
unsigned char *frame_buffer_get_buffer(TFrameBuffer *fb,unsigned char buffer_id);
void frame_buffer_set_pixel(TFrameBuffer *fb,unsigned char buffer_id,unsigned char R,unsigned char G,unsigned char B,unsigned short int row,unsigned short int col);
#ifdef __cplusplus
}
......
#ifndef _FRAME_BUFFER_CONTROL_H
#define _FRAME_BUFFER_CONTROL_H
#ifdef __cplusplus
extern "C" {
#endif
#include "frame_buffer.h"
#include "patterns.h"
#include "memory.h"
#include "scheduler.h"
#ifndef FBC_MAX_PATTERN_FUNC
#error "Please, specify the maximum number of pattern functions with the FBC_MAX_PATTERN_FUNC macro"
#endif
#ifndef FBC_MAX_DATA_PATTERN_LEN
#error "Please, specify the maximum number of dtaa for each pattern with the FBC_MAX_DATA_PATTERN_LEN macro"
#endif
#ifndef FBC_MAX_COPY_FUNC
#error "Please, specify the maximum number of copy functions with the FBC_MAX_COPY_FUNC macro"
#endif
#include "frame_buffer_control_registers.h"
typedef void (*copy_func_t)(void *data);
typedef struct TFBControl
{
TFrameBuffer frame_buffer;
TScheduler *scheduler;
sched_channel_t sch_channel;
unsigned short int period_ms;
TMemModule mem_module;
unsigned short int ram_base_address;
unsigned short int eeprom_base_address;
// pattern attributes
unsigned char num_patterns;
void (*pat_functions[FBC_MAX_PATTERN_FUNC])(TLEDArea *area,void *pattern_data,unsigned char buffer_id,unsigned short int period,struct TFBControl *control);
TLEDArea pat_area[FBC_MAX_PATTERN_FUNC];
unsigned char pat_buffer_id[FBC_MAX_PATTERN_FUNC];
unsigned char pat_parameters[FBC_MAX_PATTERN_FUNC][FBC_MAX_DATA_PATTERN_LEN];
// copy attributes
unsigned char num_copy_functions;
copy_func_t copy_functions[FBC_MAX_COPY_FUNC];
void *copy_data[FBC_MAX_COPY_FUNC];
}TFBControl;
typedef void (*pattern_func_t)(TLEDArea *area,void *pattern_data,unsigned char buffer_id,unsigned short int period,TFBControl *control);
unsigned char frame_buffer_control_init(TFBControl *control,TMemory *memory,TScheduler *scheduler,sched_channel_t ch,unsigned short int ram_base_address,unsigned short int eeprom_base_address);
void frame_buffer_control_start(TFBControl *control);
void frame_buffer_control_stop(TFBControl *control);
void frame_buffer_control_set_period(TFBControl *control,unsigned short int period_ms);
unsigned short int frame_buffer_control_get_period(TFBControl *control);
// pattern functions
unsigned char frame_buffer_control_add_pattern(TFBControl *control,pattern_func_t function,TLEDArea *area,void *data,unsigned char data_length,unsigned char buffer_id);
void frame_buffer_control_remove_pattern(TFBControl *control,unsigned char index);
void frame_buffer_control_clear_patterns(TFBControl *control);
unsigned char frame_buffer_control_get_num_patterns(TFBControl *control);
unsigned char *frame_buffer_control_get_parameters(TFBControl *control, unsigned char index);
void frame_buffer_control_update(TFBControl *control);
// copy functions
unsigned char frame_buffer_control_add_copy_function(TFBControl *control,copy_func_t function,void *data);
void frame_buffer_control_remove_copy_function(TFBControl *control,unsigned char index);
void frame_buffer_control_clear_copy_functions(TFBControl *control);
unsigned char frame_buffer_control_get_num_copy_functions(TFBControl *control);
#ifdef __cplusplus
}
#endif
#endif
#ifndef _FRAME_BUFFER_CONTROL_REGISTERS_H
#define _FRAME_BUFFER_CONTROL_REGISTERS_H
#define RAM_FRAME_BUFFER_CONTROL_LENGTH (18+FBC_MAX_DATA_PATTERN_LEN+IMG_MAX_NUM_IMAGES*IMG_MAX_IMAGE_WIDTH*IMG_MAX_IMAGE_HEIGHT*3)
#define FRAME_BUFFER_CONTROL_NUM_PATTERN_OFFSET 0
#define FRAME_BUFFER_CONTROL_PATTERN_INDEX_OFFSET 1
#define FRAME_BUFFER_CONTROL_OFFSET 2
#define FRAME_BUFFER_CONTROL_PATTERN_ID_OFFSET 3
#define FRAME_BUFFER_CONTROL_MIN_ROW_OFFSET 4
#define FRAME_BUFFER_CONTROL_MAX_ROW_OFFSET 6
#define FRAME_BUFFER_CONTROL_MIN_COL_OFFSET 8
#define FRAME_BUFFER_CONTROL_MAX_COL_OFFSET 10
#define FRAME_BUFFER_CONTROL_BUFFER_ID_OFFSET 12
#define FRAME_BUFFER_CONTROL_DATA_OFFSET 13
#define FRAME_BUFFER_CONTROL_FREE_MEMORY_OFFSET (13+FBC_MAX_DATA_PATTERN_LEN)
#define FRAME_BUFFER_CONTROL_IMG_MAX_WIDTH_OFFSET (15+FBC_MAX_DATA_PATTERN_LEN)
#define FRAME_BUFFER_CONTROL_IMG_MAX_HEIGHT_OFFSET (16+FBC_MAX_DATA_PATTERN_LEN)
#define FRAME_BUFFER_CONTROL_IMG_NUM_IMGS_OFFSET (17+FBC_MAX_DATA_PATTERN_LEN)
#define FRAME_BUFFER_CONTROL_IMG_DATA_OFFSET (18+FBC_MAX_DATA_PATTERN_LEN)
#define FRAME_BUFFER_CONTROL_LOAD 0x01
#define FRAME_BUFFER_CONTROL_REMOVE 0x02
#define FRAME_BUFFER_CONTROL_CLEAR 0x04
#define FRAME_BUFFER_CONTROL_START 0x08
#define FRAME_BUFFER_CONTROL_STOP 0x10
#define FRAME_BUFFER_CONTROL_RUNNING 0x80
#define EEPROM_FRAME_BUFFER_CONTROL_LENGTH 8
#define FRAME_BUFFER_CONTROL_PERIOD_OFFSET 0
#define FRAME_BUFFER_CONTROL_NUM_ROWS_OFFSET 2
#define FRAME_BUFFER_CONTROL_NUM_PIXELS_OFFSET 4
#define FRAME_BUFFER_CONTROL_NUM_BUFFERS_OFFSET 6
#ifndef DEFAULT_FRAME_BUFFER_CONTROL_PERIOD
#define DEFAULT_FRAME_BUFFER_CONTROL_PERIOD 0x0004
#endif
#ifndef DEFAULT_FRAME_BUFFER_CONTROL_NUM_ROWS
#define DEFAULT_FRAME_BUFFER_CONTROL_NUM_ROWS 0x0004
#endif
#ifndef DEFAULT_FRAME_BUFFER_CONTROL_NUM_PIXELS
#define DEFAULT_FRAME_BUFFER_CONTROL_NUM_PIXELS 0x0030
#endif
#ifndef DEFAULT_FRAME_BUFFER_CONTROL_NUM_BUFFERS
#define DEFAULT_FRAME_BUFFER_CONTROL_NUM_BUFFERS 0x0001
#endif
#define frame_buffer_control_eeprom_data(name,section_name,base_address) \
unsigned short int name##_eeprom_data[] __attribute__ ((section (section_name)))={DEFAULT_FRAME_BUFFER_CONTROL_PERIOD&0x00FF,base_address+FRAME_BUFFER_CONTROL_PERIOD_OFFSET, \
(DEFAULT_FRAME_BUFFER_CONTROL_PERIOD>>8)&0x00FF,base_address+FRAME_BUFFER_CONTROL_PERIOD_OFFSET+1, \
DEFAULT_FRAME_BUFFER_CONTROL_NUM_ROWS&0x00FF,base_address+FRAME_BUFFER_CONTROL_NUM_ROWS_OFFSET, \
(DEFAULT_FRAME_BUFFER_CONTROL_NUM_ROWS>>8)&0x00FF,base_address+FRAME_BUFFER_CONTROL_NUM_ROWS_OFFSET+1, \
DEFAULT_FRAME_BUFFER_CONTROL_NUM_PIXELS&0x00FF,base_address+FRAME_BUFFER_CONTROL_NUM_PIXELS_OFFSET, \
(DEFAULT_FRAME_BUFFER_CONTROL_NUM_PIXELS>>8)&0x00FF,base_address+FRAME_BUFFER_CONTROL_NUM_PIXELS_OFFSET+1, \
DEFAULT_FRAME_BUFFER_CONTROL_NUM_BUFFERS&0x00FF,base_address+FRAME_BUFFER_CONTROL_NUM_BUFFERS_OFFSET, \
(DEFAULT_FRAME_BUFFER_CONTROL_NUM_BUFFERS>>8)&0x00FF,base_address+FRAME_BUFFER_CONTROL_NUM_BUFFERS_OFFSET+1};
#endif
#ifndef _FRAME_BUFFER_REGISTERS_H
#define _FRAME_BUFFER_REGISTERS_H
#ifndef RAM_FB_BASE_ADDRESS
#define RAM_FB_BASE_ADDRESS ((unsigned short int)0x0000)
#endif
#define RAM_FB_LENGTH 2
#define FB_FREE_MEMORY (RAM_FB_BASE_ADDRESS)
#ifndef EEPROM_FB_BASE_ADDRESS
#define EEPROM_FB_BASE_ADDRESS ((unsigned short int)0x0000)
#endif
#define EEPROM_FB_LENGTH 6
#define FB_NUM_ROWS (EEPROM_FB_BASE_ADDRESS)
#define FB_NUM_PIXELS (EEPROM_FB_BASE_ADDRESS+2)
#define FB_NUM_BUFFERS (EEPROM_FB_BASE_ADDRESS+4)
#ifndef DEFAULT_FB_NUM_ROWS
#define DEFAULT_FB_NUM_ROWS 0x0004
#endif
#ifndef DEFAULT_FB_NUM_PIXELS
#define DEFAULT_FB_NUM_PIXELS 0x0030
#endif
#ifndef DEFAULT_FB_NUM_BUFFERS
#define DEFAULT_FB_NUM_BUFFERS 0x0001
#endif
#define frame_buffer_eeprom_data(name,section_name) \
unsigned short int name##_eeprom_data[] __attribute__ ((section (".section_nane")))={DEFAULT_FB_NUM_ROWS&0x00FF,FB_NUM_ROWS, \
(DEFAULT_FB_NUM_ROWS>>8)&0x00FF,FB_NUM_ROWS+1, \
DEFAULT_FB_NUM_PIXELS&0x00FF,FB_NUM_PIXELS, \
(DEFAULT_FB_NUM_PIXELS>>8)&0x00FF,FB_NUM_PIXELS+1, \
DEFAULT_FB_NUM_BUFFERS&0x00FF,FB_NUM_BUFFERS, \
(DEFAULT_FB_NUM_BUFFERS>>8)&0x00FF,FB_NUM_BUFFERS+1}; \
#endif
......@@ -2,25 +2,25 @@
#define IMAGE_PATTERNS_H
#include "patterns.h"
#include "memory.h"
#include "frame_buffer_control.h"
#ifndef MAX_NUM_IMAGES
#define MAX_NUM_IMAGES 1
#ifndef IMG_MAX_NUM_IMAGES
#error "Please, specify the maximum number of images with the IMG_MAX_NUM_IMAGES macro"
#endif
#ifndef MAX_IMAGE_WIDTH
#define MAX_IMAGE_WIDTH 15
#ifndef IMG_MAX_IMAGE_WIDTH
#error "Please, specify the maximum image width with the IMG_MAX_IMAGE_WIDTH macro"
#endif
#ifndef MAX_IMAGE_HEIGHT
#define MAX_IMAGE_HEIGHT 15
#ifndef IMG_MAX_IMAGE_HEIGHT
#error "Please, specify the maximum image height with the IMG_MAX_IMAGE_HEIGHT macro"
#endif
#include "image_patterns_registers.h"
#define IMAGE_GROUP 0x20
unsigned char img_patterns_init(TMemory *memory);
extern unsigned char img_pattern_data[IMG_MAX_NUM_IMAGES][IMG_MAX_IMAGE_WIDTH][IMG_MAX_IMAGE_HEIGHT][3];
void img_patterns_init(unsigned short int ram_base_address);
#pragma pack (push, 1)
typedef struct
......@@ -40,6 +40,6 @@ typedef struct
#define IMG_WF_INDEX_OFFSET 5
#define IMG_MTN_INDEX_OFFSET 6
void img_general(TLEDArea *area,TIMGDisplayData *pattern_data,unsigned short int period,unsigned char *buffer);
void img_general(TLEDArea *area,TIMGDisplayData *pattern_data,unsigned char buffer_id,unsigned short int period,TFBControl *control);
#endif
#ifndef _IMAGE_PATTERNS_REGISTERS_H
#define _IMAGE_PATTERNS_REGISTERS_H
#ifndef RAM_IMG_PATTERNS_BASE_ADDRESS
#define RAM_IMG_PATTERNS_BASE_ADDRESS ((unsigned short int)0x0000)
#endif
#define RAM_IMG_PATTERNS_LENGTH MAX_NUM_IMAGES*MAX_IMAGE_WIDTH*MAX_IMAGE_HEIGHT*3+3
#define IMG_PATTERNS_MAX_WIDTH (RAM_IMG_PATTERNS_BASE_ADDRESS)
#define IMG_PATTERNS_MAX_HEIGHT (RAM_IMG_PATTERNS_BASE_ADDRESS+1)
#define IMG_PATTERNS_NUM_IMGS (RAM_IMG_PATTERNS_BASE_ADDRESS+2)
#define IMG_PATTERNS_DATA (RAM_IMG_PATTERNS_BASE_ADDRESS+3)
#endif
#ifndef _LED_CONTROL_H
#define _LED_CONTROL_H
#ifdef __cplusplus
extern "C" {
#endif
#include "stm32f4xx.h"
#include "patterns.h"
#include "memory.h"
#ifndef MAX_PATTERN_FUNC
#define MAX_PATTERN_FUNC 16
#endif
#ifndef MAX_DATA_PATTERN_LEN
#define MAX_DATA_PATTERN_LEN 32
#endif
#include "led_control_registers.h"
typedef void (*pattern_func_t)(TLEDArea *area,void *pattern_data,uint16_t period,unsigned char *buffer);
typedef struct
{
unsigned char num_patterns;
pattern_func_t functions[MAX_PATTERN_FUNC];
TLEDArea area[MAX_PATTERN_FUNC];
unsigned char parameters[MAX_PATTERN_FUNC][MAX_DATA_PATTERN_LEN];
}TPatterns;
unsigned char led_control_init(TMemory *memory);
unsigned char led_control_add_pattern(pattern_func_t function,TLEDArea *area,void *data,unsigned char data_length);
void led_control_remove_pattern(unsigned char index);
void led_control_clear_patterns(void);
unsigned char led_control_get_num_patterns(void);
unsigned char *led_control_get_parameters(unsigned char index);
void led_control_loop(void);
#ifdef __cplusplus
}
#endif
#endif
#ifndef _LED_CONTROL_REGISTERS_H
#define _LED_CONTROL_REGISTERS_H
#ifndef RAM_LED_CONTROL_BASE_ADDRESS
#define RAM_LED_CONTROL_BASE_ADDRESS ((unsigned short int)0x0000)
#endif
#define RAM_LED_CONTROL_LENGTH 12+MAX_DATA_PATTERN_LEN
#define LED_CONTROL_NUM_PATTERN (RAM_LED_CONTROL_BASE_ADDRESS)
#define LED_CONTROL_PATTERN_INDEX (RAM_LED_CONTROL_BASE_ADDRESS+1)
#define LED_CONTROL (RAM_LED_CONTROL_BASE_ADDRESS+2)
#define LED_CONTROL_PATTERN_ID (RAM_LED_CONTROL_BASE_ADDRESS+3)
#define LED_CONTROL_MIN_ROW (RAM_LED_CONTROL_BASE_ADDRESS+4)
#define LED_CONTROL_MAX_ROW (RAM_LED_CONTROL_BASE_ADDRESS+6)
#define LED_CONTROL_MIN_COL (RAM_LED_CONTROL_BASE_ADDRESS+8)
#define LED_CONTROL_MAX_COL (RAM_LED_CONTROL_BASE_ADDRESS+10)
#define LED_CONTROL_DATA (RAM_LED_CONTROL_BASE_ADDRESS+12)
#define LED_CONTROL_LOAD 0x01
#define LED_CONTROL_REMOVE 0x02
#define LED_CONTROL_CLEAR 0x04
#endif
......@@ -2,16 +2,17 @@
#define _MOTION_PATTERNS_H
#include "patterns.h"
#include "frame_buffer_control.h"
#ifndef MTN_X_LED_SPACING
#define MTN_X_LED_SPACING 10
#error "Please, specify the LED spacing in mm in the X direction with the MTN_X_LED_SPACING macro"
#endif
#ifndef MTN_Y_LED_SPACING
#define MTN_Y_LED_SPACING 10
#error "Please, specify the LED spacing in mm in the Y direction with the MTN_Y_LED_SPACING macro"
#endif
#define MOTION_GROUP 0x30
#define MOTION_GROUP 0x30
typedef enum {MTN_RAMP=0x01,MTN_TRIANGLE=0x02,MTN_CIRCLE=0x03,MTN_NONE=0x04} mtn_id_t;
......@@ -68,7 +69,7 @@ typedef struct
#define MTN_CURRENT_COL_OFFSET 12
#define MTN_CURRENT_ROW_OFFSET 14
#define MTN_CURRENT_TIME_OFFSET 16
void mtn_general(TLEDArea *area,TMotion *pattern_data,unsigned short int period,unsigned char *buffer);
void mtn_general(TLEDArea *area,TMotion *pattern_data,unsigned char buffer_id,unsigned short int period,TFBControl *control);
void mtn_compute(TMotion *pattern_data);
......
......@@ -19,6 +19,4 @@ typedef struct
unsigned char B;
}TPixelRGB;
#endif
......@@ -2,6 +2,7 @@
#define WAVEFORM_PATTERNS_H
#include "patterns.h"
#include "frame_buffer_control.h"
#define WAVEFORM_GROUP 0x10
......@@ -59,7 +60,7 @@ typedef struct
#define WF_DATA_OFFSET 9
#define WF_ACTIVE 11
#define WF_CURRENT_PERIOD_OFFSET 12
void wf_general(TLEDArea *area,TWaveform *pattern_data,unsigned short int period,unsigned char *buffer);
void wf_general(TLEDArea *area,TWaveform *pattern_data,unsigned char buffer_id,unsigned short int period,TFBControl *control);
TPixelRGB wf_pixel(TWaveform *pattern_data);
......
#include "frame_buffer.h"
typedef enum {FB_SRAM1,FB_SRAM2} fb_segment_t;
typedef struct
{
TMemModule *mem_module;
TScheduler *scheduler;
unsigned short int num_rows;
unsigned short int num_pixels_per_row;
unsigned short int num_buffers;
unsigned short int buffer_size;
unsigned short int free_mem;
fb_segment_t read_current_segment;
unsigned char read_current_buffer;
fb_segment_t write_current_segment;
unsigned char write_current_buffer;
unsigned char buffer1[FB_MAX_BUFFER_LEN];
unsigned char buffer2[FB_MAX_BUFFER_LEN];
unsigned char pixel_buffer[FB_MAX_BUFFER_LEN/(FB_BYTES_PER_PIXEL/FB_BYTES_PER_PIXEL)];
}TFrameBuffer;
#include "frame_buffer_control_registers.h"
#include "ram.h"
// private functions
void fb_write_cmd(void *module,unsigned short int address,unsigned short int length,unsigned char *data)
{
TFrameBuffer *fb=(TFrameBuffer *)module;
unsigned short int new_value;
unsigned char *data_ptr;
if(ram_in_window(FB_NUM_ROWS,2,address,length))
{
new_value=fb->num_rows;
data_ptr=(unsigned char *)&new_value;
if(ram_in_range(FB_NUM_ROWS,address,length))
data_ptr[0]=data[FB_NUM_ROWS-address];
if(ram_in_range(FB_NUM_ROWS+1,address,length))
data_ptr[1]=data[FB_NUM_ROWS+1-address];
fb_set_num_rows(new_value);
}
if(ram_in_window(FB_NUM_PIXELS,2,address,length))
{
new_value=fb->num_pixels_per_row;
data_ptr=(unsigned char *)&new_value;
if(ram_in_range(FB_NUM_PIXELS,address,length))
data_ptr[0]=data[FB_NUM_PIXELS-address];
if(ram_in_range(FB_NUM_PIXELS+1,address,length))
data_ptr[1]=data[FB_NUM_PIXELS+1-address];
fb_set_pixels_per_row(new_value);
}
if(ram_in_window(FB_NUM_BUFFERS,2,address,length))
{
new_value=fb->num_buffers;
data_ptr=(unsigned char *)&new_value;
if(ram_in_range(FB_NUM_BUFFERS,address,length))
data_ptr[0]=data[FB_NUM_BUFFERS-address];
if(ram_in_range(FB_NUM_BUFFERS+1,address,length))
data_ptr[1]=data[FB_NUM_BUFFERS+1-address];
fb_set_num_buffers(new_value);
}
}
void fb_read_cmd(void *module,unsigned short int address,unsigned short int length,unsigned char *data)
void frame_buffer_compute_free_memory(TFrameBuffer *fb)
{
ram_read_table(address,length,data);
}
void fb_compute_free_memory(TFrameBuffer *fb)
{
leds_buffer_size=leds_num_rows*leds_num_pixels_per_row*FB_BYTES_PER_PIXEL+RESET_LENGTH;
leds_free_mem=MAX_BUFFER_LEN-leds_buffer_size*leds_num_buffers;
ram_data[FB_FREE_MEMORY]=leds_free_mem&0x00FF;
ram_data[FB_FREE_MEMORY+1]=(leds_free_mem&0xFF00)>>8;
}
void leds_write_buffer(TFrameBuffer *fb,unsigned char *pixel_buffer,unsigned char *led_buffer)
{
unsigned short int i,j,k,offset_pixel,offset_leds;
unsigned char pixel_g,pixel_r,pixel_b;
for(i=0;i<leds_num_rows;i++)
{
for(j=0;j<leds_num_pixels_per_row;j++)
{
offset_pixel=(i*leds_num_pixels_per_row+j)*BYTES_PER_PIXEL;
pixel_r=pixel_buffer[offset_pixel];
pixel_g=pixel_buffer[offset_pixel+1];
pixel_b=pixel_buffer[offset_pixel+2];
if(i%2)//odd
offset_leds=((i+1)*leds_num_pixels_per_row-1-j)*FB_BYTES_PER_PIXEL;
else//even
offset_leds=(i*leds_num_pixels_per_row+j)*FB_BYTES_PER_PIXEL;
for(k=0;k<4;k++)
{
if(pixel_g&(0x80>>(k*2)))
led_buffer[offset_leds+k]=0xC0;
else
led_buffer[offset_leds+k]=0x80;
if(pixel_g&(0x80>>((k*2)+1)))
led_buffer[offset_leds+k]|=0x0C;
else
led_buffer[offset_leds+k]|=0x08;
if(pixel_r&(0x80>>(k*2)))
led_buffer[offset_leds+(k+4)]=0xC0;
else
led_buffer[offset_leds+(k+4)]=0x80;
if(pixel_r&(0x80>>((k*2)+1)))
led_buffer[offset_leds+(k+4)]|=0x0C;
else
led_buffer[offset_leds+(k+4)]|=0x08;
if(pixel_b&(0x80>>(k*2)))
led_buffer[offset_leds+(k+8)]=0xC0;
else
led_buffer[offset_leds+(k+8)]=0x80;
if(pixel_b&(0x80>>((k*2)+1)))
led_buffer[offset_leds+(k+8)]|=0x0C;
else
led_buffer[offset_leds+(k+8)]|=0x08;
}
pixel_buffer[offset_pixel]=0x00;
pixel_buffer[offset_pixel+1]=0x00;
pixel_buffer[offset_pixel+2]=0x00;
}
}
}
void leds_write_reset(TFrameBuffer *fb,unsigned char *led_buffer)
{
unsigned short int i;
for(i=0;i<RESET_LENGTH;i++)
led_buffer[leds_num_rows*leds_num_pixels_per_row*FB_BYTES_PER_PIXEL+i]=0x00;
}
/* Interrupt handlers */
void leds_scheduler(void)
{
unsigned char *start_address;
/* switch to the next buffer*/
if(leds_spi_current_buffer>=leds_num_buffers)
{
leds_spi_current_buffer=0;
if(leds_spi_current_segment==FB_SRAM1)
{
leds_spi_current_segment=FB_SRAM2;
start_address=&leds_buffer2[0];
}
else