ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
firmware.h File Reference
#include "includes.h"
+ Include dependency graph for firmware.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int getfwversion (usbdevice *kb)
 
int cmd_fwupdate (usbdevice *kb, usbmode *dummy1, int nnumber, int dummy2, const char *path)
 

Function Documentation

int cmd_fwupdate ( usbdevice kb,
usbmode dummy1,
int  nnumber,
int  dummy2,
const char *  path 
)

Definition at line 154 of file firmware.c.

References FEAT_FWUPDATE, FW_NOFILE, FW_OK, FW_USBFAIL, FW_WRONGDEV, fwupdate(), HAS_FEATURES, nprintf(), and usb_tryreset().

154  {
155  (void)dummy1;
156  (void)dummy2;
157 
158  if(!HAS_FEATURES(kb, FEAT_FWUPDATE))
159  return 0;
160  // Update the firmware
161  int ret = fwupdate(kb, path, nnumber);
162  while(ret == FW_USBFAIL){
163  // Try to reset the device if it fails
164  if(usb_tryreset(kb))
165  break;
166  ret = fwupdate(kb, path, nnumber);
167  }
168  switch(ret){
169  case FW_OK:
170  nprintf(kb, nnumber, 0, "fwupdate %s ok\n", path);
171  break;
172  case FW_NOFILE:
173  case FW_WRONGDEV:
174  nprintf(kb, nnumber, 0, "fwupdate %s invalid\n", path);
175  break;
176  case FW_USBFAIL:
177  nprintf(kb, nnumber, 0, "fwupdate %s fail\n", path);
178  return -1;
179  }
180  return 0;
181 }
void nprintf(usbdevice *kb, int nodenumber, usbmode *mode, const char *format,...)
Definition: notify.c:8
int usb_tryreset(usbdevice *kb)
Definition: usb.c:475
#define FW_WRONGDEV
Definition: firmware.c:8
#define FW_NOFILE
Definition: firmware.c:7
#define FW_USBFAIL
Definition: firmware.c:9
#define FW_OK
Definition: firmware.c:6
#define HAS_FEATURES(kb, feat)
Definition: structures.h:157
int fwupdate(usbdevice *kb, const char *path, int nnumber)
Definition: firmware.c:55
#define FEAT_FWUPDATE
Definition: structures.h:143

+ Here is the call graph for this function:

int getfwversion ( usbdevice kb)

Definition at line 11 of file firmware.c.

References ckb_err, ckb_warn, FEAT_POLLRATE, usbdevice::features, usbdevice::fwversion, MSG_SIZE, usbdevice::pollrate, usbdevice::product, usbrecv, and usbdevice::vendor.

Referenced by _start_dev().

11  {
12  // Ask board for firmware info
13  uchar data_pkt[MSG_SIZE] = { 0x0e, 0x01, 0 };
14  uchar in_pkt[MSG_SIZE];
15  if(!usbrecv(kb, data_pkt, in_pkt))
16  return -1;
17  if(in_pkt[0] != 0x0e || in_pkt[1] != 0x01){
18  ckb_err("Bad input header\n");
19  return -1;
20  }
21  short vendor, product, version, bootloader;
22  // Copy the vendor ID, product ID, version, and poll rate from the firmware data
23  memcpy(&version, in_pkt + 8, 2);
24  memcpy(&bootloader, in_pkt + 10, 2);
25  memcpy(&vendor, in_pkt + 12, 2);
26  memcpy(&product, in_pkt + 14, 2);
27  char poll = in_pkt[16];
28  if(poll <= 0){
29  poll = -1;
30  kb->features &= ~FEAT_POLLRATE;
31  }
32  // Print a warning if the message didn't match the expected data
33  if(vendor != kb->vendor)
34  ckb_warn("Got vendor ID %04x (expected %04x)\n", vendor, kb->vendor);
35  if(product != kb->product)
36  ckb_warn("Got product ID %04x (expected %04x)\n", product, kb->product);
37  // Set firmware version and poll rate
38  if(version == 0 || bootloader == 0){
39  // Needs firmware update
40  kb->fwversion = 0;
41  kb->pollrate = -1;
42  } else {
43  if(version != kb->fwversion && kb->fwversion != 0)
44  ckb_warn("Got firmware version %04x (expected %04x)\n", version, kb->fwversion);
45  kb->fwversion = version;
46  kb->pollrate = poll;
47  }
48  return 0;
49 }
#define MSG_SIZE
Definition: structures.h:176
#define ckb_err(fmt, args...)
Definition: includes.h:49
ushort fwversion
Definition: structures.h:239
unsigned char uchar
Definition: includes.h:24
#define ckb_warn(fmt, args...)
Definition: includes.h:52
short product
Definition: structures.h:237
char pollrate
Definition: structures.h:241
ushort features
Definition: structures.h:229
#define usbrecv(kb, out_msg, in_msg)
usbrecv macro is used to wrap _usbrecv() with debugging information (file and lineno) ...
Definition: usb.h:288
short vendor
Definition: structures.h:237
#define FEAT_POLLRATE
Definition: structures.h:138

+ Here is the caller graph for this function: