34
libe Documentation Release alpha Antti Partanen Jun 02, 2022

libe Documentation

  • Upload
    others

  • View
    14

  • Download
    0

Embed Size (px)

Citation preview

Page 1: libe Documentation

libe DocumentationRelease alpha

Antti Partanen

Jun 02, 2022

Page 2: libe Documentation
Page 3: libe Documentation

Contents

1 Build system 11.1 Command line options for make . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Makefile options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

2 System and time 52.1 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.2 Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.3 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

3 GPIO 73.1 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73.2 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73.3 Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83.4 Defines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

4 I2C 114.1 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114.2 Master drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114.3 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

5 SPI 17

6 Sensors 196.1 Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196.2 Generic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196.3 ADC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206.4 Temperature and Humidity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

7 Encryption 257.1 AES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257.2 RC5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267.3 XTEA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267.4 XXTEA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

Index 29

i

Page 4: libe Documentation

ii

Page 5: libe Documentation

CHAPTER 1

Build system

1.1 Command line options for make

All option names must be lower case for not to override internals.

target=<target>

mcu=<mcu>

f_cpu=<frequency>

use="<use1> <use2>"

defines="<define1> <define2>"

cflags="<flag1> <flag2>"Directly add these to CFLAGS.

ldflags="<flag1> <flag2>"Directly add these to LDFLAGS.

1.2 Makefile options

TARGET = <TARGET>In Makefile you MUST use upper case for target value. In command line you can also use lower case.

Define default target in Makefile:

TARGET = X86

Then compile using another target:

make target=avr

1

Page 6: libe Documentation

libe Documentation, Release alpha

MCU_<TARGET> = <MCU>Target specific default MCU. Could be ATmega8 for AVR targets or 16F87 for 8-bit PIC targets.

Define default MCU in Makefile:

TARGET = X86MCU_AVR = atmega328pMCU_PIC8 = 16f84a

Then compile using another MCU:

make target=avr mcu=atmega8make target=pic8 mcu=16f87

F_CPU = <FREQUENCY>Generic default CPU clock speed needed by some targets like AVR and 8-bit PIC.

Define in Makefile:

F_CPU = 1000000

Then override from command line:

make f_cpu=8000000

F_CPU_<TARGET> = <FREQUENCY>Same as F_CPU_<TARGET> but TARGET specific.

F_CPU_<MCU> = <FREQUENCY>Same as F_CPU_<TARGET> but MCU specific.

USE += ...Add used components. Normally you want some since almost nothing is included as default.

Makefile with I2C and logging enabled:

USE += I2C LOG

Then compile by adding GPIO and using I2C in bitbang mode (which needs GPIO):

make use="gpio i2c_bitbang"

USE_<TARGET> += ...Same as USE but TARGET specific.

USE_<MCU> += ...Same as USE but MCU specific.

DEFINES += ...Add defines. This basically is a shorthand for CFLAGS += -D<DEFINE>.

Usage in Makefile:

DEFINES += MY_DEFINE OTHER_DEFINEDEFINES += MY_PI=3.1415

From command line:

make defines="CMD_DEFINE1 CMD_DEFINE2=123"

2 Chapter 1. Build system

Page 7: libe Documentation

libe Documentation, Release alpha

DEFINES_<TARGET> += ...Same as DEFINES but TARGET specific.

DEFINES_<MCU> += ...Same as DEFINES but MCU specific.

CFLAGS += ...Compiler flags.

CFLAGS_<TARGET> += ...Compiler flags.

CFLAGS_<MCU> += ...Compiler flags.

LDFLAGS += ...Linker flags.

LDFLAGS_<TARGET> += ...Linker flags.

LDFLAGS_<MCU> += ...Linker flags.

1.2. Makefile options 3

Page 8: libe Documentation

libe Documentation, Release alpha

4 Chapter 1. Build system

Page 9: libe Documentation

CHAPTER 2

System and time

2.1 Functions

int os_init(void)

