Difference between revisions of "DSerial Library"

From NaWiki
Jump to: navigation, search
m (UART)
(UART)
 
(10 intermediate revisions by 3 users not shown)
Line 2: Line 2:
  
 
<b>libdserial</b> allows to use DSerial in DS homebrews.
 
<b>libdserial</b> allows to use DSerial in DS homebrews.
 
Note: The following sections are subject to change in the near future.
 
  
 
== Functions ==
 
== Functions ==
  
 
=== Configuration ===
 
=== Configuration ===
 +
 +
==== Initializing DSerial ====
  
 
<cpp>
 
<cpp>
Line 14: Line 14:
  
 
Initializes DSerial. Returns <b>false</b> if DSerial wasn't detected.
 
Initializes DSerial. Returns <b>false</b> 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>
 
<cpp>
Line 21: Line 31:
 
Uploads raw [[firmware]] data into DSerial. <b>data</b> should be a proper [[Firmware Image]] with a CRC. Returns <b>false</b> if firmware upload failed.
 
Uploads raw [[firmware]] data into DSerial. <b>data</b> should be a proper [[Firmware Image]] with a CRC. Returns <b>false</b> if firmware upload failed.
  
 +
==== Switch between Bootloader and Firmware ====
 
<cpp>
 
<cpp>
 
bool dseBoot()
 
bool dseBoot()
Line 26: Line 37:
  
 
Boots [[firmware]] if we're in [[bootloader]]. Boots bootloader if we're in firmware. Returns <b>false</b> if operation failed.
 
Boots [[firmware]] if we're in [[bootloader]]. Boots bootloader if we're in firmware. Returns <b>false</b> 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 ===
 
=== UART ===
 +
 +
==== Setting Baudrate ====
  
 
<cpp>
 
<cpp>
bool dseUartSetBaudrate(unsigned int baudrate)
+
bool dseUartSetBaudrate(DseUart uart, unsigned int baudrate)
 
</cpp>
 
</cpp>
  
Sets [[UART]] baud rate. 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 ====
 +
 
 +
You need to provide a function which gets called when UART data is received.
  
 
<cpp>
 
<cpp>
void dseUartSetReceiveHandler(void (*receiveHandler)(char * data, unsigned int size))
+
void dseUartSetReceiveHandler(DseUart uart, void (*receiveHandler)(char * data, unsigned int size))
 
</cpp>
 
</cpp>
  
Sets [[UART]] receive handler. 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 ====
  
 
<cpp>
 
<cpp>
void dseUartSetSendHandler(int (*sendHandler)(void))
+
bool dseUartSendBuffer(DseUart uart, char * data, unsigned int size, bool block = false)
 
</cpp>
 
</cpp>
  
Sets [[UART]] send handler. Handler gets called when data send is completed. Set to <b>NULL</b> to stop.
+
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>
bool dseUartSendBuffer(char * data, unsigned int size, bool block = false)
+
void dseUartSetSendHandler(DseUart uart, int (*sendHandler)(void))
 
</cpp>
 
</cpp>
  
Sends data on the [[UART]] port. <b>size</b> is maximum 32. Returns <b>false</b> if something went wrong.
+
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.
  
=== Tilt ===
+
=== GPIO ===
  
To be written.
+
==== Setting Direction of a Pin ====
  
=== I/O ===
+
<cpp>
 +
void dsePinMode(uint8 port, uint8 pin, DsePinMode mode)
 +
</cpp>
  
To be written.
+
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.)
  
=== ADC ===
+
==== Writing a Digital Output ====
  
To be written.
+
<cpp>
 +
void dsePinWrite(uint8 port, uint8 pin, bool state)
 +
</cpp>
  
=== PWM ===
+
Outputs logical state on a digital <b>pin</b> of given <b>port</b>. To output a high set <b>state</b> to true. To output a low set <b>state</b> to false. Please set the pin to OUTPUT using dsePinMode() first.
  
To be written.
+
==== Reading a Digital Input ====
  
=== USB Device ===
+
<cpp>
 +
bool dsePinRead(uint8 port, uint8 pin)
 +
</cpp>
  
To be written.
+
Reads logical state of a digital <b>pin</b> of given <b>port</b>. Returns true if state is high, false if state is low. Please set the pin to INPUT using dsePinMode() first.
  
=== Misc ===
+
==== Reading an Analog Input ====
 +
 
 +
<cpp>
 +
uint16 dsePinReadAnalog(uint8 port, uint8 pin)
 +
</cpp>
  
To be written.
+
Reads analog state from analog <b>pin</b> of given <b>port</b>. 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.

Latest revision as of 19: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.