Crate tmledkey_hal_drv

Source
Expand description

This crate provides interface to work with Titanmec LED drives for 7 segment displays. Titanmec produce different types of MCUs that are using common 2 pin or 3 pin serial like interfaces. The most popular models for DIY projects are TM1637 and TM1638. Besides display driver capabilities this MCUs are also provide key-scan functionality.

This driver utilize embedded_hal functionality, thus it could work on different kind of hardware via HAL.

§This is low level API

Read data sheet first if you want to understand how to work with MCU. API provided here only wraps data transfer protocols. You still have to send and receive raw data as bytes. In order to understand meaning of this bytes you should have some knowledges.

§Need code examples?

Just explore repository examples folder.

I just have no capacity to maintain actual code samples in every place.

§Features

Some functionality of this library are splitted into features. I hope that it may help to reduce resulted firmware size.

  • cldkio - functions to work with 2 wire interfaces
  • clkdiostb - functions to work with 3 wire interfaces
  • keys - key scan support
  • fx - tiny effects api (depends on “galloc”)
  • galloc - functionality that require to have global allocator in your application

You should look into Cargo.toml in source code to get better understanding how does this features combined together.

§Handling delays

I’ve found out that handling delays is a very tricky for some hardware. Plus HAL implementation gives DelayXX and Timer traits thus it is not obvious what kind of trait should be preferred.

In order to simplify delay approach I decided that you have to implement delay logic on your side and wrap it in lambda. It is up to you what kind of delay approach you will use. Just keep in mind that delays have to be precise.

Some functions accepts delay value as input parameter. It is kinda weird, but it would allow you to reduce bus communication delays if your circuit configuration allows you to. In other cases you can use pre defined delay values.

Modules§

utils
Helpful functions to work with MCUs raw data.

Enums§

TmError
Describes possible error mostly related to low level interaction with MCU. At least it should give you an insight about what goes wrong.

Constants§

BUS_DELAY_US
Universal delay for TM serial protocol. This value should fit all configurations, but you should prefer to use values that fits exact MCU chip version.
CHAR_0
CHAR_1
CHAR_2
CHAR_3
CHAR_4
CHAR_5
CHAR_6
CHAR_7
CHAR_8
CHAR_9
CHAR_A
CHAR_BRACKET_LEFT
CHAR_BRACKET_RIGHT
CHAR_C
CHAR_CYR_B
CHAR_CYR_E
CHAR_DEGREE
CHAR_E
CHAR_F
CHAR_G
CHAR_H
CHAR_I
CHAR_J
CHAR_L
CHAR_MINUS
CHAR_N
CHAR_O
CHAR_P
CHAR_R
CHAR_S
CHAR_U
CHAR_UNDERSCORE
CHAR_a
CHAR_b
CHAR_c
CHAR_d
CHAR_e
CHAR_h
CHAR_i
CHAR_l
CHAR_n
CHAR_o
CHAR_q
CHAR_r
CHAR_t
CHAR_u
CHAR_y
COM_ADDRESS
Address instruction set
COM_DATA
Data control instruction set
COM_DATA_ADDRESS_ADD
Address adding mode (write to display)
COM_DATA_ADDRESS_FIXED
Data fix address mode (write to display)
COM_DATA_READ
Read key scan data
COM_DISPLAY
Display control instruction set
COM_DISPLAY_OFF
COM_DISPLAY_ON
Display ON max brightness. Can be combined with masked bytes to adjust brightness level
DIGITS
List of digit characters where values correlates with array index 0-9.
DISPLAY_BRIGHTNESS_MASK
Display brightness mask
SEG_1
Segment A - top
SEG_2
Segment B - top right
SEG_3
Segment C - bottom right
SEG_4
Segment D - bottom
SEG_5
Segment E - bottom left
SEG_6
Segment F - top left
SEG_7
Segment G - middle
SEG_8
Segment DP (eight) - dot or colon
SEG_9
Used with 3 wire interface for second byte
SEG_10
Used with 3 wire interface for second byte
SEG_11
Used with 3 wire interface for second byte
SEG_12
Used with 3 wire interface for second byte
TM1637_BUS_DELAY_US
Proven working delay for TM1637, it can be lower depending of your pull-up resistor characteristics.
TM1637_MAX_SEGMENTS
Maximum number of display segments supported by this MCU.
TM1637_RESPONSE_SIZE
Number of bytes that can be read from from TM1637 response.
TM1638_BUS_DELAY_US
Proven working delay for TM1638
TM1638_MAX_SEGMENTS
Maximum number of display segments supported by this MCU.
TM1638_RESPONSE_SIZE
Number of bytes that can be read from from TM1638 response.

Functions§

tm_send_bytes_2wire
Send one or several bytes to MCU via 2 wire interface (DIO,CLK).
tm_send_bytes_3wire
Send bytes using 3 wire interface (DIO,CLK,STB).