Difference between revisions of "DSerial Library"

From NaWiki
Jump to: navigation, search
(Sending Data)
(UART)
 
(3 intermediate revisions by the same user not shown)
Line 62: Line 62:
 
</cpp>
 
</cpp>
  
Sets baud rate for given UART. Returns <b>false</b> if operation failed.
+
Sets baud rate for given UART (UART0 or UART1). Returns <b>false</b> if operation failed.
  
 
==== Receiving Data ====
 
==== Receiving Data ====
Line 72: Line 72:
 
</cpp>
 
</cpp>
  
Sets receive handler for given UART. Handler gets called when data has arrived. Set to <b>NULL</b> to stop.
+
Sets receive handler for given UART (UART0 or UART1). Handler gets called when data has arrived. Set to <b>NULL</b> to stop.
  
 
==== Sending Data ====
 
==== Sending Data ====
Line 80: Line 80:
 
</cpp>
 
</cpp>
  
Sends data on the specified UART. <b>size</b> is maximum 32. Returns <b>false</b> 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.
+
Sends data on the specified UART (UART0 or UART1). <b>size</b> is maximum 32. Returns <b>false</b> 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>
 
<cpp>
Line 86: Line 86:
 
</cpp>
 
</cpp>
  
Sets send handler for the specified UART. Handler gets called when data send is completed. Set to <b>NULL</b> to stop.
+
Sets send handler for the specified UART (UART0 or UART1). Handler gets called when data send is completed. Set to <b>NULL</b> to stop.
  
 
=== GPIO ===
 
=== GPIO ===
Line 96: Line 96:
 
</cpp>
 
</cpp>
  
Sets the <b>mode</b> of a pin: OUTPUT, INPUT or ANALOG_INPUT. <b>port</b> can be PORT0 - PORT3, <b>pin</b> can be 0-7. Please check DSerial [[IO]] schematic for available pins.
+
Sets the <b>mode</b> of a pin: OUTPUT, INPUT or ANALOG_INPUT. <b>port</b> can be PORT0 - PORT3, <b>pin</b> 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 ====
 
==== Writing a Digital Output ====

Latest revision as of 18:43, 25 November 2008

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 (UART0 or UART1). 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 (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.

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

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

<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.