Returns 0 on success, -1 on errors

Low-level system setup. Should be always called first at start of application main entry point. Generally will atleast set all ports as inputs.

void os_quit(void)Will de-initialize system. On many smaller targets this is just an empty define and does nothing.

time_t os_timei(void)

Returns seconds since some unspecified constant point in the past, usually system boot

os_time_t os_timef(void)

Returns seconds since some unspecified constant point in the past, usually system boot

void os_sleepi(time_t t)

Parameters

• t (time_t) – seconds to sleep

Sleep given amount of seconds. On most targets this is stupid while-loop that simply blocks.

void os_sleepf(os_time_t t)

Parameters

• t (os_time_t) – seconds to sleep, floating point, with fractions of second included

Sleep given amount of seconds. On most targets this is stupid while-loop that simply blocks.

5

Page 10: libe Documentation

libe Documentation, Release alpha

2.2 Macros

os_delay_us(delay)

Parameters

• delay – microseconds to sleep

This usually calls target specific macro, like _delay_us() in AVR and __delay_us() in PIC.

os_delay_ms(delay)

Parameters

• delay – milliseconds to sleep

This usually calls target specific macro, like _delay_ms() in AVR and __delay_ms() in PIC.

2.3 Types

os_time_t

Floating point time representation type:

• default: long double

• AVR: double

• PIC, 8-bit: double

6 Chapter 2. System and time

Page 11: libe Documentation

CHAPTER 3

GPIO

Generic interface for GPIO which requires only pin number instead of port&pin-combo used in many smaller deviceslike AVR and PIC. This is achieved by mapping PORTB in AVR to pin numbers 8-15, PORTC to 16-23 and so on.Same for PIC, MSP430 and others that do this kind of thing instead of having continuous GPIO pin numbers.

For convenience GPIOxy constants have been defined where x is the letter of an 8-bit port and y is the bit number.These constants cover ports from A to H.

GPIO implemented this way is more and less complex thing. On most targets, like AVR, GPIO functions are inlineand will often optimize as well as directly written native code.

3.1 Configuration

3.1.1 Enable GPIO module

To enable GPIO, flag USE_GPIO must be defined globally.

In Makefile:

USE += GPIO

From command line when compiling:

make use=gpio

3.2 Functions

void gpio_enable(uint8_t pin, bool direction)

Parameters

• pin (uint8_t) – pin to be enabled

7

Page 12: libe Documentation

libe Documentation, Release alpha

• direction (bool) –

– 0 is input

– 1 is output

Enable specific pin using it as an input or output.

void gpio_set(uint8_t pin, uint8_t state)

Parameters

• pin (uint8_t) – pin to be set

• state (uint8_t) –

– 0 is low

– any other value is high

uint8_t gpio_read(uint8_t pin)

Parameters

• pin (uint8_t) – pin to be read

Returns 0 if pin is low, non-zero if high

3.3 Macros

gpio_input(pin)Calls gpio_enable(pin, 0).

gpio_output(pin)Calls gpio_enable(pin, 1).

gpio_low(pin)Calls gpio_set(pin, 0).

gpio_high(pin)Calls gpio_set(pin, 1).

3.4 Defines

enumerator GPIOA0 = 0

enumerator GPIOA1 = 1

enumerator GPIOA2 = 2

enumerator GPIOA3 = 3

enumerator GPIOA4 = 4

enumerator GPIOA5 = 5

enumerator GPIOA6 = 6

enumerator GPIOA7 = 7

enumerator GPIOB0 = 8

enumerator GPIOB1 = 9

8 Chapter 3. GPIO

Page 13: libe Documentation

libe Documentation, Release alpha

enumerator GPIOB2 = 10

enumerator GPIOB3 = 11

enumerator GPIOB4 = 12

enumerator GPIOB5 = 13

enumerator GPIOB6 = 14

enumerator GPIOB7 = 15

enumerator GPIOC0 = 16

enumerator GPIOC1 = 17

enumerator GPIOC2 = 18

