Libndls: Difference between revisions

From Hackspire
Jump to navigation Jump to search
(hwtype() now a function)
(is_classic)
Line 28: Line 28:
*<tt>BOOL any_key_pressed(void)</tt>: non-blocking key press test. Return <tt>TRUE</tt> if one or more keys are being pressed.
*<tt>BOOL any_key_pressed(void)</tt>: non-blocking key press test. Return <tt>TRUE</tt> if one or more keys are being pressed.
*<tt>BOOL isKeyPressed(key)</tt>: non-blocking key press test. <tt>key</tt> must be one of the <tt>KEY_NSPIRE_*</tt> constants defined in ''include/common.h''.
*<tt>BOOL isKeyPressed(key)</tt>: non-blocking key press test. <tt>key</tt> must be one of the <tt>KEY_NSPIRE_*</tt> constants defined in ''include/common.h''.
*<tt>BOOL on_key_pressed(void)</tt>: since v3.0. Non-blocking ON key press test.
*<tt>BOOL on_key_pressed(void)</tt>: since v3.1. Non-blocking ON key press test.
*<tt>void wait_key_pressed(void)</tt>: block until a key is pressed
*<tt>void wait_key_pressed(void)</tt>: block until a key is pressed
*<tt>void wait_no_key_pressed(void)</tt>: block until all the keys are released
*<tt>void wait_no_key_pressed(void)</tt>: block until all the keys are released
Line 36: Line 36:
==CPU==
==CPU==
*<tt>void clear_cache(void)</tt>: flush the data cache and invalidate the instruction and data caches of the processor. Should be called before loading code dynamically, after a code patch or with self-modifying code.
*<tt>void clear_cache(void)</tt>: flush the data cache and invalidate the instruction and data caches of the processor. Should be called before loading code dynamically, after a code patch or with self-modifying code.
*<tt>unsigned set_cpu_speed(unsigned speed)</tt>: since v3.0. ''speed'' is one of <tt>CPU_SPEED_150MHZ</tt>, <tt>CPU_SPEED_120MHZ</tt>, <tt>CPU_SPEED_90MHZ</tt>. Returns the previous speed. You must restore the original speed before the program exits.
*<tt>unsigned set_cpu_speed(unsigned speed)</tt>: since v3.1. ''speed'' is one of <tt>CPU_SPEED_150MHZ</tt>, <tt>CPU_SPEED_120MHZ</tt>, <tt>CPU_SPEED_90MHZ</tt>. Returns the previous speed. You must restore the original speed before the program exits.


==Hardware==
==Hardware==
*<tt>BOOL is_cx</tt>: <tt>TRUE</tt> on a TI-Nspire CX.
*<tt>BOOL is_classic</tt>: since v3.1. <tt>TRUE</tt> on classic TI-Nspire. This is the preferred way to check CX-specific features: ''if (is_classic) classic_code; else cx_code;''
*<tt>BOOL is_touchpad</tt>: <tt>TRUE</tt> on a TI-Nspire Touchpad.
*<tt>BOOL is_cx</tt>: since v3.1. <tt>TRUE</tt> on TI-Nspire CX.
*<tt>unsigned hwtype()</tt>: 0 on original TI-Nspire, 1 on TI-Nspire CX
*<tt>BOOL is_touchpad</tt>: <tt>TRUE</tt> on a TI-Nspire Touchpad or on a TI-Nspire CX.
*<tt>unsigned hwtype()</tt>: 0 on classic TI-Nspire, 1 on TI-Nspire CX.


==Time==
==Time==

Revision as of 08:18, 4 December 2011

libndls is a set of macros and functions available as a static library when building with Ndless. The library is automatically linked by nspire-ld if required.

These definitions are available in Ndless 2.0. Definitions marked with (asm) are only available in assembly.

Common types

  • typedef enum bool {FALSE = 0, TRUE = 1} BOOL;

Data manipulation

  • uint16_t bswap16(uint16_t): swap the bytes of a 2-bytes integer
  • uint32_t bswap32(uint32_t): swap the bytes of a 4-bytes integer

Math

  • number abs(number)
  • number min(number, number)
  • number max(number, number)

Screen

  • SCREEN_BASE_ADDRESS: address of the screen buffer. Each grayscaled pixel is 4-bit long. 1111 is white, 0000 is black.
  • SCREEN_BYTES_SIZE: size of the screen buffer
  • SCREEN_WIDTH: screen width in pixels
  • SCREEN_HEIGHT: screen height in pixels
  • void clrscr(void): clear the screen

UI

  • void show_msgbox(const char *title, const char *msg): show a message box, with a single button OK"

Keyboard

  • BOOL any_key_pressed(void): non-blocking key press test. Return TRUE if one or more keys are being pressed.
  • BOOL isKeyPressed(key): non-blocking key press test. key must be one of the KEY_NSPIRE_* constants defined in include/common.h.
  • BOOL on_key_pressed(void): since v3.1. Non-blocking ON key press test.
  • void wait_key_pressed(void): block until a key is pressed
  • void wait_no_key_pressed(void): block until all the keys are released
  • touchpad_info_t *touchpad_getinfo(void): return information on the Touchpad area such as its dimension. Return NULL if not a TI-Nspire Touchpad. See include/libndls.h for the definition of touchpad_info_t.
  • int touchpad_scan(touchpad_report_t *report): check user interactions with the Touchpad area and writes to report. See include/libndls.h for the definition of touchpad_report_t. report->contact and report->pressed are always FALSE on TI-Nspire Clickpad. See src/arm/tests/ndless_tpad.c for an example of use.

CPU

  • void clear_cache(void): flush the data cache and invalidate the instruction and data caches of the processor. Should be called before loading code dynamically, after a code patch or with self-modifying code.
  • unsigned set_cpu_speed(unsigned speed): since v3.1. speed is one of CPU_SPEED_150MHZ, CPU_SPEED_120MHZ, CPU_SPEED_90MHZ. Returns the previous speed. You must restore the original speed before the program exits.

Hardware

  • BOOL is_classic: since v3.1. TRUE on classic TI-Nspire. This is the preferred way to check CX-specific features: if (is_classic) classic_code; else cx_code;
  • BOOL is_cx: since v3.1. TRUE on TI-Nspire CX.
  • BOOL is_touchpad: TRUE on a TI-Nspire Touchpad or on a TI-Nspire CX.
  • unsigned hwtype(): 0 on classic TI-Nspire, 1 on TI-Nspire CX.

Time

  • void idle(void): switch to low-power state until the next interrupt occurs. The use of this function is encouraged when waiting in loops for an event to save the batteries.
  • void sleep(unsigned m): delay for a specified amount of time. The CPU is regularly switched to low-power state while blocking.

Debugging

  • void halt(void): stop the execution flow with an endless loop. If you are using the Ncubate emulator, use the j debugger command to jump over the instruction.
  • halt (asm) (macro): similar to halt()