# CANDis (SW)

## Overview

"CANDis" small touch panel acting as an light switch.

## MCU

STM32G441KB; 48 Mhz; 128KB Flash

## Flash Device

### Firmware via DFU/USB

To be able to flash the device via USB following prerequisite are needed:

* Device connected via USB to host PC
* [STM32CubeProgrammer]( https://www.st.com/en/development-tools/stm32cubeprog.html ) is installed on host PC

Power on the device. Hold the "B"-Button on the backside with an toothpick and
hold it pressed. Press the "R"-Button and hold it pressed for c.a. one second.
Relese the "R"-button, then release the "B"-Botton. The Display must remain
dark. The amber LED must not glow.

The command line tool of STM32CubeProgrammer can be use to flash the firmware:
```
$HOME/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/STM32_Programmer_CLI -c port=usb1 -w candis_eval.bin 0x08000000 -s
```

The device will automatically start.

Caution: When the firmware was not already installed before, the device will automatically start the media bootloader. See next chapter.

### Media catalog via USB

The device contains an SPI-Flash for media data like images and icons. The version of the catalog must match to the firmware.
If versions do not match or media catalog is corrupt, the device will automatically start the media bootloader.

![Media bootloader](doc/pic/screen_bootloader.png)

The command line tool of STM32CubeProgrammer can be use to flash the firmware.
The file "media.bin" that is shipped with the firmware has to be flashed.
Because data is stored to SPI-Flash and not the STM32-Flash, the target address
is 0x0. The automatic erasing does not work so an chip-erase has to be set
via "-e all".

> **Warning**: Unlike flashing firmware, an serial port has to be committed to
the programmer tool instead of usb directly.

e.g.:
```
$HOME/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/STM32_Programmer_CLI -c port=/dev/ttyACM0 -e all -d media.bin 0x0
```


> **Warning**: The progress bar on the screen shows the overall usage of the flash.
It does not match the progress bar of the flashing tool.

> **Warning**: If the flashing fails, start the process again.

## Screens

<table style=" margin-left: auto; margin-right: auto;">
<tr>
<td><figure>
![Media bootloader](doc/pic/screen_bootloader.png)
<figcaption>Media bootloader</figcaption></figure></td>
<td><figure>
![Media bootloader](doc/pic/screen_standby.png)
<figcaption>Standby</figcaption></figure></td>
<td><figure>
![Main Menu](doc/pic/screen_main_menu.png)
<figcaption>Main Menu</figcaption></figure></td>
<td><figure>
![Minutnik Items](doc/pic/screen_items.png)
<figcaption>Minutnik Items</figcaption></figure></td>
</tr>

<tr>
<td><figure>
![Illumination](doc/pic/screen_illumination.png)
<figcaption>Illumination</figcaption></figure></td>
<td><figure>
![Info](doc/pic/screen_info.png)
<figcaption>Info</figcaption></figure></td>
<td><figure>
![Settings](doc/pic/screen_settings.png)
<figcaption>Settings</figcaption></figure></td>
<td><figure>
![Chart](doc/pic/screen_chart.png)
<figcaption>Chart</figcaption></figure></td>
</tr>

<tr>
<td><figure>
![Chart](doc/pic/screen_wine.png)
<figcaption>Wine</figcaption></figure></td>
<td><figure>
![Minutnik](doc/pic/screen_minutnik.png)
<figcaption>Minutnik</figcaption></figure></td>
<td><figure>
![Alarm](doc/pic/screen_alarm.png)
<figcaption>Minutnik Alarm</figcaption></figure></td>
</tr>
</table>