enumerator GPIOC3 = 19

enumerator GPIOC4 = 20

enumerator GPIOC5 = 21

enumerator GPIOC6 = 22

enumerator GPIOC7 = 23

enumerator GPIOD0 = 24

enumerator GPIOD1 = 25

enumerator GPIOD2 = 26

enumerator GPIOD3 = 27

enumerator GPIOD4 = 28

enumerator GPIOD5 = 29

enumerator GPIOD6 = 30

enumerator GPIOD7 = 31

enumerator GPIOE0 = 32

enumerator GPIOE1 = 33

enumerator GPIOE2 = 34

enumerator GPIOE3 = 35

enumerator GPIOE4 = 36

enumerator GPIOE5 = 37

enumerator GPIOE6 = 38

enumerator GPIOE7 = 39

enumerator GPIOF0 = 40

enumerator GPIOF1 = 41

enumerator GPIOF2 = 42

enumerator GPIOF3 = 43

enumerator GPIOF4 = 44

enumerator GPIOF5 = 45

3.4. Defines 9

Page 14: libe Documentation

libe Documentation, Release alpha

enumerator GPIOF6 = 46

enumerator GPIOF7 = 47

enumerator GPIOG0 = 48

enumerator GPIOG1 = 49

enumerator GPIOG2 = 50

enumerator GPIOG3 = 51

enumerator GPIOG4 = 52

enumerator GPIOG5 = 53

enumerator GPIOG6 = 54

enumerator GPIOG7 = 55

enumerator GPIOH0 = 56

enumerator GPIOH1 = 57

enumerator GPIOH2 = 58

enumerator GPIOH3 = 59

enumerator GPIOH4 = 60

enumerator GPIOH5 = 61

enumerator GPIOH6 = 62

enumerator GPIOH7 = 63

10 Chapter 3. GPIO

Page 15: libe Documentation

CHAPTER 4

I2C

Only a single I2C driver can be used for the time being. If you use the bitbang driver then you cannot use target builtinI2C driver. Nor can you use two different builtin drivers.

4.1 Configuration

4.1.1 Enable I2C module

To enable I2C, flag USE_I2C must be defined globally.

In Makefile:

USE += I2C

From command line when compiling:

make use=i2c

4.2 Master drivers

4.2.1 X86, RPI and other linux based systems

Linux based systems use /dev/i2c interface:

• context for i2c_master_open() must be an absolute path, i.e. "/dev/i2c-13".

• rest of the parameters after context do not matter

Opening multiple masters is supported.

11

Page 16: libe Documentation

libe Documentation, Release alpha

4.2.2 AVR

AVR’s have only single I2C interface as far as I know so:

• frequency must be valid for i2c_master_open() or use 0 to fallback to default 100 kHz

– closest available bitrate register value will then be calculated using (𝐹_𝐶𝑃𝑈/𝑓𝑟𝑒𝑞𝑢𝑒𝑛𝑐𝑦 − 16)/2

– negative results are rounded up to zero

• rest of the parameters do not matter, even master can be NULL

4.2.3 Bitbang driver

Bitbang driver is available on all targets that are GPIO capable.

Static mode

Mostly for optimizations sake on small targets, the bitbang driver requires clock and data pins to be defined in compiletime as defines.

Because of this none of the parameters to i2c_master_open() matter.

To enable static bitbang driver with I2C, following conditions must be met:

• enable bitbang driver by defining USE_I2C_BITBANG globally with USE_I2C and USE_GPIO

• define I2C clock and data pins using I2C_BITBANG_SCL and I2C_BITBANG_SDA

In Makefile:

USE += GPIO I2C I2C_BITBANG# define target specific pinsDEFINES_AVR += I2C_BITBANG_SCL=<PIN> I2C_BITBANG_SDA=<PIN>DEFINES_PIC8 += I2C_BITBANG_SCL=<PIN> I2C_BITBANG_SDA=<PIN>

From command line when compiling:

