DSerial Library

From NaWiki

Jump to: navigation, search

Contents

Description

libdserial allows to use DSerial in DS homebrews.

Functions

Configuration

Initializing DSerial

bool dseInit()

Initializes DSerial. Returns false if DSerial wasn't detected.

Matching DSerial Firmware

bool dseMatchFirmware(char * data, unsigned int size)

Compares given firmware image to the firmware on DSerial flash. If false is returned, firmwares do not mach and you should update DSerial firmware using dseUploadFirmware().

Uploading DSerial Firmware

bool dseUploadFirmware(char * data, unsigned int size)

Uploads raw firmware data into DSerial. data should be a proper Firmware Image with a CRC. Returns false if firmware upload failed.

Switch between Bootloader and Firmware

bool dseBoot()

Boots firmware if we're in bootloader. Boots bootloader if we're in firmware. Returns false if operation failed.

Checking DSerial Status

DseStatus dseStatus()

Returns the current status of DSerial: DISCONNECTED, BOOTLOADER or FIRMWARE.

Checking DSerial Version

int dseVersion()

Returns the version of DSerial hardware. Returns 0 for DSerial1/2. Returns 2 for DSerial Edge.

UART

Setting Baudrate

bool dseUartSetBaudrate(DseUart uart, unsigned int baudrate)

Sets baud rate for given UART (UART0 or UART1). Returns false if operation failed.

Receiving Data

You need to provide a function which gets called when UART data is received.

void dseUartSetReceiveHandler(DseUart uart, void (*receiveHandler)(char * data, unsigned int size))

Sets receive handler for given UART (UART0 or UART1). Handler gets called when data has arrived. Set to NULL to stop.

Sending Data

bool dseUartSendBuffer(DseUart uart, char * data, unsigned int size, bool block = false)

Sends data on the specified UART (UART0 or UART1). size is maximum 32. Returns false if something went wrong. If non-blocking, function will return before data is finished sending. Once data transfer is complete, your send handler function will be called (if it is set). In blocking mode, dseUartSendBuffer() will return only when data is finished sending. This should be used mostly for testing.

void dseUartSetSendHandler(DseUart uart, int (*sendHandler)(void))

Sets send handler for the specified UART (UART0 or UART1). Handler gets called when data send is completed. Set to NULL to stop.

GPIO

Setting Direction of a Pin

void dsePinMode(uint8 port, uint8 pin, DsePinMode mode)

Sets the mode of a pin: OUTPUT, INPUT or ANALOG_INPUT. port can be PORT0 - PORT3, pin can be 0-7. Please check DSerial IO schematic for available pins. (Note: P1.0 and P1.1 are used by the LEDs.)

Writing a Digital Output

void dsePinWrite(uint8 port, uint8 pin, bool state)

Outputs logical state on a digital pin of given port. To output a high set state to true. To output a low set state to false. Please set the pin to OUTPUT using dsePinMode() first.

Reading a Digital Input

bool dsePinRead(uint8 port, uint8 pin)

Reads logical state of a digital pin of given port. Returns true if state is high, false if state is low. Please set the pin to INPUT using dsePinMode() first.

Reading an Analog Input

uint16 dsePinReadAnalog(uint8 port, uint8 pin)

Reads analog state from analog pin of given port. A 10-bit analog-to-digital converter is used corresponding to a range of 0x0 - 0x3FF. Please set the pin to ANALOG_INPUT using dsePinMode() first.

Personal tools