Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00018 #include "nrf24le1.h"
00019 #include <stdint.h>
00020
00021 #include <string.h>
00022 #include "nordic_common.h"
00023 #include "hal_delay.h"
00024 #include "lib_display.h"
00025
00026 #define DDRAM_ADR 0x80 // Write to DDRAM AC
00027 #define DDRAM_WR 0x40 // Write to DDRAM
00028 #define FUNC_SET 0x00 // Enter LCD Function settings
00029 #define LCD_ADDR 0x3E // LCD display adr
00030 #define JS_ADDR 0x3F // Joystick adr
00031
00032 #define X 0 // Contents in joystick array
00033 #define Y 1
00034
00035 void lcd_init(void)
00036 {
00037 hal_w2_configure_master(HAL_W2_400KHZ);
00038 delay_us(100);
00039
00040 lcd_set_instruction(0x38);
00041 lcd_set_instruction(0x39);
00042 lcd_set_instruction(0x14);
00043 lcd_set_contrast(LCD_CONTRAST_HIGH);
00044 lcd_set_instruction(0x5F);
00045
00046 lcd_set_instruction(0x6A);
00047 delay_ms(200);
00048
00049 lcd_on();
00050 lcd_clear();
00051 lcd_set_instruction(0x06);
00052 }
00053
00054 void lcd_write_string(char *text, uint8_t line, uint8_t pos)
00055 {
00056 char str[18];
00057 uint8_t buffer[2];
00058 uint8_t i;
00059
00060 if(line == 0)
00061 {
00062 line = 0x00;
00063 }
00064 else
00065 {
00066 line = 0x40;
00067 }
00068
00069 if(pos > 15) pos = 16;
00070
00071 buffer[0] = FUNC_SET;
00072 buffer[1] = DDRAM_ADR + (pos + line);
00073 hal_w2_write(LCD_ADDR, buffer, 2);
00074
00075 for(i=0;i<17;i++)
00076 {
00077 str[i+1] = text[i];
00078 }
00079 str[0] = DDRAM_WR;
00080 hal_w2_write(LCD_ADDR, (const uint8_t *)str, strlen(text) + 1);
00081 }
00082
00083 void lcd_clear(void)
00084 {
00085 uint8_t buffer[2];
00086
00087 delay_ms(10);
00088 buffer[0] = FUNC_SET;
00089 buffer[1] = 0x01;
00090 hal_w2_write(LCD_ADDR, buffer, 2);
00091 delay_ms(10);
00092 }
00093
00094 void lcd_set_contrast(lib_nrf6350_lcd_contrast_t contrast)
00095 {
00096 uint8_t buffer[2];
00097
00098 delay_ms(10);
00099 buffer[0] = FUNC_SET;
00100 buffer[1] = 0x70 | contrast;
00101 hal_w2_write(LCD_ADDR, buffer, 2);
00102 delay_ms(10);
00103 }
00104
00105 void lcd_set_instruction(uint8_t instr)
00106 {
00107 uint8_t buffer[2];
00108
00109 delay_ms(10);
00110 buffer[0] = FUNC_SET;
00111 buffer[1] = instr;
00112 hal_w2_write(LCD_ADDR, buffer, 2);
00113 delay_ms(10);
00114 }
00115
00116 void lcd_on(void)
00117 {
00118 uint8_t buffer[2];
00119
00120 delay_ms(10);
00121 buffer[0] = FUNC_SET;
00122 buffer[1] = 0x0C;
00123 hal_w2_write(LCD_ADDR, &buffer[0], 2);
00124 delay_ms(10);
00125 }
00126
00127 void lcd_off(void)
00128 {
00129 uint8_t buffer[2];
00130
00131 delay_ms(10);
00132 buffer[0] = FUNC_SET;
00133 buffer[1] = 0x08;
00134 hal_w2_write(LCD_ADDR, buffer, 2);
00135 delay_ms(10);
00136 }
00137
00138 void js_get_value(int8_t *val)
00139 {
00140 uint8_t js_data;
00141 uint8_t rx_buffer[1];
00142
00143 hal_w2_read(JS_ADDR, rx_buffer, 1);
00144 js_data = (~rx_buffer[0] & 0x1D);
00145
00146 if((js_data & BIT_0) == BIT_0)
00147 {
00148 val[X] = -1;
00149 }
00150 else if((js_data & BIT_4) == BIT_4)
00151 {
00152 val[X] = 1;
00153 }
00154 else
00155 {
00156 val[X] = 0;
00157 }
00158
00159 if((js_data & BIT_2) == BIT_2)
00160 {
00161 val[Y] = 1;
00162 }
00163 else if((js_data & BIT_3) == BIT_3)
00164 {
00165 val[Y] = -1;
00166 }
00167 else
00168 {
00169 val[Y] = 0;
00170 }
00171 }
00172
00173 bool js_button_pushed(void)
00174 {
00175 uint8_t js_data;
00176 uint8_t rx_buffer[1];
00177
00178 hal_w2_read(JS_ADDR, rx_buffer, 1);
00179 js_data = (~rx_buffer[0] & BIT_1);
00180
00181 return (js_data == BIT_1);
00182 }
00183
00184 lib_display_js_states_t js_get_status()
00185 {
00186 uint8_t js_data;
00187
00188 hal_w2_read(JS_ADDR, &js_data, 1);
00189 js_data = ~js_data;
00190 if( js_data & 0x02 ) return JS_BUTTON_PUSH;
00191 if( js_data & 0x01 ) return JS_BUTTON_LEFT;
00192 if( js_data & 0x10 ) return JS_BUTTON_RIGHT;
00193 if( js_data & 0x08 ) return JS_BUTTON_UP;
00194 if( js_data & 0x04 ) return JS_BUTTON_DOWN;
00195 return JS_BUTTON_NONE;
00196 }