make use="gpio i2c i2c_bitbang" defines="I2C_BITBANG_SCL=<PIN> I2C_BITBANG_SDA=<PIN>"

Dynamic mode

I2C bitbang driver can also be configured to use dynamic run-time values for clock and data pins.

This mode should not be used on smaller targets. It is slow and compiles ineffectively as a large piece of code exampleon targets AVR and PIC8.

On the other hand, you can open multiple masters using different GPIO pins in this mode.

To enable dynamic bitbang driver with I2C, following conditions must be met:

• enable bitbang driver by defining USE_I2C_BITBANG globally with USE_I2C and USE_GPIO

• set bitbang driver into dynamic mode with USE_I2C_BITBANG_DYNAMIC

• call i2c_master_open() with valid values for master, frequency, scl_pin and sda_pin

In Makefile:

12 Chapter 4. I2C

Page 17: libe Documentation

libe Documentation, Release alpha

USE += GPIO I2C I2C_BITBANG USE_I2C_BITBANG_DYNAMIC

Frequency

As default the frequency will be set using a delay according to following rules:

• If dynamic mode is enabled using USE_I2C_BITBANG_DYNAMIC, then delay is frequency given toi2c_master_open() and implemented as os_sleepf(1 / master->frequency / 2) which isvery inaccurate on smaller targets

• If target is AVR then _delay_loop1(F_CPU / 200000 / 3) is used to achieve an inaccurate approxi-mate of 100 kHz

• On other targets os_delay_us(4) is used to achieve an inaccurate approximate of 100 kHz

Bitbang driver also supports custom delay. This can be defined using I2C_BITBANG_DELAY_FUNC macro. Re-member that delay function should create a delay half of the actual frequency since it is called twice per clock cycleto generate the clock for I2C.

In Makefile:

DEFINES += I2C_BITBANG_DELAY_FUNC=your_delay_func_or_macro()

4.3 Functions

int8_t i2c_master_open(struct i2c_master *master, void *context, uint32_t frequency, uint8_t scl_pin,uint8_t sda_pin)

Parameters

• master (struct i2c_master *) – pointer to preallocated memory

• context (void *) – driver specific context

• frequency (uint32_t) – I2C frequency, used only if driver supports setting frequency

• scl_pin (uint8_t) – I2C clock GPIO, used only if driver supports changing scl

• sda_pin (uint8_t) – I2C data GPIO, used only if driver supports changing sda

Returns 0 on success, negative value on errors

Open I2C driver in master mode.

void i2c_master_close(struct i2c_master *master)

Parameters

• master (struct i2c_master *) – previously opened master

Close I2C driver.

int8_t i2c_open(struct i2c_device *dev, struct i2c_master *master, uint8_t address)

Parameters

• dev (struct i2c_device *) – pointer to preallocated memory

• master (struct i2c_master *) – previously opened master

• address (uint8_t) – device address

4.3. Functions 13

Page 18: libe Documentation

libe Documentation, Release alpha

Returns

• 0 on success

• -1 if device did not respond

Try to open I2C device connected to master.

void i2c_close(struct i2c_device *dev)

Parameters

• dev (struct i2c_device *) – previously opened i2c device

Close I2C device.

int8_t i2c_read(struct i2c_device *dev, void *data, int8_t size)

Parameters

• dev (struct i2c_device *) – previously opened i2c device

• data (void *) – pointer to a buffer where to save read data

• size (int8_t) – count of bytes to read

Returns

• 0 on success

• -1 if device did not respond

Read data from I2C device.

int8_t i2c_write(struct i2c_device *dev, void *data, int8_t size)

Parameters

• dev (struct i2c_device *) – previously opened i2c device

• data (void *) – pointer to data to be written

• size (int8_t) – count of bytes to write

Returns

• 0 on success

• -1 if device did not respond

Write data to I2C device. Setting data = NULL and size = 0 can be used to detect if there is a deviceconnected to the address used by device. This is done automatically when calling i2c_open().

int8_t i2c_write_byte(struct i2c_device *dev, uint8_t value)

Parameters

• dev (struct i2c_device *) – previously opened i2c device

• value (uint8_t) – value to write

Returns 1 on success

Write single byte to I2C device.

int8_t i2c_write_reg_byte(struct i2c_device *dev, uint8_t reg, uint8_t value)

Parameters

• dev (struct i2c_device *) – previously opened i2c device

14 Chapter 4. I2C

Page 19: libe Documentation

libe Documentation, Release alpha

• reg (uint8_t) – register to write

• value (uint8_t) – value to write

Returns 0 on success

Write register value to I2C device. This is same as writing two bytes to I2C device, in this case reg followedby value.

uint8_t i2c_read_reg_byte(struct i2c_device *dev, uint8_t reg)

Parameters

• dev (struct i2c_device *) – previously opened i2c device

• reg (uint8_t) – register to read

Returns

• register value on success

• 255 on errors, which can be also a valid value read from a register

Read register from I2C device. This is same as writing a single byte to device and then reading a single bytefrom it.

4.3. Functions 15

Page 20: libe Documentation

libe Documentation, Release alpha

16 Chapter 4. I2C

Page 21: libe Documentation

CHAPTER 5

SPI

To be written.

17

Page 22: libe Documentation

libe Documentation, Release alpha

18 Chapter 5. SPI

Page 23: libe Documentation

CHAPTER 6

Sensors

6.1 Reference

Reference for following capitalized words in this page:

• SENSOR

– sensor name being used (as a prefix to functions), e.g. hdc1080 or adc which then translates tohdc1080_open(..) or adc_read(..)

• DEV

– struct i2c_device * in case of sensor connected to I2C bus

– struct spi_device * in case of sensor connected to SPI bus

– other device structs depending on bus and so on

• MASTER

– struct i2c_master * in case of sensor connected to I2C bus

– struct spi_master * in case of sensor connected to SPI bus

– other master structs depending on bus and so on

6.2 Generic Functions

int8_t SENSOR_open(DEV, MASTER, int32_t ref, int32_t cfg)

Parameters

• DEV – See Reference

• MASTER – See Reference

• ref (int32_t) – Reference information to driver

19

Page 24: libe Documentation

libe Documentation, Release alpha

– I2C: Optional address if device supports more than one, set to zero to use default

– SPI: Slave select pin

• cfg (int32_t) – Driver specific configuration option

– T&H sensors: Device specific measurement resolution or similar setting

– 0: use default

– -1: skip configuration and use what ever the chip is using currently

Returns

• 0 on success

• -1 if device not found

• -2 on other errors, e.g. configuration failed

void SENSOR_close(DEV)

Parameters

• DEV – See Reference

6.3 ADC

Analog to digital converters.

6.3.1 Functions

int8_t SENSOR_vref(DEV, float vref)

Parameters

• DEV – See Reference

• vref (float) – Reference voltage to use when reading

Returns

• 0 on success

• -1 if device not found

• -2 on other errors

Set reference voltage used by ADC. Default is 1.0 volts.

See SENSOR_read().

int8_t SENSOR_zero(DEV, float zero)

Parameters

• DEV – See Reference

• zero (float) – Zero offset to apply when reading

Returns 0

Set zero offset. Default is zero which means no effect.

See SENSOR_read().

20 Chapter 6. Sensors

Page 25: libe Documentation

libe Documentation, Release alpha

int8_t SENSOR_multiplier(DEV, float multiplier)

Parameters

• DEV – See Reference

• multiplier (float) – Multiplier to apply when reading

Returns 0

Default is 1.0.

See SENSOR_read().

int8_t SENSOR_read(DEV, int32_t *raw, float *value)

Parameters

• DEV – See Reference

• *raw (int32_t) – Save raw reading here if not NULL.

