Battery blinks if >BATTERY_LEVEL_DANGEROUS
[kugel-rb.git] / firmware / API
blobcfd5aa8945c68009cf91000da3a03557ec8cdb9d
1 $Id$
2                __________               __   ___.
3      Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
4      Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
5      Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
6      Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
7                        \/            \/     \/    \/            \/
9                                  API summmary
11 [ This is still pretty rough and basic. Extend! ]
13 LCD
15   #include <lcd.h>
17   Generic
19     Most LCD functions are specific for which output we work with, due to the
20     huge differences.
22     lcd_init() - init the LCD stuff
23     lcd_clear_display() - clear the whole display
24     lcd_backlight(on) - set backlight on/off
25     lcd_puts(x,y,string) write a string at given character position
27   Recorder
29     All the functions operate on a display buffer. You make the buffer get
30     shown on screen by calling lcd_update().
32     lcd_update() update the LCD according to the internal buffer.
33     lcd_setfont(int font) set default font
34     lcd_setmargins(int x, int y) set top/left margins
35     lcd_putsxy(x,y,string,font) put a string at given position, using a
36                                 specific font
37     lcd_bitmap(src,x,y,width,height,clear) put a bitmap at given position
38     lcd_clearrect(x,y,width,height) clear a rectangle area
39     lcd_fillrect(x,y,width,height) fill a rectangle area
40     lcd_drawrect(x,y,width,height) draw a rectangle
41     lcd_invertrect(x,y,width,height) revert the graphics of the given area
42     lcd_drawline(x1,y1,x2,y2) draw a line between the coordinates
43     lcd_drawpixel(x,y) put a pixel on the given coordinate
44     lcd_clearpixel(x,y) clear the pixel at the given coordinate
45     lcd_fontsize(font,width,height) return the width and height of the font
47   Player
49     lcd_define_pattern(which,pattern,lenth) define a custom pattern
51 Buttons
53   #include <button.h>
55   These functions work the same regardless of which keypad you have, but they
56   return a different set of values. Note that the Recorder keypad has 10
57   keys, while the Player keypad only features 6.
59   int button_get(bool block)
61      Returns a bitmask for which keys were pressed. If 'block' is set TRUE it
62      won't return until a key is pressed.
64 Files
66   (These functions are POSIX look-alikes)
68   #include <file.h>
70   int open(const char *path, int oflag);
72      The open() function establishes the connection between a file and a file
73      descriptor. It creates an open file descrip- tion that refers to a file
74      and a file descriptor that refers to that open file description. The file
75      descriptor is used by other I/O functions to refer to that file.
77   int read(int fildes, void *buf, size_t nbyte);
79      The read() function attempts to read nbyte bytes from the file associated
80      with the open file descriptor, fildes, into the buffer pointed to by buf.
82   int lseek(int fildes, off_t offset, int whence);
84      The lseek() function sets the file pointer associated with the open file
85      descriptor specified by fildes as follows:
87         o  If whence is SEEK_SET, the pointer is  set  to  offset
88            bytes.
90         o  If whence is SEEK_CUR,  the  pointer  is  set  to  its
91            current location plus offset.
93         o  If whence is SEEK_END, the pointer is set to the  size
94            of the file plus offset.
96   int write(int fildes, const void *buf, size_t nbyte);
98      NOT CURRENTLY SUPPORTED.
100      write writes up to count bytes to the file referenced by the file
101      descriptor fd from the buffer starting at buf.
103   int close(int fildes);
105      The close() function will deallocate the file descriptor indicated by
106      fildes.  To deallocate means to make the file descriptor available for
107      return by subsequent calls to open(2) or other functions that allocate
108      file descriptors.
110   int rename(const char *old, const char *new);
112      NOT CURRENTLY SUPPORTED.
114      The rename() function changes the name of a file. The old argument points
115      to the pathname of the file to be renamed. The new argument points to the
116      new pathname of the file.
118   int remove(const char *pathname);
120      NOT CURRENTLY SUPPORTED.
122      remove deletes a name from the filesystem.  It calls unlink for files,
123      and rmdir for directories.
126 Directories
128   #include <dir.h>
130   DIR *opendir(const char *name);
132      The opendir() function opens a directory stream corresponding to the
133      directory name, and returns a pointer to the directory stream.  The
134      stream is positioned at the first entry in the directory.
136   struct dirent *readdir(DIR *dir);
138      The readdir() function returns a pointer to a dirent structure
139      representing the next directory entry in the directory stream pointed to
140      by dir.  It returns NULL on reaching the end-of-file or if an error
141      occurred.
143      Add a description of the struct here.
145   int closedir(DIR *dir);
147      The closedir() function closes the directory stream associated with dir.
148      The directory stream descriptor dir is not available after this call.
151 String/Memory
153   #include <string.h>
155   strcmp()
156   strcpy()
157   memcpy()
158   memset()
159   ...
161 Memory allocation
163   #include <dmalloc.h>
165   void *malloc(size_t size);
167      malloc() allocates size bytes and returns a pointer to the allocated
168      memory. The memory is not cleared.
170   void free(void *ptr);
172      free() frees the memory space pointed to by ptr, which must have been
173      returned by a previous call to malloc(), calloc() or realloc().
174      Otherwise, or if free(ptr) has already been called before, undefined
175      behaviour occurs.
177   void *realloc(void *ptr, size_t size);
179      realloc() changes the size of the memory block pointed to by ptr to size
180      bytes.  The contents will be unchanged to the minimum of the old and new
181      sizes; newly allocated memory will be uninitialized.  If ptr is NULL, the
182      call is equivalent to malloc(size); if size is equal to zero, the call is
183      equivalent to free(ptr).  Unless ptr is NULL, it must have been returned
184      by an earlier call to malloc(), calloc() or realloc().
186   void *calloc(size_t nmemb, size_t size);
188      calloc() allocates memory for an array of nmemb elements of size bytes
189      each and returns a pointer to the allocated memory. The memory is set to
190      zero.
194   #include <id3.h>
195   bool mp3info(mp3entry *entry, char *filename);
197      Return FALSE if successful. The given mp3entry is then filled in with
198      whatever id3 info it could find about the given file.
200 Various
202   #include <kernel.h>
204   void kernel_init(void)
206      Inits the kernel and starts the tick interrupt
208   void sleep(ticks)
210      Sleep a specified number of ticks, we have HZ ticks per second.
212   void yield(void)
214      Let another thread run. This should be used as soon as you have to "wait"
215      for something or similar, and also if you do anything that takes "a long
216      time". This function is the entire foundation that our "cooperative
217      multitasking" is based on. Use it.
219   int set_irq_level(int level)
221      Sets the interrupt level (0 = lowest, 15 = highest) and returns the
222      previous level.
224   void queue_init(struct event_queue *q)
226      Initialize an event queue. The maximum number of events in a queue is
227      QUEUE_LENGTH-1.
229   void queue_wait(struct event_queue *q, struct event *ev)
231      Receive an event in a queue, blocking the thread if the queue is empty.
233   void queue_post(struct event_queue *q, int id, void *data)
235      Post an event to a queue.
236      NOTE: Negative event ID's are for system use only!!!
238   bool queue_empty(struct event_queue* q)
240      Returns true if the queue is empty.
242   int queue_broadcast(int id, void *data)
244      Posts an event in all queues that has been initiated with queue_init().
245      Returns the number of queues that were posted to.
247   int tick_add_task(void (*f)(void))
249      Add a task to the tick task queue. The argument is a pointer to a
250      function that will be called every tick interrupt.
251      At most MAX_NUM_TICK_TASKS can be active at the same time.
253   int tick_remove_task(void (*f)(void))
255      Remove a task from the task queue.
257   void mutex_init(struct mutex *m)
259      Initialize a mutex.
261   void mutex_lock(struct mutex *m)
263      Lock a mutex. This will block the thread if the mutex is already locked.
264      Note that you will geta deadlock if you lock the mutex twice!
266 void mutex_unlock(struct mutex *m)
268      Unlock a mutex.