I needed to build USB device that is recognizable as UPS by Network UPS Tools (NUT).
It seems that one of the simplest USB drivers in NUT is drivers/richcomm_usb.c.
This code implements richcomm_usb.c protocol using MC HCK prototype board based on Freescale Kinetis K20 MCU (ARM Cortex-M4). I just had spare kit and wanted to try the SDK, so the code has a lot of comments.
- MC HCK board with standard bootloader
- GCC ARM embedded toolchain
- MC HCK toolchain
- dfu-util
- Clone this repository to examples/ subdirectory of MC HCK toolchain.
cd richcomm-ups-mchck; make
- Plug MC HCK into USB port; type
make flash
, press push button on the board, wait ~1 sec and press Enter. lsusb -v
now shows MC HCK as "Richcomm UPS emulator".
See rcm_handle_data() function that imitates power failure and battery discharge.
You can check your current UPS status with upsc
(look for ups.status).
This source code is in public domain. For more information, please refer to http://unlicense.org/