Note that differential ADC readings can be negative. *raw is a 32 bit signed integer whichmeans that example a 16 bit differential ADC reading is returned between -32768..32767 asa 32 bit signed integer, not 16 bits of raw data saved in 32 bit signed integer.

• *value (float) – Save converted value here after applying formula shown in description.Can be NULL.

Returns

• 0 on success

• -1 if device not found

• -2 on other errors

Read ADC value. Formula applied to raw value for converting it to *value:

(𝑅𝐴𝑊_𝑉 𝐴𝐿𝑈𝐸/𝑀𝐴𝑋_𝑉 𝐴𝐿𝑈𝐸 * 𝑣𝑟𝑒𝑓 − 𝑧𝑒𝑟𝑜) *𝑚𝑢𝑙𝑡𝑖𝑝𝑙𝑖𝑒𝑟

6.3.2 ADC Drivers

None at the moment. Only documentation written to be used when writing actual drivers.

adc (internal)

Internal device ADC driver, if exists.

6.4 Temperature and Humidity

Temperature and humidity sensors are combined together under same API.

Note: Even sensors that provide only one use the same API.

6.4. Temperature and Humidity 21

Page 26: libe Documentation

libe Documentation, Release alpha

6.4.1 Functions

int8_t SENSOR_heater(DEV, bool on)

Parameters

• DEV – See Reference

• on (bool) – Heater on or off

Returns

• 0 on success

• -1 if device not found

• -2 on other errors

• -3 if device has no heater

Enable internal heater if device has such. Usually heater will only apply heat when a measurement is requestedso in order to actually heat the device sensor should be read continuously.

int8_t SENSOR_read(DEV, float *t, float *h)

Parameters

• DEV – See Reference

• *t (float) – Save temperature here if not NULL

– Set to -274 if device does not support temperature reading

– Set to -275.0 on other errors, e.g. reading failed

• *h (float) – Save humidity here if not NULL

– Set to -1 if device does not support humidity reading

– Set to -2 on other errors, e.g. reading failed

Returns

• 0 on success

• -1 if device not found

• -2 on other errors

Read device temperature and humidity values.

6.4.2 T&H Drivers

hdc1080

SENSOR_open()

• ref is not used

• cfg is resolution

– 14 bits (default)

– 11 bits

SENSOR_heater()

22 Chapter 6. Sensors

Page 27: libe Documentation

libe Documentation, Release alpha

• Has a heater

sht21

SENSOR_open()

• ref is not used

• cfg is resolution

– 14: T = 14 bits, RH = 12 bits (default)

– 13: T = 13 bits, RH = 10 bits

– 12: T = 12 bits, RH = 8 bits

– 11: T = 11 bits, RH = 11 bits

SENSOR_heater()

• Has a heater

sht31

SENSOR_open()

• ref is I2C address

– 0x44 (default)

– 0x45

• cfg is repeatability

enumerator SHT31_REPEATABILITY_HIGH = 0x00

enumerator SHT31_REPEATABILITY_MEDIUM = 0x0b

enumerator SHT31_REPEATABILITY_LOW = 0x16

SENSOR_heater()

• Has a heater

6.4. Temperature and Humidity 23

Page 28: libe Documentation

libe Documentation, Release alpha

24 Chapter 6. Sensors

Page 29: libe Documentation

CHAPTER 7

Encryption

All these encryption methods use primarily software. No hardware drivers implemented, at least not yet.

7.1 AES

Software AES support thanks to AndrewCarterUK from SmarterDM.

• Supported key sizes are 128, 192 and 256 bits (10/12/14 rounds for each)

• Block size is 128 bits

To enable AES set USE_AES.

void aes_128_init(aes_128_context_t *context, uint8_t key[16])

void aes_128_encrypt(aes_128_context_t *context, uint8_t block[16])

void aes_128_decrypt(aes_128_context_t *context, uint8_t block[16])

void aes_192_init(aes_192_context_t *context, uint8_t key[24])

void aes_192_encrypt(aes_192_context_t *context, uint8_t block[16])

