summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Hodder <dave.hodder@focusrite.com>2017-01-09 14:30:20 +0000
committerDave Hodder <dave.hodder@focusrite.com>2017-01-09 14:30:20 +0000
commit59d4f28fe214601d323b2e0fb8a272040ba02a37 (patch)
tree357ea0d743432d88e20f24168e8c2da6f1bfd7fe
parent50778f7bbb9ba2135df5e699521a61a83dcddbc6 (diff)
downloadlaunchpad-polymaker-59d4f28fe214601d323b2e0fb8a272040ba02a37.tar.gz
launchpad-polymaker-59d4f28fe214601d323b2e0fb8a272040ba02a37.zip
tidying up ADC api
-rw-r--r--include/app.h5
-rw-r--r--include/app_defs.h21
-rw-r--r--src/app.c31
3 files changed, 33 insertions, 24 deletions
diff --git a/include/app.h b/include/app.h
index 83ef48a..96801eb 100644
--- a/include/app.h
+++ b/include/app.h
@@ -133,6 +133,11 @@ void hal_write_flash(u32 offset,const u8 *data, u32 length);
133 133
134/** 134/**
135 * Called on startup, this is a good place to do any initialisation. 135 * Called on startup, this is a good place to do any initialisation.
136 *
137 * @param adc_buffer - this is a pointer to the raw ADC frame buffer. The
138 * data is 12 bit unsigned. Note the indexing is strange -
139 * translate ADC indices to LED/button indices using the
140 * ADC_MAP table declared in app_defs.h.
136 */ 141 */
137void app_init(const u16 *adc_buffer); 142void app_init(const u16 *adc_buffer);
138 143
diff --git a/include/app_defs.h b/include/app_defs.h
index 7a3efa1..d9b4311 100644
--- a/include/app_defs.h
+++ b/include/app_defs.h
@@ -107,5 +107,26 @@ typedef unsigned char u8;
107#define USER_AREA_SIZE 1024 107#define USER_AREA_SIZE 1024
108 108
109// ____________________________________________________________________________ 109// ____________________________________________________________________________
110//
111// Raw ADC reads. For technical reasons, the ADC layout is not the same as the
112// LED layout. Be sure to translate ADC values using the table below as you
113// need them!
114// ____________________________________________________________________________
115
116#define PAD_COUNT 64
117
118static const u8 ADC_MAP[PAD_COUNT] =
119{
120 11, 51, 12, 52, 13, 53, 14, 54,
121 15, 55, 16, 56, 17 ,57, 18, 58,
122 21, 61, 22, 62, 23, 63, 24, 64,
123 25, 65, 26, 66, 27, 67, 28, 68,
124 31, 71, 32, 72, 33, 73, 34, 74,
125 35, 75, 36, 76, 37, 77, 38, 78,
126 41, 81, 42, 82, 43, 83, 44, 84,
127 45, 85, 46, 86, 47, 87, 48, 88,
128};
129
130// ____________________________________________________________________________
110 131
111#endif 132#endif
diff --git a/src/app.c b/src/app.c
index 3499d58..d4db1f9 100644
--- a/src/app.c
+++ b/src/app.c
@@ -45,8 +45,6 @@
45// In this example, we render the raw ADC data as LED rainbows. 45// In this example, we render the raw ADC data as LED rainbows.
46//______________________________________________________________________________ 46//______________________________________________________________________________
47 47
48#define PAD_COUNT 64
49
50static const u16 *g_ADC = 0; 48static const u16 *g_ADC = 0;
51 49
52//______________________________________________________________________________ 50//______________________________________________________________________________
@@ -82,33 +80,18 @@ void app_cable_event(u8 type, u8 value)
82 80
83//______________________________________________________________________________ 81//______________________________________________________________________________
84 82
85static const u8 ADC_MAP[PAD_COUNT] =
86{
87 11, 51, 12, 52, 13, 53, 14, 54,
88 15, 55, 16, 56, 17 ,57, 18, 58,
89 21, 61, 22, 62, 23, 63, 24, 64,
90 25, 65, 26, 66, 27, 67, 28, 68,
91 31, 71, 32, 72, 33, 73, 34, 74,
92 35, 75, 36, 76, 37, 77, 38, 78,
93 41, 81, 42, 82, 43, 83, 44, 84,
94 45, 85, 46, 86, 47, 87, 48, 88,
95};
96
97
98void app_timer_event() 83void app_timer_event()
99{ 84{
100 // example: render raw ADC data as LEDs 85 // render raw ADC data as LEDs
101 for (int i=0; i < PAD_COUNT; ++i) 86 for (int i=0; i < PAD_COUNT; ++i)
102 { 87 {
103 // raw adc values are 12 bit, but LEDs are 6 bit. 88 // raw adc values are 12 bit, but LEDs are 6 bit.
104 // so saturate into r;g;b for a rainbow effect to show pressure 89 // Let's saturate into r;g;b for a rainbow effect to show pressure
105 u16 r =0; 90 u16 r = 0;
106 u16 g =0; 91 u16 g = 0;
107 u16 b =0; 92 u16 b = 0;
108
109 u16 x = g_ADC[i];
110 93
111 x = (3 * MAXLED * x) >> 12; 94 u16 x = (3 * MAXLED * g_ADC[i]) >> 12;
112 95
113 if (x < MAXLED) 96 if (x < MAXLED)
114 { 97 {
@@ -134,6 +117,6 @@ void app_timer_event()
134void app_init(const u16 *adc_raw) 117void app_init(const u16 *adc_raw)
135{ 118{
136 119
137 // example - store off the raw ADC frame pointer for later use 120 // store off the raw ADC frame pointer for later use
138 g_ADC = adc_raw; 121 g_ADC = adc_raw;
139} 122}