rb-blink1 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,83 @@
1
+ /*
2
+ * blink(1) C library --
3
+ *
4
+ * 2012, Tod E. Kurt, http://todbot.com/blog/ , http://thingm.com/
5
+ *
6
+ */
7
+
8
+
9
+ #ifndef __BLINK1_LIB_H__
10
+ #define __BLINK1_LIB_H__
11
+
12
+ #include <stdint.h>
13
+
14
+ #include "hidapi.h"
15
+ #include "usbconfig.h" // from firmware, for VID,PID,vendor name & product name
16
+
17
+ #ifdef __cplusplus
18
+ extern "C" {
19
+ #endif
20
+
21
+ #define blink1_max_devices 16
22
+
23
+
24
+ int blink1_vid(void);
25
+ int blink1_pid(void);
26
+ void blink1_sortPaths(void);
27
+ void blink1_sortSerials(void);
28
+
29
+ int blink1_enumerate();
30
+ int blink1_enumerateByVidPid(int vid, int pid);
31
+ const char* blink1_getCachedPath(int i);
32
+ const wchar_t* blink1_getCachedSerial(int i);
33
+ int blink1_getCachedCount(void);
34
+
35
+ hid_device* blink1_open(void);
36
+ hid_device* blink1_openByPath(const char* path);
37
+ hid_device* blink1_openBySerial(const wchar_t* serial);
38
+ hid_device* blink1_openById( int i );
39
+
40
+ void blink1_close( hid_device* dev );
41
+
42
+ int blink1_write( hid_device* dev, void* buf, int len);
43
+ int blink1_read( hid_device* dev, void* buf, int len);
44
+
45
+ int blink1_getSerialNumber(hid_device *dev, char* buf);
46
+ int blink1_getVersion(hid_device *dev);
47
+
48
+ int blink1_fadeToRGB(hid_device *dev, uint16_t fadeMillis,
49
+ uint8_t r, uint8_t g, uint8_t b );
50
+
51
+ int blink1_setRGB(hid_device *dev, uint8_t r, uint8_t g, uint8_t b );
52
+
53
+ int blink1_eeread(hid_device *dev, uint16_t addr, uint8_t* val);
54
+ int blink1_eewrite(hid_device *dev, uint16_t addr, uint8_t val);
55
+
56
+ int blink1_serialnumread(hid_device *dev, uint8_t** serialnumstr);
57
+ int blink1_serialnumwrite(hid_device *dev, uint8_t* serialnumstr);
58
+
59
+ //int blink1_nightlight(hid_device *dev, uint8_t on);
60
+ int blink1_serverdown(hid_device *dev, uint8_t on, uint16_t millis);
61
+
62
+ int blink1_play(hid_device *dev, uint8_t play, uint8_t pos);
63
+ int blink1_writePatternLine(hid_device *dev, uint16_t fadeMillis,
64
+ uint8_t r, uint8_t g, uint8_t b,
65
+ uint8_t pos);
66
+ int blink1_readPatternLine(hid_device *dev, uint16_t* fadeMillis,
67
+ uint8_t* r, uint8_t* g, uint8_t* b,
68
+ uint8_t pos);
69
+ //int blink1_playPattern(hid_device *dev,,);
70
+
71
+ char *blink1_error_msg(int errCode);
72
+
73
+ void blink1_enableDegamma();
74
+ void blink1_disableDegamma();
75
+ int blink1_degamma(int n);
76
+
77
+ void blink1_sleep(uint16_t delayMillis);
78
+
79
+ #ifdef __cplusplus
80
+ }
81
+ #endif
82
+
83
+ #endif
@@ -0,0 +1,101 @@
1
+ //
2
+ // color_funcs.h -- color sliding
3
+ //
4
+ // 2012, Tod E. Kurt, http://todbot.com/blog/
5
+ //
6
+ //
7
+ // also see:
8
+ // http://meyerweb.com/eric/tools/color-blend/
9
+ //
10
+ //
11
+
12
+ #ifndef RGB_FUNCS_H
13
+ #define RGB_FUNCS_H
14
+
15
+ #include <stdint.h>
16
+
17
+ // RGB triplet of 8-bit vals for input/output use
18
+ typedef struct {
19
+ uint8_t r;
20
+ uint8_t g;
21
+ uint8_t b;
22
+ } rgb_t;
23
+
24
+ // RGB triplet unsigned ints for internal use of 100x scale
25
+ // used instead of floating point
26
+ typedef struct {
27
+ int r;
28
+ int g;
29
+ int b;
30
+ } rgbint_t;
31
+
32
+ //
33
+ typedef struct {
34
+ rgb_t color;
35
+ uint16_t dmillis; // hundreths of a sec
36
+ } patternline_t;
37
+
38
+ #define setRGBt(rgbt,x,y,z) { rgbt.r=x; rgbt.g=y; rgbt.b=z; }
39
+
40
+ rgbint_t dest100x; // the eventual destination color we want to hit
41
+ rgbint_t step100x; // the amount of to move each tick
42
+ rgbint_t curr100x; // the current color, times 10 (to lessen int trunc issue)
43
+ int stepcnt;
44
+
45
+ #ifndef setRGBOut
46
+ #error "setRGBOut(r,g,b) not defined"
47
+ #endif
48
+
49
+ // set the current color
50
+ void rgb_setCurr( rgb_t* newcolor )
51
+ {
52
+ curr100x.r = newcolor->r * 100;
53
+ curr100x.g = newcolor->g * 100;
54
+ curr100x.b = newcolor->b * 100;
55
+
56
+ dest100x.r = curr100x.r;
57
+ dest100x.g = curr100x.g;
58
+ dest100x.b = curr100x.b;
59
+ stepcnt = 0;
60
+
61
+ setRGBOut( newcolor->r, newcolor->g, newcolor->b );
62
+ }
63
+
64
+ // set a new destination color
65
+ void rgb_setDest( rgb_t* newcolor, int steps )
66
+ {
67
+ dest100x.r = newcolor->r*100;
68
+ dest100x.g = newcolor->g*100;
69
+ dest100x.b = newcolor->b*100;
70
+
71
+ stepcnt = steps+1;
72
+
73
+ step100x.r = (dest100x.r - curr100x.r ) / steps;
74
+ step100x.g = (dest100x.g - curr100x.g ) / steps;
75
+ step100x.b = (dest100x.b - curr100x.b ) / steps;
76
+ }
77
+
78
+ // call at every tick
79
+ void rgb_updateCurrent(void)
80
+ {
81
+ if( !stepcnt ) {
82
+ return;
83
+ }
84
+ stepcnt--;
85
+ if( stepcnt ) {
86
+ curr100x.r += step100x.r;
87
+ curr100x.g += step100x.g;
88
+ curr100x.b += step100x.b;
89
+ } else {
90
+ curr100x.r = dest100x.r;
91
+ curr100x.g = dest100x.g;
92
+ curr100x.b = dest100x.b;
93
+ }
94
+
95
+ setRGBOut( curr100x.r/100, curr100x.g/100, curr100x.b/100 );
96
+ }
97
+
98
+
99
+ #endif
100
+
101
+
@@ -0,0 +1,383 @@
1
+ /*******************************************************
2
+ HIDAPI - Multi-Platform library for
3
+ communication with HID devices.
4
+
5
+ Alan Ott
6
+ Signal 11 Software
7
+
8
+ 8/22/2009
9
+
10
+ Copyright 2009, All Rights Reserved.
11
+
12
+ At the discretion of the user of this library,
13
+ this software may be licensed under the terms of the
14
+ GNU Public License v3, a BSD-Style license, or the
15
+ original HIDAPI license as outlined in the LICENSE.txt,
16
+ LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt
17
+ files located at the root of the source distribution.
18
+ These files may also be found in the public source
19
+ code repository located at:
20
+ http://github.com/signal11/hidapi .
21
+ ********************************************************/
22
+
23
+ /** @file
24
+ * @defgroup API hidapi API
25
+ */
26
+
27
+ #ifndef HIDAPI_H__
28
+ #define HIDAPI_H__
29
+
30
+ #include <wchar.h>
31
+
32
+ #ifdef _WIN32
33
+ #define HID_API_EXPORT __declspec(dllexport)
34
+ #define HID_API_CALL
35
+ #else
36
+ #define HID_API_EXPORT /**< API export macro */
37
+ #define HID_API_CALL /**< API call macro */
38
+ #endif
39
+
40
+ #define HID_API_EXPORT_CALL HID_API_EXPORT HID_API_CALL /**< API export and call macro*/
41
+
42
+ #ifdef __cplusplus
43
+ extern "C" {
44
+ #endif
45
+ struct hid_device_;
46
+ typedef struct hid_device_ hid_device; /**< opaque hidapi structure */
47
+
48
+ /** hidapi info structure */
49
+ struct hid_device_info {
50
+ /** Platform-specific device path */
51
+ char *path;
52
+ /** Device Vendor ID */
53
+ unsigned short vendor_id;
54
+ /** Device Product ID */
55
+ unsigned short product_id;
56
+ /** Serial Number */
57
+ wchar_t *serial_number;
58
+ /** Device Release Number in binary-coded decimal,
59
+ also known as Device Version Number */
60
+ unsigned short release_number;
61
+ /** Manufacturer String */
62
+ wchar_t *manufacturer_string;
63
+ /** Product string */
64
+ wchar_t *product_string;
65
+ /** Usage Page for this Device/Interface
66
+ (Windows/Mac only). */
67
+ unsigned short usage_page;
68
+ /** Usage for this Device/Interface
69
+ (Windows/Mac only).*/
70
+ unsigned short usage;
71
+ /** The USB interface which this logical device
72
+ represents. Valid on both Linux implementations
73
+ in all cases, and valid on the Windows implementation
74
+ only if the device contains more than one interface. */
75
+ int interface_number;
76
+
77
+ /** Pointer to the next device */
78
+ struct hid_device_info *next;
79
+ };
80
+
81
+
82
+ /** @brief Initialize the HIDAPI library.
83
+
84
+ This function initializes the HIDAPI library. Calling it is not
85
+ strictly necessary, as it will be called automatically by
86
+ hid_enumerate() and any of the hid_open_*() functions if it is
87
+ needed. This function should be called at the beginning of
88
+ execution however, if there is a chance of HIDAPI handles
89
+ being opened by different threads simultaneously.
90
+
91
+ @ingroup API
92
+
93
+ @returns
94
+ This function returns 0 on success and -1 on error.
95
+ */
96
+ int HID_API_EXPORT HID_API_CALL hid_init(void);
97
+
98
+ /** @brief Finalize the HIDAPI library.
99
+
100
+ This function frees all of the static data associated with
101
+ HIDAPI. It should be called at the end of execution to avoid
102
+ memory leaks.
103
+
104
+ @ingroup API
105
+
106
+ @returns
107
+ This function returns 0 on success and -1 on error.
108
+ */
109
+ int HID_API_EXPORT HID_API_CALL hid_exit(void);
110
+
111
+ /** @brief Enumerate the HID Devices.
112
+
113
+ This function returns a linked list of all the HID devices
114
+ attached to the system which match vendor_id and product_id.
115
+ If @p vendor_id and @p product_id are both set to 0, then
116
+ all HID devices will be returned.
117
+
118
+ @ingroup API
119
+ @param vendor_id The Vendor ID (VID) of the types of device
120
+ to open.
121
+ @param product_id The Product ID (PID) of the types of
122
+ device to open.
123
+
124
+ @returns
125
+ This function returns a pointer to a linked list of type
126
+ struct #hid_device, containing information about the HID devices
127
+ attached to the system, or NULL in the case of failure. Free
128
+ this linked list by calling hid_free_enumeration().
129
+ */
130
+ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id);
131
+
132
+ /** @brief Free an enumeration Linked List
133
+
134
+ This function frees a linked list created by hid_enumerate().
135
+
136
+ @ingroup API
137
+ @param devs Pointer to a list of struct_device returned from
138
+ hid_enumerate().
139
+ */
140
+ void HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs);
141
+
142
+ /** @brief Open a HID device using a Vendor ID (VID), Product ID
143
+ (PID) and optionally a serial number.
144
+
145
+ If @p serial_number is NULL, the first device with the
146
+ specified VID and PID is opened.
147
+
148
+ @ingroup API
149
+ @param vendor_id The Vendor ID (VID) of the device to open.
150
+ @param product_id The Product ID (PID) of the device to open.
151
+ @param serial_number The Serial Number of the device to open
152
+ (Optionally NULL).
153
+
154
+ @returns
155
+ This function returns a pointer to a #hid_device object on
156
+ success or NULL on failure.
157
+ */
158
+ HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number);
159
+
160
+ /** @brief Open a HID device by its path name.
161
+
162
+ The path name be determined by calling hid_enumerate(), or a
163
+ platform-specific path name can be used (eg: /dev/hidraw0 on
164
+ Linux).
165
+
166
+ @ingroup API
167
+ @param path The path name of the device to open
168
+
169
+ @returns
170
+ This function returns a pointer to a #hid_device object on
171
+ success or NULL on failure.
172
+ */
173
+ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path);
174
+
175
+ /** @brief Write an Output report to a HID device.
176
+
177
+ The first byte of @p data[] must contain the Report ID. For
178
+ devices which only support a single report, this must be set
179
+ to 0x0. The remaining bytes contain the report data. Since
180
+ the Report ID is mandatory, calls to hid_write() will always
181
+ contain one more byte than the report contains. For example,
182
+ if a hid report is 16 bytes long, 17 bytes must be passed to
183
+ hid_write(), the Report ID (or 0x0, for devices with a
184
+ single report), followed by the report data (16 bytes). In
185
+ this example, the length passed in would be 17.
186
+
187
+ hid_write() will send the data on the first OUT endpoint, if
188
+ one exists. If it does not, it will send the data through
189
+ the Control Endpoint (Endpoint 0).
190
+
191
+ @ingroup API
192
+ @param device A device handle returned from hid_open().
193
+ @param data The data to send, including the report number as
194
+ the first byte.
195
+ @param length The length in bytes of the data to send.
196
+
197
+ @returns
198
+ This function returns the actual number of bytes written and
199
+ -1 on error.
200
+ */
201
+ int HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned char *data, size_t length);
202
+
203
+ /** @brief Read an Input report from a HID device with timeout.
204
+
205
+ Input reports are returned
206
+ to the host through the INTERRUPT IN endpoint. The first byte will
207
+ contain the Report number if the device uses numbered reports.
208
+
209
+ @ingroup API
210
+ @param device A device handle returned from hid_open().
211
+ @param data A buffer to put the read data into.
212
+ @param length The number of bytes to read. For devices with
213
+ multiple reports, make sure to read an extra byte for
214
+ the report number.
215
+ @param milliseconds timeout in milliseconds or -1 for blocking wait.
216
+
217
+ @returns
218
+ This function returns the actual number of bytes read and
219
+ -1 on error.
220
+ */
221
+ int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds);
222
+
223
+ /** @brief Read an Input report from a HID device.
224
+
225
+ Input reports are returned
226
+ to the host through the INTERRUPT IN endpoint. The first byte will
227
+ contain the Report number if the device uses numbered reports.
228
+
229
+ @ingroup API
230
+ @param device A device handle returned from hid_open().
231
+ @param data A buffer to put the read data into.
232
+ @param length The number of bytes to read. For devices with
233
+ multiple reports, make sure to read an extra byte for
234
+ the report number.
235
+
236
+ @returns
237
+ This function returns the actual number of bytes read and
238
+ -1 on error.
239
+ */
240
+ int HID_API_EXPORT HID_API_CALL hid_read(hid_device *device, unsigned char *data, size_t length);
241
+
242
+ /** @brief Set the device handle to be non-blocking.
243
+
244
+ In non-blocking mode calls to hid_read() will return
245
+ immediately with a value of 0 if there is no data to be
246
+ read. In blocking mode, hid_read() will wait (block) until
247
+ there is data to read before returning.
248
+
249
+ Nonblocking can be turned on and off at any time.
250
+
251
+ @ingroup API
252
+ @param device A device handle returned from hid_open().
253
+ @param nonblock enable or not the nonblocking reads
254
+ - 1 to enable nonblocking
255
+ - 0 to disable nonblocking.
256
+
257
+ @returns
258
+ This function returns 0 on success and -1 on error.
259
+ */
260
+ int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *device, int nonblock);
261
+
262
+ /** @brief Send a Feature report to the device.
263
+
264
+ Feature reports are sent over the Control endpoint as a
265
+ Set_Report transfer. The first byte of @p data[] must
266
+ contain the Report ID. For devices which only support a
267
+ single report, this must be set to 0x0. The remaining bytes
268
+ contain the report data. Since the Report ID is mandatory,
269
+ calls to hid_send_feature_report() will always contain one
270
+ more byte than the report contains. For example, if a hid
271
+ report is 16 bytes long, 17 bytes must be passed to
272
+ hid_send_feature_report(): the Report ID (or 0x0, for
273
+ devices which do not use numbered reports), followed by the
274
+ report data (16 bytes). In this example, the length passed
275
+ in would be 17.
276
+
277
+ @ingroup API
278
+ @param device A device handle returned from hid_open().
279
+ @param data The data to send, including the report number as
280
+ the first byte.
281
+ @param length The length in bytes of the data to send, including
282
+ the report number.
283
+
284
+ @returns
285
+ This function returns the actual number of bytes written and
286
+ -1 on error.
287
+ */
288
+ int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *device, const unsigned char *data, size_t length);
289
+
290
+ /** @brief Get a feature report from a HID device.
291
+
292
+ Make sure to set the first byte of @p data[] to the Report
293
+ ID of the report to be read. Make sure to allow space for
294
+ this extra byte in @p data[].
295
+
296
+ @ingroup API
297
+ @param device A device handle returned from hid_open().
298
+ @param data A buffer to put the read data into, including
299
+ the Report ID. Set the first byte of @p data[] to the
300
+ Report ID of the report to be read.
301
+ @param length The number of bytes to read, including an
302
+ extra byte for the report ID. The buffer can be longer
303
+ than the actual report.
304
+
305
+ @returns
306
+ This function returns the number of bytes read and
307
+ -1 on error.
308
+ */
309
+ int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *device, unsigned char *data, size_t length);
310
+
311
+ /** @brief Close a HID device.
312
+
313
+ @ingroup API
314
+ @param device A device handle returned from hid_open().
315
+ */
316
+ void HID_API_EXPORT HID_API_CALL hid_close(hid_device *device);
317
+
318
+ /** @brief Get The Manufacturer String from a HID device.
319
+
320
+ @ingroup API
321
+ @param device A device handle returned from hid_open().
322
+ @param string A wide string buffer to put the data into.
323
+ @param maxlen The length of the buffer in multiples of wchar_t.
324
+
325
+ @returns
326
+ This function returns 0 on success and -1 on error.
327
+ */
328
+ int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *device, wchar_t *string, size_t maxlen);
329
+
330
+ /** @brief Get The Product String from a HID device.
331
+
332
+ @ingroup API
333
+ @param device A device handle returned from hid_open().
334
+ @param string A wide string buffer to put the data into.
335
+ @param maxlen The length of the buffer in multiples of wchar_t.
336
+
337
+ @returns
338
+ This function returns 0 on success and -1 on error.
339
+ */
340
+ int HID_API_EXPORT_CALL hid_get_product_string(hid_device *device, wchar_t *string, size_t maxlen);
341
+
342
+ /** @brief Get The Serial Number String from a HID device.
343
+
344
+ @ingroup API
345
+ @param device A device handle returned from hid_open().
346
+ @param string A wide string buffer to put the data into.
347
+ @param maxlen The length of the buffer in multiples of wchar_t.
348
+
349
+ @returns
350
+ This function returns 0 on success and -1 on error.
351
+ */
352
+ int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *device, wchar_t *string, size_t maxlen);
353
+
354
+ /** @brief Get a string from a HID device, based on its string index.
355
+
356
+ @ingroup API
357
+ @param device A device handle returned from hid_open().
358
+ @param string_index The index of the string to get.
359
+ @param string A wide string buffer to put the data into.
360
+ @param maxlen The length of the buffer in multiples of wchar_t.
361
+
362
+ @returns
363
+ This function returns 0 on success and -1 on error.
364
+ */
365
+ int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *device, int string_index, wchar_t *string, size_t maxlen);
366
+
367
+ /** @brief Get a string describing the last error which occurred.
368
+
369
+ @ingroup API
370
+ @param device A device handle returned from hid_open().
371
+
372
+ @returns
373
+ This function returns a string containing the last error
374
+ which occurred or NULL if none has occurred.
375
+ */
376
+ HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *device);
377
+
378
+ #ifdef __cplusplus
379
+ }
380
+ #endif
381
+
382
+ #endif
383
+
@@ -0,0 +1,85 @@
1
+ #ifndef __OSCAL_H__
2
+ #define __OSCAL_H__
3
+
4
+ #include <avr/eeprom.h>
5
+ #include <avr/interrupt.h>
6
+
7
+ const uint8_t EEPROM_ADDR_OSCCAL = 0;
8
+
9
+ /* ------------------------------------------------------------------------- */
10
+ /* ------------------------ Oscillator Calibration ------------------------- */
11
+ /* ------------------------------------------------------------------------- */
12
+
13
+ // put this in main() before usbInit
14
+ static void calibrationLoad(void)
15
+ {
16
+ uint8_t calibrationValue;
17
+ // calibration value from last time
18
+ calibrationValue = eeprom_read_byte(EEPROM_ADDR_OSCCAL);
19
+ if(calibrationValue != 0xff){
20
+ OSCCAL = calibrationValue;
21
+ }
22
+ }
23
+
24
+ /* Calibrate the RC oscillator to 8.25 MHz. The core clock of 16.5 MHz is
25
+ * derived from the 66 MHz peripheral clock by dividing. Our timing reference
26
+ * is the Start Of Frame signal (a single SE0 bit) available immediately after
27
+ * a USB RESET. We first do a binary search for the OSCCAL value and then
28
+ * optimize this value with a neighboorhod search.
29
+ * This algorithm may also be used to calibrate the RC oscillator directly to
30
+ * 12 MHz (no PLL involved, can therefore be used on almost ALL AVRs), but this
31
+ * is wide outside the spec for the OSCCAL value and the required precision for
32
+ * the 12 MHz clock! Use the RC oscillator calibrated to 12 MHz for
33
+ * experimental purposes only!
34
+ */
35
+ static void calibrateOscillator(void)
36
+ {
37
+ uchar step = 128;
38
+ uchar trialValue = 0, optimumValue;
39
+ int x, optimumDev;
40
+ int targetValue = (unsigned)(1499 * (double)F_CPU / 10.5e6 + 0.5);
41
+
42
+ /* do a binary search: */
43
+ do{
44
+ OSCCAL = trialValue + step;
45
+ x = usbMeasureFrameLength(); // proportional to current real frequency
46
+ if(x < targetValue) // frequency still too low
47
+ trialValue += step;
48
+ step >>= 1;
49
+ }while(step > 0);
50
+ /* We have a precision of +/- 1 for optimum OSCCAL here */
51
+ /* now do a neighborhood search for optimum value */
52
+ optimumValue = trialValue;
53
+ optimumDev = x; /* this is certainly far away from optimum */
54
+ for(OSCCAL = trialValue - 1; OSCCAL <= trialValue + 1; OSCCAL++){
55
+ x = usbMeasureFrameLength() - targetValue;
56
+ if(x < 0)
57
+ x = -x;
58
+ if(x < optimumDev){
59
+ optimumDev = x;
60
+ optimumValue = OSCCAL;
61
+ }
62
+ }
63
+ OSCCAL = optimumValue;
64
+ }
65
+ /*
66
+ Note: This calibration algorithm may try OSCCAL values of up to 192 even if
67
+ the optimum value is far below 192. It may therefore exceed the allowed clock
68
+ frequency of the CPU in low voltage designs!
69
+ You may replace this search algorithm with any other algorithm you like if
70
+ you have additional constraints such as a maximum CPU clock.
71
+ For version 5.x RC oscillators (those with a split range of 2x128 steps, e.g.
72
+ ATTiny25, ATTiny45, ATTiny85), it may be useful to search for the optimum in
73
+ both regions.
74
+ */
75
+
76
+ void usbEventResetReady(void)
77
+ {
78
+ calibrateOscillator();
79
+ // store the calibrated value in EEPROM
80
+ eeprom_write_byte(EEPROM_ADDR_OSCCAL, OSCCAL);
81
+
82
+ usbHasBeenSetup++;
83
+ }
84
+
85
+ #endif