My Project
Public Member Functions | Static Public Attributes | List of all members
kicon_badge.KiconBadge Class Reference

Public Member Functions

def __init__ (self, port)
 
def __del__ (self)
 
def init (self)
 Initializes the badge to a valid state. More...
 
def uart_transfer (self, data)
 Transfers data over UART. More...
 
def lcd_clear (self)
 Clears the display buffer. More...
 
def lcd_refresh (self)
 Redraws the display buffer. More...
 
def lcd_pixel (self, x, y, color)
 Draws a pixel in the display buffer. More...
 
def lcd_text (self, row, col, text)
 Draws a text in the display buffer. More...
 
def led_set (self, led, state)
 Turns on/off an LED. More...
 
def led_blink (self, led, period)
 Keeps blinking an LED. More...
 
def buttons (self)
 Returns the button state. More...
 
def i2c_set_clock_khz (self, clock_khz)
 Reconfigures I2C clock frequency. More...
 
def i2c_read (self, dev_addr, reg_addr, length)
 Reads registers over I2C. More...
 
def i2c_write (self, dev_addr, reg_addr, data)
 Writes registers over I2C. More...
 
def spi_config (self, clock_khz, mode)
 Configures the SPI peripheral. More...
 
def spi_transfer (self, data_in)
 Transfers data over SPI. More...
 

Static Public Attributes

int LED1 = 0
 
int LED2 = 1
 
int BUT_RIGHT = 1
 
int BUT_LEFT = 2
 
int BUT_DOWN = 4
 
int BUT_UP = 8
 
int BLACK = 0
 
int WHITE = 1
 
int LCD_WIDTH = 128
 
int LCD_HEIGHT = 64
 

Member Function Documentation

◆ buttons()

def kicon_badge.KiconBadge.buttons (   self)

Returns the button state.

Note that it is impossible to read 'left' button state, as it quits the command interface mode.

Returns
Number indicating pressed buttons (BUT_RIGHT, BUT_DOWN, BUT_UP).

◆ i2c_read()

def kicon_badge.KiconBadge.i2c_read (   self,
  dev_addr,
  reg_addr,
  length 
)

Reads registers over I2C.

Parameters
dev_addris the 7-bit device address.
reg_addris the register address.
lengthis number of bytes to read.
Returns
Registers contents.

◆ i2c_set_clock_khz()

def kicon_badge.KiconBadge.i2c_set_clock_khz (   self,
  clock_khz 
)

Reconfigures I2C clock frequency.

The default I2C clock frequency is 100 kHz. It does not affect the clock for the display data transfers (400 kHz).

Parameters
clock_khzis the requested clock frequency [kHz, 1-400].

◆ i2c_write()

def kicon_badge.KiconBadge.i2c_write (   self,
  dev_addr,
  reg_addr,
  data 
)

Writes registers over I2C.

Parameters
dev_addris the 7-bit device address.
reg_addris the register address.
dataare the bytes to be written.

◆ init()

def kicon_badge.KiconBadge.init (   self)

Initializes the badge to a valid state.

Should be called whenever the badge state is unknown.

◆ lcd_clear()

def kicon_badge.KiconBadge.lcd_clear (   self)

Clears the display buffer.

◆ lcd_pixel()

def kicon_badge.KiconBadge.lcd_pixel (   self,
  x,
  y,
  color 
)

Draws a pixel in the display buffer.

Parameters
xis the horizontal coordinate (0-127).
yis the vertical coordinate (0-63).
coloris the pixel color (BLACK [0] or WHITE [1]).

◆ lcd_refresh()

def kicon_badge.KiconBadge.lcd_refresh (   self)

Redraws the display buffer.

◆ lcd_text()

def kicon_badge.KiconBadge.lcd_text (   self,
  row,
  col,
  text 
)

Draws a text in the display buffer.

Parameters
rowis the row number (0-7).
colis the column number (0-63).
textis the string to be drawn.

◆ led_blink()

def kicon_badge.KiconBadge.led_blink (   self,
  led,
  period 
)

Keeps blinking an LED.

Parameters
ledis the LED number (LED1 [0] or LED2 [1]).
periodis the blinking period.

◆ led_set()

def kicon_badge.KiconBadge.led_set (   self,
  led,
  state 
)

Turns on/off an LED.

Parameters
ledis the LED number (LED1 [0] or LED2 [1]).
stateis the requested LED state (0 - off, 1 - on).

◆ spi_config()

def kicon_badge.KiconBadge.spi_config (   self,
  clock_khz,
  mode 
)

Configures the SPI peripheral.

Parameters
clock_khzis the clock frequency [1-60000 kHz].
modeis the SPI mode: 0: capture data on rising clock edge, shift data on falling clock edge, inactive clock low 1: capture data on falling clock edge, shift data on rising clock edge, inactive clock low 2: capture data on falling clock edge, shift data on rising clock edge, inactive clock high 3: capture data on rising clock edge, shift data on falling clock edge, inactive clock high

◆ spi_transfer()

def kicon_badge.KiconBadge.spi_transfer (   self,
  data_in 
)

Transfers data over SPI.

Uses PB14 (DAC1) as the active-low chip select.

Parameters
data_inare the bytes to be transferred.
returnsreceived data.

◆ uart_transfer()

def kicon_badge.KiconBadge.uart_transfer (   self,
  data 
)

Transfers data over UART.

Parameters
dataare bytes to be sent
Returns
Received data (if any).

The documentation for this class was generated from the following file: