Phoenard
PHNSettings.h
Go to the documentation of this file.
1 /*
2 The MIT License (MIT)
3 
4 This file is part of the Phoenard Arduino library
5 Copyright (c) 2014 Phoenard
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 THE SOFTWARE.
24 */
25 
34 #include <avr/eeprom.h>
35 
36 #ifndef _PHN_SETTINGS_H_
37 #define _PHN_SETTINGS_H_
38 
39 /* Flags used for status eeprom values */
44 #define SETTINGS_LOAD 0x01
46 #define SETTINGS_LOADWIPE 0x02
48 #define SETTINGS_MODIFIED 0x04
50 #define SETTINGS_TOUCH_HOR_INV 0x08
52 #define SETTINGS_TOUCH_VER_INV 0x10
54 #define SETTINGS_CHANGED 0x80
56 
57 
59 typedef struct {
60  unsigned char touch_hor_a;
61  unsigned char touch_hor_b;
62  unsigned char touch_ver_a;
63  unsigned char touch_ver_b;
64  char sketch_toload[8];
65  char sketch_current[8];
66  unsigned long sketch_size;
67  unsigned char flags;
68 } PHN_Settings;
69 
70 /* Default Phoenard settings, used to restore corrupted or wiped EEPROM */
71 #define SETTINGS_DEFAULT_SKETCH {'S', 'K', 'E', 'T', 'C', 'H', 'E', 'S'}
72 #define SETTINGS_DEFAULT_FLAGS (SETTINGS_LOAD | SETTINGS_CHANGED | SETTINGS_TOUCH_HOR_INV)
73 #define SETTINGS_DEFAULT_TOUCH_HOR_A 100
74 #define SETTINGS_DEFAULT_TOUCH_HOR_B 100
75 #define SETTINGS_DEFAULT_TOUCH_VER_A 120
76 #define SETTINGS_DEFAULT_TOUCH_VER_B 120
77 
78 const PHN_Settings SETTINGS_DEFAULT = {
79  SETTINGS_DEFAULT_TOUCH_HOR_A, SETTINGS_DEFAULT_TOUCH_HOR_B,
80  SETTINGS_DEFAULT_TOUCH_VER_A, SETTINGS_DEFAULT_TOUCH_VER_B,
81  SETTINGS_DEFAULT_SKETCH, SETTINGS_DEFAULT_SKETCH, 0, SETTINGS_DEFAULT_FLAGS
82 };
83 
85 #define EEPROM_SIZE 4096
86 #define EEPROM_SETTINGS_SIZE sizeof(PHN_Settings)
88 #define EEPROM_SETTINGS_ADDR (EEPROM_SIZE - EEPROM_SETTINGS_SIZE)
90 #define EEPROM_SETTINGS_ADDR_FIELD(field) (const uint8_t*) (EEPROM_SETTINGS_ADDR+offsetof(PHN_Settings, field))
92 
94 #define PHN_Settings_Load(settings) eeprom_read_block( &settings, (void*) EEPROM_SETTINGS_ADDR, EEPROM_SETTINGS_SIZE)
95 #define PHN_Settings_Save(settings) eeprom_write_block(&settings, (void*) EEPROM_SETTINGS_ADDR, EEPROM_SETTINGS_SIZE)
97 #define PHN_Settings_LoadField(settings, field, size) eeprom_read_block(&settings.field, EEPROM_SETTINGS_ADDR_FIELD(field), size)
99 
101 void PHN_Settings_ReadCali(PHN_Settings settings, int *hor_a, int *hor_b, int *ver_a, int *ver_b);
103 void PHN_Settings_WriteCali(PHN_Settings *settings, int hor_a, int hor_b, int ver_a, int ver_b);
105 void PHN_loadSketch(const char* sketchName, bool loadNow = true);
106 
107 #endif
Structure holding the settings stored in EEPROM.
Definition: PHNSettings.h:59
void PHN_Settings_ReadCali(PHN_Settings settings, int *hor_a, int *hor_b, int *ver_a, int *ver_b)
Reads the screen calibration information from the settings.
Definition: PHNSettings.cpp:28
void PHN_loadSketch(const char *sketchName, bool loadNow=true)
Requests the bootloader to load a particular sketch.
Definition: PHNSettings.cpp:64
void PHN_Settings_WriteCali(PHN_Settings *settings, int hor_a, int hor_b, int ver_a, int ver_b)
Writes the screen calibration information to the settings.
Definition: PHNSettings.cpp:43