void aes_192_decrypt(aes_192_context_t *context, uint8_t block[16])

void aes_256_init(aes_256_context_t *context, uint8_t key[32])

void aes_256_encrypt(aes_256_context_t *context, uint8_t block[16])

void aes_256_decrypt(aes_256_context_t *context, uint8_t block[16])

7.1.1 Defines

enumerator AES_128_ROUNDS = 10

enumerator AES_192_ROUNDS = 12

enumerator AES_256_ROUNDS = 14

25

Page 30: libe Documentation

libe Documentation, Release alpha

7.2 RC5

Should be only really used in very resource constrained platforms.

• Key size is 128 bits as default

• Block size is fixed to 64 bits

• Rounds is 12 as default

To enable RC5 set USE_RC5.

void rc5_init(rc5_context_t *rc5, void *key)

Parameters

• rc5 (rc5_context_t *) – pointer to preallocated memory

• key (void *) – pointer to memory holding binary key, must be at least 16 bytes

void rc5_encrypt(rc5_context_t *rc5, void *block)

Parameters

• rc5 (rc5_context_t *) – previously initialized context

• block (void *) – pointer to memory holding binary data to be encrypted, must be at least8 bytes

void rc5_decrypt(rc5_context_t *rc5, void *block)

Parameters

• rc5 (rc5_context_t *) – previously initialized context

• block (void *) – pointer to memory holding binary data to be decrypted, must be at least8 bytes

7.2.1 Defines

enumerator RC5_KEY_LEN = 16Key length in bytes. Can be overridden by defining other value globally.

enumerator RC5_ROUNDS = 12Rounds. Can be overridden by defining other value globally.

7.3 XTEA

Should be only really used in very resource constrained platforms.

Note: This implementation has not been properly evaluated against others since there are so few. It isanyways almost a direct copy-paste from wikipedia.

• Key size is 128 bits

• Block size is 64 bits

• Rounds is 32

To enable XTEA set USE_XTEA.

26 Chapter 7. Encryption

Page 31: libe Documentation

libe Documentation, Release alpha

void xtea_encrypt(void *block, void *key)

void xtea_decrypt(void *block, void *key)

7.4 XXTEA

Should be only really used in very resource constrained platforms.

Note: This implementation has not been properly evaluated against others since there are so few. It isanyways almost a direct copy-paste from wikipedia.

• Key size is 128 bits

• Block size must be at least 64 bits (8 bytes) and multiples of 32 bits (4 bytes)

• Rounds is 32

To enable XXTEA set USE_XXTEA.

void xxtea_encrypt(void *data, size_t size, void *key)

void xxtea_decrypt(void *data, size_t size, void *key)

7.4. XXTEA 27

Page 32: libe Documentation

libe Documentation, Release alpha

28 Chapter 7. Encryption

Page 33: libe Documentation

Index

Aaes_128_decrypt (C function), 25aes_128_encrypt (C function), 25aes_128_init (C function), 25AES_128_ROUNDS (C++ enumerator), 25aes_192_decrypt (C function), 25aes_192_encrypt (C function), 25aes_192_init (C function), 25AES_192_ROUNDS (C++ enumerator), 25aes_256_decrypt (C function), 25aes_256_encrypt (C function), 25aes_256_init (C function), 25AES_256_ROUNDS (C++ enumerator), 25

Ggpio_enable (C function), 7gpio_high (C function), 8gpio_input (C function), 8gpio_low (C function), 8gpio_output (C function), 8gpio_read (C function), 8gpio_set (C function), 8GPIOA0 (C++ enumerator), 8GPIOA1 (C++ enumerator), 8GPIOA2 (C++ enumerator), 8GPIOA3 (C++ enumerator), 8GPIOA4 (C++ enumerator), 8GPIOA5 (C++ enumerator), 8GPIOA6 (C++ enumerator), 8GPIOA7 (C++ enumerator), 8GPIOB0 (C++ enumerator), 8GPIOB1 (C++ enumerator), 8GPIOB2 (C++ enumerator), 8GPIOB3 (C++ enumerator), 9GPIOB4 (C++ enumerator), 9GPIOB5 (C++ enumerator), 9GPIOB6 (C++ enumerator), 9GPIOB7 (C++ enumerator), 9GPIOC0 (C++ enumerator), 9

