Renesas GR-Peach LCD Interface
Dependencies: EthernetInterface HTTPD PubNub SDFileSystem mbed-rtos mbed picojson
Renesas GR-Peach LCD Interface
Revision 0:0b32d3eaabfe, committed 2015-10-23
- Comitter:
- nikhilchaturtvedi
- Date:
- Fri Oct 23 20:16:05 2015 +0000
- Commit message:
- Renesas LCD Interface
Changed in this revision
diff -r 000000000000 -r 0b32d3eaabfe EthernetInterface.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetInterface.lib Fri Oct 23 20:16:05 2015 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/nikhilchaturtvedi/code/EthernetInterface/#719630f9c955
diff -r 000000000000 -r 0b32d3eaabfe HTTPD.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HTTPD.lib Fri Oct 23 20:16:05 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/okini3939/code/HTTPD/#d18dff347122
diff -r 000000000000 -r 0b32d3eaabfe PubNub.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PubNub.lib Fri Oct 23 20:16:05 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/PubNub/code/PubNub/#c9f79982b5ca
diff -r 000000000000 -r 0b32d3eaabfe SDFileSystem.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Fri Oct 23 20:16:05 2015 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/nikhilchaturtvedi/code/SDFileSystem/#3b77a0193dbc
diff -r 000000000000 -r 0b32d3eaabfe gen_helper.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gen_helper.h Fri Oct 23 20:16:05 2015 +0000 @@ -0,0 +1,108 @@ +#ifndef _GEN_HELPER_H_ +#define _GEN_HELPER_H_ + +#include "mbed.h" +#include "SDFileSystem.h" + +/* Helper class for drawing onto LCD over SPI*/ + +/*#defines for screen settings and color - based on Adafruit definitions*/ +#define SW_RESET 0x01 +#define AWAKE_SLEEPMODE 0x11 +#define NORMAL_DISP_ON 0x13 +#define INVOFF 0x20 +#define DISPLAY_ON 0x29 +#define COLUMN_ADDR_SET 0x2A +#define ROW_ADDR_SET 0x2B +#define WRITE_RAM 0x2C +#define COLOR_MODE 0x3A +#define ORIENTATION 0x36 +#define FRAMERATE_NORMAL 0xB1 +#define FRAMERATE_IDLE 0xB2 +#define FRAMERATE_PARTIAL 0xB3 +#define INVERTED_MODE_OFF 0xB4 +#define POWER_CONTROL_1 0xC0 +#define POWER_CONTROL_2 0xC1 +#define POWER_CONTROL_3 0xC2 +#define POWER_CONTROL_4 0xC3 +#define POWER_CONTROL_5 0xC4 +#define POWER_CONTROL_6 0xC5 + +//Screen dimensions +#define SCREEN_HEIGHT 160 +#define SCREEN_WIDTH 120 + + +// Color definitions +#define BLACK 0x0000 +#define BLUE 0x001F +#define RED 0xF800 +#define GREEN 0x07E0 +#define CYAN 0x07FF +#define MAGENTA 0xF81F +#define YELLOW 0xFFE0 +#define WHITE 0xFFFF +#define SKYBLUE 0x6AFFD8 +#define BROWN 0x8B5436 + +//hardcoded definitions for testing +#define HOST_IP_ADDR "143.103.6.188" +#define HOST_GATEWAY "143.103.6.254" +#define HOST_SUBNET "255.255.255.0" +#define HOST_PORT 80 + +class gen_helper +{ + +public: + + /* LCD function declarations */ + int spiwrite(uint8_t c); + void write_spi_command(uint8_t c); + void write_spi_data(uint8_t c); + void draw_pixel(int16_t x, int16_t y, uint16_t color); + void lcd_init(); + void fill_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint32_t color); + void write_rgb(uint32_t color, uint32_t repeat); + void draw_vertical_line(int16_t x, int16_t y, int16_t h, uint16_t color); + void draw_horizontal_line(int16_t x, int16_t y, int16_t w, uint16_t color); + void set_screen_coor(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1); + void init_console(); + void rotate_line(float x1, float y1, float x2, float y2, uint16_t alpha, float *X, float *Y); + void massaged_line(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, float lambda, uint16_t colour, uint16_t *X, uint16_t *Y); + void drawLine(int16_t x0, int16_t y0,int16_t x1, int16_t y1,uint16_t color); + void draw_pattern_helper(); + void draw_custom_pattern(int x0, int y0, int x1, int y1); + void draw_pattern(int x1, int y1, int x2, int y2); + + /* SD card function declarations */ + uint8_t init_disk(); + uint8_t make_dir(char *path, uint32_t mode); + FILE* open_file(char *path, char *mode); + uint8_t close_file(FILE *fp); + uint8_t init_SD(); + uint8_t remove_file(char *path); + + void decrease_screen_brightness(float); + void increase_screen_brightness(float); + + /* CTOR ; Use the list of pins supported at https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-rev_B-version-information*/ + gen_helper(PinName MOSI, PinName MISO, PinName SCK, PinName CS, PinName Reset, PinName RS, PinName _USBTX, PinName _USBRX, PwmOut pwm); + + PwmOut pwm; //Backlite pin. need to be a private member and have get/set functions + +private: + SPI lcd; /* SPI0 - MOSI, MISO, SCK P10_14, P10_15, P10_12 */ + DigitalOut ssel; // Chip select P10_13 + DigitalOut reset; // Reset signal P3_15 + DigitalOut rs; // Register select P3_14; Problem with rs pin fixed. + Serial console; //write to the console using serial comm + SDFileSystem *sd_fs; //SD card file system instance + + uint8_t colstart; + uint8_t rowstart; + uint8_t _height; //height of the lcd display + uint8_t _width; //width of the lcd display + +}; +#endif \ No newline at end of file
diff -r 000000000000 -r 0b32d3eaabfe lcd_main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lcd_main.cpp Fri Oct 23 20:16:05 2015 +0000 @@ -0,0 +1,647 @@ +#include "gen_helper.h" +#include "math.h" + + +/* An SPI Master for interfacing and handling an LCD Slave with GR-Peach */ + + +/* Variables for holding previously drawn co-ordinate values */ +int x_left = 0; //holder for the last updated x co-ordinate value for the left side +int y_left = 0; //holder for the last updated y co-ordinate value for the left side +int x_right = 0; //holder for the last updated x co-ordinate value for the right side +int y_right = 0; //holder for the last updated y co-ordinate value for the right side + +//The number of the levels for the tree. +//This is declared here for ease of change in any function and reset it to +//the original value after use. +int number_levels = 0; + +gen_helper::gen_helper(PinName MOSI, PinName MISO, PinName SCK, PinName CS, PinName Reset, PinName RS, PinName _USBTX, PinName _USBRX, PwmOut _pwm) : + lcd(MOSI, MISO, SCK), ssel(CS), reset(Reset), rs(RS), console(_USBTX, _USBRX), pwm(_pwm) +{ + _height = SCREEN_HEIGHT; + _width = SCREEN_WIDTH; +} + + +/* Init console by setting the baud rate */ + +void gen_helper::init_console() +{ + //init serial over USB here + console.baud(115200); + console.printf("Console init done\n"); +} + +/** + * Draws a line by a factor of lambda value + *(x0,y0) are initial co-ordinates and (x1,y1) are the end co-ordinates + + * x0 - starting x co-ordinate value + * y0 - starting y co-ordinate value + * x1 - end x co-ordinate value + * y1 - end y co-ordinate value + * lambda - the factor that decides the length of the resulting line segment + */ +void gen_helper::massaged_line(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, float lambda, uint16_t colour, uint16_t *X, uint16_t *Y) +{ + *X = (uint16_t)(x0 + (lambda * (x1 - x0))); + *Y = (uint16_t)(y0 + (lambda * (y1 - y0))); +} + + +/** + * rotate (x2,y2) around (x1,y1) by alpha degrees + * combines rotation and translation also. + + * x1 - starting x co-ordinate + * y1 - starting y co-ordinate + * x2 - end x co-ordinate + * y2 - end y co-ordinate + * alpha - the degree of rotation required + */ +void gen_helper::rotate_line(float x1, float y1, float x2, float y2, uint16_t alpha, float *X, float *Y) +{ + float radian = (3.1415 * alpha / 180); + *X = (x2 - x1) * cosf(radian) - (y2 - y1) * sinf(radian) + x1; + *Y = (y2 - y1) * cosf(radian) + (x2 - x1) * sinf(radian) + y1; +} + + +/** + * Draw a line with the init and end co-ordinates + * (x0, y0) - start co-ordinates + * (x1, y1) - end co-ordinates + * color - color of the line + * Based on the ST7735 source +*/ +void gen_helper::drawLine(int16_t x0, int16_t y0,int16_t x1, int16_t y1,uint16_t color) +{ + int16_t x, y; + float slope; + + //check for slope conditions + if( (x0 != x1) && (y0 != y1) ) + { + slope = (y1 - y0) / (x1 - x0); + + if (abs(slope) < 1) + { + for(x = x0; x < x1 + 1; x++) + { + y = (x - x0) * slope + y0; + draw_pixel(x, (y + 0.5), color); + } + } + else + { + for(y = y0; y < y1 + 1; y++) + { + x = (y - y0) / slope + x0; + draw_pixel((x + 0.5), y, color); + } + } + } +} + +/** + * A helper function which is flexible enough to be + * given any pattern to be drawn on the LCD + * initial values are (20,0) and (20,20) and the number of levels in 7 + */ +void gen_helper::draw_pattern_helper() +{ + int first_x0 = 20; + int first_y0 = 0; + int first_x1 = 20; + int first_y1 = 20; + //set the number of levels of the tree to 7 + number_levels = 7; + + //Draw the first tree + draw_custom_pattern(first_x0, first_y0, first_x1, first_y1); + + + //The second tree in the same plane + int next_tree_index = first_x0 + 30; + first_x0 = next_tree_index; + first_x1 = first_x0; + + draw_custom_pattern(first_x0, first_y0, first_x1, first_y1); + + //Third tree + next_tree_index += 30; + first_x0 = next_tree_index; + first_x1 = first_x0; + draw_custom_pattern(first_x0, first_y0, first_x1, first_y1); + + //Fourth tree + next_tree_index += 30; + first_x0 = next_tree_index; + first_x1 = first_x0; + draw_custom_pattern(first_x0, first_y0, first_x1, first_y1); + + //Fifth tree which starts at a much higher level than the previous trees + next_tree_index = 35; + first_x0 = next_tree_index; + first_x1 = first_x0; + first_y0+=20; + first_y1+=20; + draw_custom_pattern(first_x0, first_y0, first_x1, first_y1); + + //Sixth tree that is at the same level as fifth + next_tree_index = 65; + first_x0 = next_tree_index; + first_x1 = first_x0; + draw_custom_pattern(first_x0, first_y0, first_x1, first_y1); + + //Seventh tree that is at the same level as sixth + next_tree_index = 95; + first_x0 = next_tree_index; + first_x1 = first_x0; + draw_custom_pattern(first_x0, first_y0, first_x1, first_y1); + + + //Eighth tree at the same level as seventh + next_tree_index = 20; + first_x0 = next_tree_index; + first_x1 = first_x0; + first_y0 = 90; + first_y1 = first_y0 + 20; + number_levels = 3; + draw_custom_pattern(first_x0, first_y0, first_x1, first_y1); + + //Ninth tree at the same level as eight but with only 3 levels + next_tree_index = 50; + first_x0 = next_tree_index; + first_x1 = first_x0; + first_y0 = 90; + first_y1 = first_y0 + 20; + number_levels = 3; + draw_custom_pattern(first_x0, first_y0, first_x1, first_y1); + + //Tenth tree at the same level as ninth but with only 3 levels + next_tree_index = 80; + first_x0 = next_tree_index; + first_x1 = first_x0; + first_y0 = 90; + first_y1 = first_y0 + 20; + number_levels = 3; + draw_custom_pattern(first_x0, first_y0, first_x1, first_y1); + + //Eleventh tree at the same level as tenth but with only 3 levels + next_tree_index = 110; + first_x0 = next_tree_index; + first_x1 = first_x0; + first_y0 = 90; + first_y1 = first_y0 + 20; + number_levels = 3; + draw_custom_pattern(first_x0, first_y0, first_x1, first_y1); + +} + + +/** + * Draw the forest in any pattern that is desired with + * given two sets of start and end points + + * x0 - starting x co-ordinate value + * y0 - starting y co-ordinate value + * x1 - end x co-ordinate value + * y1 - end y co-ordinate value + * + */ +void gen_helper::draw_custom_pattern(int x0, int y0, int x1, int y1) +{ + int first_x0 = x0; + int first_y0 = y0; + int first_x1 = x1; + int first_y1 = y1; + int temp_leftx = 0; + int temp_lefty = 0; + int temp_rightx = 0; + int temp_righty = 0; + int r_temp_leftx = 0; + int r_temp_lefty = 0; + int r_temp_rightx = 0; + int r_temp_righty = 0; + + //draw the initial trunk of the tree and the next vertical branch that is + //a shrunken version of the trunk + drawLine(first_x0, first_y0, first_x1, first_y0+10, BLACK); + drawLine(first_x0+1, first_y0, first_x1+1, first_y0+10, BLACK); + draw_pattern(first_x0, first_y0+10, first_x1, first_y1+10); + + + //The pattern for drawing the tree and hence the forest. + //This can be any pattern required. + temp_leftx = x_left; + temp_lefty = y_left; + temp_rightx = x_right; + temp_righty = y_right; + + r_temp_leftx = x_left; + r_temp_lefty = y_left; + r_temp_rightx = x_right; + r_temp_righty = y_right; + + + int i = 0; + for(i = 0; i < number_levels; i++) + { + draw_pattern(r_temp_leftx, r_temp_lefty, r_temp_leftx, r_temp_lefty+10); + draw_pattern(r_temp_rightx, r_temp_righty, r_temp_rightx, r_temp_righty+10); + r_temp_leftx = x_left; + r_temp_lefty = y_left; + r_temp_rightx = x_right; + r_temp_righty = y_right; + } + + i = 0; + for(i = 0; i < number_levels; i++) + { + draw_pattern(temp_rightx, temp_righty, temp_rightx, temp_righty+10); + draw_pattern(temp_leftx, temp_lefty, temp_leftx, temp_lefty+10); + temp_leftx = x_left; + temp_lefty = y_left; + temp_rightx = x_right; + temp_righty = y_right; + } + +} + + +/** + * + * x1 - starting x co-ordinate value + * y1 - starting y co-ordinate value + * x2 - end x co-ordinate value + * y2 - end y co-ordinate value + */ +void gen_helper::draw_pattern(int x1, int y1, int x2, int y2) +{ + + int first_x0 = x1; + int first_y0 = y1; + int first_x1 = x2; + int first_y1 = y2; + int alpha = 30; + int neg_alpha = -30; + + + float x0=0, y0=0; + + rotate_line(first_x0, first_y0, first_x1, first_y1, alpha, &x0, &y0); + + drawLine(first_x0, first_y0, (int)x0, (int)y0, GREEN); + + x_right = (int)x0; + y_right = (int)y0; + + x0 = 0; + y0 = 0; + + rotate_line(first_x0, first_y0, first_x1, first_y1, neg_alpha, &x0, &y0); + drawLine(first_x0, first_y0, (int)(x0+3), (int)y0, GREEN); + + x_left = (int)x0+3; + y_left = (int)y0; + + +} + +/********* SD card helper functions; wrappers over the SD card file system ********/ +uint8_t gen_helper::init_disk() +{ + return sd_fs->disk_initialize(); +} + +/** +* Initialize the SD card +*/ +uint8_t gen_helper::init_SD() +{ + sd_fs = new SDFileSystem(P8_5, P8_6, P8_3, P8_4, "sd"); + + if(sd_fs) + return (uint8_t)0; //force a casting + else + return (uint8_t)-1; +} + +/** +* Open a file and return the file descriptor +*/ +FILE* gen_helper::open_file(char *path, char *mode) +{ + return fopen(path, mode); +} + +uint8_t gen_helper::close_file(FILE *fp) +{ + return fclose(fp); +} + +uint8_t gen_helper::make_dir(char *path, uint32_t mode) +{ + return mkdir(path, mode); +} + +uint8_t gen_helper::remove_file(char *path) +{ + return remove(path); +} +/****SD card function implementations end****/ + + +/* Initialize the LCD +* +*TODO : Check the row select and col select for Renesas GR-PEACH +* +* Based on the specs from ST7735 +*/ +void gen_helper::lcd_init() +{ + console.printf("Writing to the lcd \n"); + + lcd.format(8, 3); + //lcd.frequency(15000000); + ssel = 0; + reset = 1; + wait_ms(500); + reset = 0; + wait_ms(500); + reset = 1; + wait_ms(500); + + write_spi_command(SW_RESET); // SW Reset + wait_ms(150); + write_spi_command(AWAKE_SLEEPMODE); // Out of sleepmode + wait_ms(500); + + write_spi_command(FRAMERATE_NORMAL); // Frame rate in normal mode + write_spi_data(0x01); + write_spi_data(0x2C); + write_spi_data(0x2D); + + write_spi_command(FRAMERATE_IDLE); // Frame rate in idle mode + write_spi_data(0x01); + write_spi_data(0x2C); + write_spi_data(0x2D); + + write_spi_command(FRAMERATE_PARTIAL); // Frame rate in partial mode + write_spi_data(0x01); + write_spi_data(0x2C); + write_spi_data(0x2D); + write_spi_data(0x01); // inversion mode settings + write_spi_data(0x2C); + write_spi_data(0x2D); + + write_spi_command(INVERTED_MODE_OFF); // Inverted mode off + write_spi_data(0x07); + + write_spi_command(POWER_CONTROL_1); + write_spi_data(0xA2); + write_spi_data(0x02); + write_spi_data(0x84); + + write_spi_command(POWER_CONTROL_2); // POWER CONTROL 2 + write_spi_data(0xC5); + + write_spi_command(POWER_CONTROL_3); // POWER CONTROL 3 + write_spi_data(0x0A); + write_spi_data(0x00); + + write_spi_command(POWER_CONTROL_4); // POWER CONTROL 4 + write_spi_data(0x8A); + write_spi_data(0x2A); + + write_spi_command(POWER_CONTROL_5); // POWER CONTROL 5 + write_spi_data(0x8A); + write_spi_data(0xEE); + + write_spi_command(POWER_CONTROL_6); // POWER CONTROL 6 + write_spi_data(0x0E); + + write_spi_command(INVOFF); + + write_spi_command(ORIENTATION); // ORIENTATION + write_spi_data(0xC8); + + write_spi_command(COLOR_MODE); + write_spi_data(0x05); + + write_spi_command(COLUMN_ADDR_SET); + write_spi_data(0x00); + write_spi_data(0x00); + write_spi_data(0x00); + write_spi_data(0x7F); + + write_spi_command(ROW_ADDR_SET); // ROW ADDR SET + write_spi_data(0x00); + write_spi_data(0x00); + write_spi_data(0x00); + write_spi_data(0x9F); + + + write_spi_command(0xE0); + write_spi_data(0x02); + write_spi_data(0x1c); + write_spi_data(0x07); + write_spi_data(0x12); + write_spi_data(0x37); + write_spi_data(0x32); + write_spi_data(0x29); + write_spi_data(0x2d); + write_spi_data(0x29); + write_spi_data(0x25); + write_spi_data(0x2B); + write_spi_data(0x39); + write_spi_data(0x00); + write_spi_data(0x01); + write_spi_data(0x03); + write_spi_data(0x10); + write_spi_command(0xE1); + write_spi_data(0x03); + write_spi_data(0x1d); + write_spi_data(0x07); + write_spi_data(0x06); + write_spi_data(0x2E); + write_spi_data(0x2C); + write_spi_data(0x29); + write_spi_data(0x2D); + write_spi_data(0x2E); + write_spi_data(0x2E); + write_spi_data(0x37); + write_spi_data(0x3F); + write_spi_data(0x00); + write_spi_data(0x00); + write_spi_data(0x02); + write_spi_data(0x10); + + write_spi_command(DISPLAY_ON); // display ON + wait_ms(100); + + write_spi_command(NORMAL_DISP_ON); // normal display on + wait_ms(10); + + pwm.period_ms(2); + + // just increasing the brightness of the screen gradually + for(float i = 0.0f; i < 1.0f; i += 0.1f) + { + wait_ms(200); + pwm = i; + } + + console.printf("PWM done\n"); // here for debugging + +} + +inline int gen_helper::spiwrite(uint8_t c) +{ + return lcd.write(c); + +} + +/* Write command */ +void gen_helper::write_spi_command(uint8_t c) +{ + + rs = 0; + ssel = 0; + lcd.write(c); + ssel = 1; +} + +/* Write data */ +void gen_helper::write_spi_data(uint8_t c) +{ + + rs = 1; + ssel = 0; + lcd.write(c); + ssel = 1; + +} + +/** + * Based on ST7735 source ; sets the screen co-ordinates +*/ +void gen_helper::set_screen_coor(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) +{ + + write_spi_command(COLUMN_ADDR_SET); // Column addr set + write_spi_data(0x00); + write_spi_data(x0+colstart); // XSTART + write_spi_data(0x00); + write_spi_data(x1+colstart); // XEND + + write_spi_command(ROW_ADDR_SET); // Row addr set + write_spi_data(0x00); + write_spi_data(y0+rowstart); // YSTART + write_spi_data(0x00); + write_spi_data(y1+rowstart); // YEND + + write_spi_command(WRITE_RAM); // write to RAM +} + + +/** +* Draw a pixel on the screen +*/ +void gen_helper::draw_pixel(int16_t x, int16_t y, uint16_t color) { + + // exit if the co-ordinates are out of bounds of the screen + if((x < 0) ||(x >= _width) || (y < 0) || (y >= _height)) + return; + + set_screen_coor(x, y, x + 1, y + 1); + + rs = 1; + ssel = 0; + lcd.format(16,3); //set the data rate to 16 bits + lcd.write(color); + ssel = 1; + lcd.format(8,3); //set the data rate to 8 bits +} + +/** +* Draw a vertical line +* Based on ST7735 source +*/ +void gen_helper::draw_vertical_line(int16_t x, int16_t y, int16_t h, uint16_t color) +{ + + if((x >= _width) || (y >= _height)) + return; + + if((y + h - 1) >= _height) + h = _height - y; + + set_screen_coor(x, y, x, y + h - 1); + + uint8_t hi = color >> 8, lo = color; + while (h--) + { + spiwrite(hi); + spiwrite(lo); + } +} + +/** +* Draw a horizontal line +* Based on ST7735 source +*/ +void gen_helper::draw_horizontal_line(int16_t x, int16_t y, int16_t w, uint16_t color) +{ + + //check for screen boundary + if((x >= _width) || (y >= _height)) + return; + + if((x + w - 1) >= _width) + w = _width - x; + + set_screen_coor(x, y, x + w - 1, y); + + uint8_t hi = color >> 8, lo = color; + + while (w--) { + spiwrite(hi); + spiwrite(lo); + } +} + +/** +* Draw a rectangle and fill it with a color +*/ +void gen_helper::fill_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint32_t color) +{ + int16_t width, height; + + width = x1 - x0 + 1; + height = y1 - y0 + 1; + set_screen_coor(x0, y0, x1, y1); + write_spi_command(WRITE_RAM); + write_rgb(color, width * height); +} + +/** +* Write RGB colors to the screen +*/ +void gen_helper::write_rgb(uint32_t color, uint32_t repeat) { + + uint8_t red, green, blue; + int i; + red = (color >> 16); + green = (color >> 8) & 0xFF; + blue = color & 0xFF; + + for (i = 0; i< repeat; i++) + { + write_spi_data(red); + write_spi_data(green); + write_spi_data(blue); + } +} \ No newline at end of file
diff -r 000000000000 -r 0b32d3eaabfe main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Oct 23 20:16:05 2015 +0000 @@ -0,0 +1,151 @@ +#include "mbed.h" +#include "EthernetInterface.h" +#include "gen_helper.h" +#include "FATFileSystem.h" +#include "ff.h" +#include "SDFileSystem.h" + + +#define INCREASE_PWM_VALUE 0 +#define DECREASE_PWM_VALUE 1 +#define DRAW_ON_SCREEN 2 +#define FADE_SCREEN_AND_TURN_OFF 3 +#define INCREASE_SCREEN_BRIGHTNESS_TO_FULL 4 +#define SET_UP_SCREEN 5 + +/* Init connections */ +void init(); +void read_temperature(); + +Serial main_console(USBTX, USBRX); +SDFileSystem sd(P8_5, P8_6, P8_3, P8_4, "sd"); // SD card interface through SPI +SPI temp_sense(P4_6, P4_7, P4_4); +DigitalOut cs(P4_5); + +EthernetInterface ethInf; +TCPSocketServer server; +TCPSocketConnection* sock_connection; +gen_helper *helper; // Helper instance + +int main() +{ + main_console.printf("START\n"); + helper = new gen_helper(P10_14, P10_15, P10_12, P10_13, P3_15, P3_14, USBTX, USBRX, P4_6); + helper->init_console(); + helper->lcd_init(); + + main_console.printf("Starting connecting in V2 \n"); + + /* Init Eth on a static IP and gateway */ + ethInf.init(HOST_IP_ADDR, HOST_SUBNET, HOST_GATEWAY); + main_console.printf("Init eth\n"); + + ethInf.connect(); + main_console.printf("Connected eth\n"); + + /* Init the TCP server after init Ethernet */ + init(); + + return 0; //should never come here +} + +/* Start the eth interface and listen for incoming connections */ +void init() +{ + /* Bind this server to a specific port */ + main_console.printf("Binding\n"); + int bind_status = server.bind(HOST_PORT); + main_console.printf("Bound on port %d with status %d\n", HOST_PORT, bind_status); + + /* Listen on the port for incoming connections */ + int listen_status = server.listen(); + main_console.printf("Listen status %d\n", listen_status); + + /* Accept incoming connections */ + sock_connection = new TCPSocketConnection(); + int conn_accept_status = server.accept(*sock_connection); + main_console.printf("Connection accept status %d\n",conn_accept_status); + + char meta_data[1] = {'\0'}; // holds the command from the client + + while(1) + { + sock_connection->receive(meta_data, sizeof(meta_data)); + + switch((int)(meta_data[0] % 48)) { + + case INCREASE_PWM_VALUE: + main_console.printf("Increasing screen brightness\n"); + helper->pwm = helper->pwm + 0.1; + break; + + case DECREASE_PWM_VALUE: + main_console.printf("Decreasing screen brightness\n"); + helper->pwm = helper->pwm - 0.1; + break; + + case DRAW_ON_SCREEN: + //Divide the screen in two sections and fill them with different colours + /*helper->fill_rect(0, 0, 128, 120, BROWN); + helper->fill_rect(0, 120, 128, 160, SKYBLUE);*/ + + //Draw the pattern + //helper->draw_pattern_helper(); + break; + + case FADE_SCREEN_AND_TURN_OFF: + main_console.printf("Fading screen\n"); + + for(float i = 0.0f; i < 1.0f; i+=0.1f) + { + main_console.printf("i %f\n", i); + if(helper->pwm > 0.0f) + { + helper->pwm = helper->pwm - i; + wait(0.3); + } + } + + break; + + case INCREASE_SCREEN_BRIGHTNESS_TO_FULL: + + main_console.printf("Increasing screen brightness to full\n"); + + float cur_bright = helper->pwm; + + for(float i = 0.0f; i < (1.0f - cur_bright); i+=0.1f) + { + helper->pwm = helper->pwm + i; + wait(0.3); + } + + break; + + case SET_UP_SCREEN: + //helper->fill_rect(0, 0, 128, 160, WHITE); //Just fill the whole screen with a colour, in this case white. + break; + + default: + main_console.printf("Junk\n"); + break; + } + } +} + + +/* Testing the temp sensor in a continuous loop */ +void read_temperature() +{ + temp_sense.format(8, 3); //set SPI to 8-bit data rate + while(1) + { + cs = 1; + temp_sense.write(0x01); + int temp = temp_sense.write(0x02); + cs = 0; + main_console.printf("Temp %d\n", temp); + wait(0.5); + } + +} \ No newline at end of file
diff -r 000000000000 -r 0b32d3eaabfe mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Fri Oct 23 20:16:05 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#5aed8bae1001
diff -r 000000000000 -r 0b32d3eaabfe mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Oct 23 20:16:05 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/bad568076d81 \ No newline at end of file
diff -r 000000000000 -r 0b32d3eaabfe picojson.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/picojson.lib Fri Oct 23 20:16:05 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mimil/code/picojson/#2bb500b021e2