DSerial Library

From NaWiki
Revision as of 18:42, 25 November 2008 by Natrium42 (talk | contribs) (Setting Baudrate)
Jump to: navigation, search

Description

libdserial allows to use DSerial in DS homebrews.

Functions

Configuration

Initializing DSerial

<cpp> bool dseInit() </cpp>

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

Matching DSerial Firmware

<cpp> bool dseMatchFirmware(char * data, unsigned int size) </cpp>

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

<cpp> bool dseUploadFirmware(char * data, unsigned int size) </cpp>

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

<cpp> bool dseBoot() </cpp>

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

Checking DSerial Status

<cpp> DseStatus dseStatus() </cpp>

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

Checking DSerial Version

<cpp> int dseVersion() </cpp>

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

UART

Setting Baudrate

<cpp> bool dseUartSetBaudrate(DseUart uart, unsigned int baudrate) </cpp>

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.

<cpp> void dseUartSetReceiveHandler(DseUart uart, void (*receiveHandler)(char * data, unsigned int size)) </cpp>

Sets receive handler for given UART. Handler gets called when data has arrived. Set to NULL to stop.

Sending Data

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

Sends data on the specified UART. 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.

<cpp> void dseUartSetSendHandler(DseUart uart, int (*sendHandler)(void)) </cpp>

Sets send handler for the specified UART. Handler gets called when data send is completed. Set to NULL to stop.

GPIO

Setting Direction of a Pin

<cpp> void dsePinMode(uint8 port, uint8 pin, DsePinMode mode) </cpp>

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

<cpp> void dsePinWrite(uint8 port, uint8 pin, bool state) </cpp>

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

<cpp> bool dsePinRead(uint8 port, uint8 pin) </cpp>

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

<cpp> uint16 dsePinReadAnalog(uint8 port, uint8 pin) </cpp>

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.