GPIOC1 (C++ enumerator), 9GPIOC2 (C++ enumerator), 9GPIOC3 (C++ enumerator), 9GPIOC4 (C++ enumerator), 9GPIOC5 (C++ enumerator), 9GPIOC6 (C++ enumerator), 9GPIOC7 (C++ enumerator), 9GPIOD0 (C++ enumerator), 9GPIOD1 (C++ enumerator), 9GPIOD2 (C++ enumerator), 9GPIOD3 (C++ enumerator), 9GPIOD4 (C++ enumerator), 9GPIOD5 (C++ enumerator), 9GPIOD6 (C++ enumerator), 9GPIOD7 (C++ enumerator), 9GPIOE0 (C++ enumerator), 9GPIOE1 (C++ enumerator), 9GPIOE2 (C++ enumerator), 9GPIOE3 (C++ enumerator), 9GPIOE4 (C++ enumerator), 9GPIOE5 (C++ enumerator), 9GPIOE6 (C++ enumerator), 9GPIOE7 (C++ enumerator), 9GPIOF0 (C++ enumerator), 9GPIOF1 (C++ enumerator), 9GPIOF2 (C++ enumerator), 9GPIOF3 (C++ enumerator), 9GPIOF4 (C++ enumerator), 9GPIOF5 (C++ enumerator), 9GPIOF6 (C++ enumerator), 9GPIOF7 (C++ enumerator), 10GPIOG0 (C++ enumerator), 10GPIOG1 (C++ enumerator), 10GPIOG2 (C++ enumerator), 10GPIOG3 (C++ enumerator), 10GPIOG4 (C++ enumerator), 10GPIOG5 (C++ enumerator), 10GPIOG6 (C++ enumerator), 10GPIOG7 (C++ enumerator), 10GPIOH0 (C++ enumerator), 10

29

Page 34: libe Documentation

libe Documentation, Release alpha

GPIOH1 (C++ enumerator), 10GPIOH2 (C++ enumerator), 10GPIOH3 (C++ enumerator), 10GPIOH4 (C++ enumerator), 10GPIOH5 (C++ enumerator), 10GPIOH6 (C++ enumerator), 10GPIOH7 (C++ enumerator), 10

Ii2c_close (C function), 14i2c_master_close (C function), 13i2c_master_open (C function), 13i2c_open (C function), 13i2c_read (C function), 14i2c_read_reg_byte (C function), 15i2c_write (C function), 14i2c_write_byte (C function), 14i2c_write_reg_byte (C function), 14

Oos_delay_ms (C macro), 6os_delay_us (C macro), 6os_init (C function), 5os_quit (C function), 5os_sleepf (C function), 5os_sleepi (C function), 5os_time_t (C type), 6os_timef (C function), 5os_timei (C function), 5

Rrc5_decrypt (C function), 26rc5_encrypt (C function), 26rc5_init (C function), 26RC5_KEY_LEN (C++ enumerator), 26RC5_ROUNDS (C++ enumerator), 26

SSENSOR_close (C function), 20SENSOR_heater (C function), 22SENSOR_multiplier (C function), 20SENSOR_open (C function), 19SENSOR_read (C function), 21, 22SENSOR_vref (C function), 20SENSOR_zero (C function), 20SHT31_REPEATABILITY_HIGH (C++ enumerator),

23SHT31_REPEATABILITY_LOW (C++ enumerator),

23SHT31_REPEATABILITY_MEDIUM (C++ enumera-

tor), 23

Xxtea_decrypt (C function), 27

xtea_encrypt (C function), 26xxtea_decrypt (C function), 27xxtea_encrypt (C function), 27

30 Index