summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Hodder <dave.hodder@focusrite.com>2016-02-12 18:06:50 +0000
committerDave Hodder <dave.hodder@focusrite.com>2016-02-12 18:06:50 +0000
commit167a7dc6a753b5ba11c8c2ae2a365cec8656c171 (patch)
treeab89dcb74260171628ef12dce11f1ba6f8c64391
parent6edc776b3d0a33c1b59ed29d66570cc8b5bc74e2 (diff)
downloadlaunchpad-polymaker-167a7dc6a753b5ba11c8c2ae2a365cec8656c171.tar.gz
launchpad-polymaker-167a7dc6a753b5ba11c8c2ae2a365cec8656c171.zip
single-page flash storage
-rw-r--r--include/app.h36
-rw-r--r--include/app_defs.h7
-rw-r--r--lib/launchpad_pro.abin16867198 -> 16872946 bytes
-rw-r--r--src/app.c38
-rw-r--r--tools/simulator.c10
5 files changed, 82 insertions, 9 deletions
diff --git a/include/app.h b/include/app.h
index ed946d5..c26c131 100644
--- a/include/app.h
+++ b/include/app.h
@@ -43,7 +43,7 @@
43 43
44/****************************************************************************** 44/******************************************************************************
45 Button indexing is as follows - numbers in brackets do not correspond to real 45 Button indexing is as follows - numbers in brackets do not correspond to real
46buttons, but can be harmessly sent in hal_set_led. 46 buttons, but can be harmessly sent in hal_set_led.
47 47
48 (90)91 92 93 94 95 96 97 98 (99) 48 (90)91 92 93 94 95 96 97 98 (99)
49 ....... 49 .......
@@ -92,6 +92,40 @@ void hal_send_midi(u8 port, u8 status, u8 data1, u8 data2);
92 */ 92 */
93void hal_send_sysex(u8 port, const u8* data, u16 length); 93void hal_send_sysex(u8 port, const u8* data, u16 length);
94 94
95/**
96 * Read some data from flash.
97 *
98 * Flash storage is in a single block, currently corresponding to one page.
99 * The block is always USER_AREA_SIZE bytes long. You can read/write any bytes
100 * within it - you do not need to worry about paging, that's handled by the HAL.
101 *
102 * The block size may increase to span multiple pages in future :)
103 *
104 * @param offset - how far into the USER_AREA_SIZE byte block to start reading
105 * @param data - buffer to receive data (must be at least length bytes long)
106 * @param length - bytes to read
107 *
108 * Attempts to read beyond the end of the block will fail silently.
109 *
110 * Note that your first ever read from a new device will contain 0xFF's until
111 * you overwrite them.
112 */
113void hal_read_flash(u32 offset, u8 *data, u32 length);
114
115/**
116 * Write data to flash
117 *
118 * Do take care to avoid thrashing it, as you can wear it out with excessive
119 * writes. The HAL does not currently do anything clever to mitigate this.
120 *
121 * @param offset - how far into the USER_AREA_SIZE byte block to start writing
122 * @param data - buffer to write (must be at least length bytes long)
123 * @param length - bytes to write
124 *
125 * Attempts to write beyond the end of the block will fail silently
126 */
127void hal_write_flash(u32 offset,const u8 *data, u32 length);
128
95// ____________________________________________________________________________ 129// ____________________________________________________________________________
96// 130//
97// Callbacks from the hardware (implemented in your app.c) 131// Callbacks from the hardware (implemented in your app.c)
diff --git a/include/app_defs.h b/include/app_defs.h
index 829f8a6..7a3efa1 100644
--- a/include/app_defs.h
+++ b/include/app_defs.h
@@ -100,5 +100,12 @@ typedef unsigned char u8;
100#define MIDI_OUT_CABLE 1 100#define MIDI_OUT_CABLE 1
101 101
102// ____________________________________________________________________________ 102// ____________________________________________________________________________
103//
104// Flash storage
105// ____________________________________________________________________________
106
107#define USER_AREA_SIZE 1024
108
109// ____________________________________________________________________________
103 110
104#endif 111#endif
diff --git a/lib/launchpad_pro.a b/lib/launchpad_pro.a
index 347b65e..907c72a 100644
--- a/lib/launchpad_pro.a
+++ b/lib/launchpad_pro.a
Binary files differ
diff --git a/src/app.c b/src/app.c
index f0edec8..e250cd3 100644
--- a/src/app.c
+++ b/src/app.c
@@ -41,6 +41,15 @@
41// 41//
42// This is where the fun is! Add your code to the callbacks below to define how 42// This is where the fun is! Add your code to the callbacks below to define how
43// your app behaves. 43// your app behaves.
44//
45// In this example, we store all button states in an array, which we sometimes
46// save to flash.
47//______________________________________________________________________________
48
49#define BUTTON_COUNT 100
50
51u8 g_Buttons[BUTTON_COUNT] = {0};
52
44//______________________________________________________________________________ 53//______________________________________________________________________________
45 54
46void app_surface_event(u8 type, u8 index, u8 value) 55void app_surface_event(u8 type, u8 index, u8 value)
@@ -49,16 +58,28 @@ void app_surface_event(u8 type, u8 index, u8 value)
49 { 58 {
50 case TYPEPAD: 59 case TYPEPAD:
51 { 60 {
52 // example - light / extinguish pad LEDs, send MIDI 61 // toggle it and store it off, so we can save to flash if we want to
53 hal_plot_led(TYPEPAD, index, value, value, value); 62 if (value)
63 {
64 g_Buttons[index] = MAXLED * !g_Buttons[index];
65 }
66
67 // example - light / extinguish pad LEDs
68 hal_plot_led(TYPEPAD, index, 0, 0, g_Buttons[index]);
69
70 // example - send MIDI
54 hal_send_midi(DINMIDI, NOTEON | 0, index, value); 71 hal_send_midi(DINMIDI, NOTEON | 0, index, value);
72
55 } 73 }
56 break; 74 break;
57 75
58 case TYPESETUP: 76 case TYPESETUP:
59 { 77 {
60 // example - light the setup LED 78 if (value)
61 hal_plot_led(TYPESETUP, 0, value, value, value); 79 {
80 // save button states to flash (reload them by power cycling the hardware!)
81 hal_write_flash(0, g_Buttons, BUTTON_COUNT);
82 }
62 } 83 }
63 break; 84 break;
64 } 85 }
@@ -137,16 +158,17 @@ void app_timer_event()
137 158
138void app_init() 159void app_init()
139{ 160{
161 // example - load button states from flash
162 hal_read_flash(0, g_Buttons, BUTTON_COUNT);
163
140 // example - light the LEDs to say hello! 164 // example - light the LEDs to say hello!
141 for (int i=0; i < 10; ++i) 165 for (int i=0; i < 10; ++i)
142 { 166 {
143 for (int j=0; j < 10; ++j) 167 for (int j=0; j < 10; ++j)
144 { 168 {
145 u8 r = i < 5 ? (MAXLED * (5-i))/5 : 0; 169 u8 b = g_Buttons[j*10 + i];
146 u8 g = i < 5 ? (MAXLED * i)/5 : (MAXLED * (10-i))/5;
147 u8 b = i < 5 ? 0 : (MAXLED * (i-5))/5;
148 170
149 hal_plot_led(TYPEPAD, j*10 + i, r, b, g); 171 hal_plot_led(TYPEPAD, j*10 + i, 0, 0, b);
150 } 172 }
151 } 173 }
152} 174}
diff --git a/tools/simulator.c b/tools/simulator.c
index 56298d7..0df95ab 100644
--- a/tools/simulator.c
+++ b/tools/simulator.c
@@ -57,6 +57,16 @@ void hal_send_sysex(u8 port, const u8* data, u16 length)
57 printf("...hal_send_midi(%d, (data), %d);\n", port, length); 57 printf("...hal_send_midi(%d, (data), %d);\n", port, length);
58} 58}
59 59
60void hal_read_flash(u32 offset, u8 *data, u32 length)
61{
62 printf("...hal_read_flash(%d, (data), %d);\n", offset, length);
63}
64
65void hal_write_flash(u32 offset,const u8 *data, u32 length)
66{
67 printf("...hal_write_flash(%d, (data), %d);\n", offset, length);
68}
69
60// ____________________________________________________________________________ 70// ____________________________________________________________________________
61// 71//
62// App event wrappers - these just log to the console. Would be nice to wire 72// App event wrappers - these just log to the console. Would be nice to wire