| Index: embios/trunk/init.c |
| — | — | @@ -170,6 +170,9 @@ |
| 171 | 171 | #ifdef HAVE_USB
|
| 172 | 172 | usb_init();
|
| 173 | 173 | #endif
|
| | 174 | +#ifdef HAVE_BUTTON
|
| | 175 | + button_init();
|
| | 176 | +#endif
|
| 174 | 177 | #ifdef HAVE_STORAGE
|
| 175 | 178 | DEBUGF("Initializing storage drivers...");
|
| 176 | 179 | storage_init();
|
| Index: embios/trunk/button.c |
| — | — | @@ -0,0 +1,94 @@ |
| | 2 | +//
|
| | 3 | +//
|
| | 4 | +// Copyright 2010 TheSeven
|
| | 5 | +//
|
| | 6 | +//
|
| | 7 | +// This file is part of emBIOS.
|
| | 8 | +//
|
| | 9 | +// emBIOS is free software: you can redistribute it and/or
|
| | 10 | +// modify it under the terms of the GNU General Public License as
|
| | 11 | +// published by the Free Software Foundation, either version 2 of the
|
| | 12 | +// License, or (at your option) any later version.
|
| | 13 | +//
|
| | 14 | +// emBIOS is distributed in the hope that it will be useful,
|
| | 15 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| | 16 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
| | 17 | +// See the GNU General Public License for more details.
|
| | 18 | +//
|
| | 19 | +// You should have received a copy of the GNU General Public License along
|
| | 20 | +// with emBIOS. If not, see <http://www.gnu.org/licenses/>.
|
| | 21 | +//
|
| | 22 | +//
|
| | 23 | +
|
| | 24 | +
|
| | 25 | +#include "global.h"
|
| | 26 | +#include "button.h"
|
| | 27 | +#include "thread.h"
|
| | 28 | +
|
| | 29 | +
|
| | 30 | +#ifndef BUTTON_MAX_HOOKS
|
| | 31 | +#define BUTTON_MAX_HOOKS 16
|
| | 32 | +#endif
|
| | 33 | +
|
| | 34 | +
|
| | 35 | +extern struct scheduler_thread* current_thread;
|
| | 36 | +static struct button_hook_entry button_hooks[BUTTON_MAX_HOOKS] IBSS_ATTR;
|
| | 37 | +static struct mutex button_mutex;
|
| | 38 | +
|
| | 39 | +
|
| | 40 | +void button_init()
|
| | 41 | +{
|
| | 42 | + memset(button_hooks, 0, sizeof(button_hooks));
|
| | 43 | + mutex_init(&button_mutex);
|
| | 44 | +}
|
| | 45 | +
|
| | 46 | +int button_register_handler(void (*handler)(enum button_event, int which, int value))
|
| | 47 | +{
|
| | 48 | + int i;
|
| | 49 | + mutex_lock(&button_mutex, TIMEOUT_BLOCK);
|
| | 50 | + for (i = 0; i < BUTTON_MAX_HOOKS; i++)
|
| | 51 | + if (button_hooks[i].owner == NULL)
|
| | 52 | + {
|
| | 53 | + button_hooks[i].owner = current_thread;
|
| | 54 | + button_hooks[i].handler = handler;
|
| | 55 | + return 0;
|
| | 56 | + }
|
| | 57 | + mutex_unlock(&button_mutex);
|
| | 58 | + return -1;
|
| | 59 | +}
|
| | 60 | +
|
| | 61 | +int button_unregister_handler(void (*handler)(enum button_event, int which, int value))
|
| | 62 | +{
|
| | 63 | + int i;
|
| | 64 | + mutex_lock(&button_mutex, TIMEOUT_BLOCK);
|
| | 65 | + for (i = 0; i < BUTTON_MAX_HOOKS; i++)
|
| | 66 | + if (button_hooks[i].handler == handler)
|
| | 67 | + {
|
| | 68 | + button_hooks[i].owner = NULL;
|
| | 69 | + button_hooks[i].handler = NULL;
|
| | 70 | + return 0;
|
| | 71 | + }
|
| | 72 | + mutex_unlock(&button_mutex);
|
| | 73 | + return -1;
|
| | 74 | +}
|
| | 75 | +
|
| | 76 | +void button_send_event(enum button_event eventtype, int which, int value)
|
| | 77 | +{
|
| | 78 | + int i;
|
| | 79 | + for (i = 0; i < BUTTON_MAX_HOOKS; i++)
|
| | 80 | + if (button_hooks[i].owner != NULL)
|
| | 81 | + handler(eventtype, which, value);
|
| | 82 | +}
|
| | 83 | +
|
| | 84 | +void button_unregister_all_of_thread(struct scheduler_thread* process)
|
| | 85 | +{
|
| | 86 | + int i;
|
| | 87 | + mutex_lock(&button_mutex, TIMEOUT_BLOCK);
|
| | 88 | + for (i = 0; i < BUTTON_MAX_HOOKS; i++)
|
| | 89 | + if (button_hooks[i].owner == process)
|
| | 90 | + {
|
| | 91 | + button_hooks[i].owner = NULL;
|
| | 92 | + button_hooks[i].handler = NULL;
|
| | 93 | + }
|
| | 94 | + mutex_unlock(&button_mutex);
|
| | 95 | +}
|
| Index: embios/trunk/button.h |
| — | — | @@ -0,0 +1,60 @@ |
| | 2 | +//
|
| | 3 | +//
|
| | 4 | +// Copyright 2010 TheSeven
|
| | 5 | +//
|
| | 6 | +//
|
| | 7 | +// This file is part of emBIOS.
|
| | 8 | +//
|
| | 9 | +// emBIOS is free software: you can redistribute it and/or
|
| | 10 | +// modify it under the terms of the GNU General Public License as
|
| | 11 | +// published by the Free Software Foundation, either version 2 of the
|
| | 12 | +// License, or (at your option) any later version.
|
| | 13 | +//
|
| | 14 | +// emBIOS is distributed in the hope that it will be useful,
|
| | 15 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| | 16 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
| | 17 | +// See the GNU General Public License for more details.
|
| | 18 | +//
|
| | 19 | +// You should have received a copy of the GNU General Public License along
|
| | 20 | +// with emBIOS. If not, see <http://www.gnu.org/licenses/>.
|
| | 21 | +//
|
| | 22 | +//
|
| | 23 | +
|
| | 24 | +
|
| | 25 | +#ifndef __BUTTON_H__
|
| | 26 | +#define __BUTTON_H__
|
| | 27 | +
|
| | 28 | +
|
| | 29 | +#include "global.h"
|
| | 30 | +#include "thread.h"
|
| | 31 | +
|
| | 32 | +
|
| | 33 | +enum button_event
|
| | 34 | +{
|
| | 35 | + BUTTON_PRESS,
|
| | 36 | + BUTTON_RELEASE,
|
| | 37 | + BUTTON_SHORTPRESS,
|
| | 38 | + BUTTON_LONGPRESS,
|
| | 39 | + WHEEL_TOUCH,
|
| | 40 | + WHEEL_UNTOUCH,
|
| | 41 | + WHEEL_POSITION,
|
| | 42 | + WHEEL_MOVED,
|
| | 43 | + WHEEL_FORWARD,
|
| | 44 | + WHEEL_BACKWARD
|
| | 45 | +};
|
| | 46 | +
|
| | 47 | +struct button_hook_entry
|
| | 48 | +{
|
| | 49 | + struct scheduler_thread* owner;
|
| | 50 | + void (*handler)(enum button_event, int which, int value);
|
| | 51 | +};
|
| | 52 | +
|
| | 53 | +
|
| | 54 | +void button_init() INITCODE_ATTR;
|
| | 55 | +int button_register_handler(void (*handler)(enum button_event, int which, int value));
|
| | 56 | +int button_unregister_handler(void (*handler)(enum button_event, int which, int value));
|
| | 57 | +void button_send_event(enum button_event eventtype, int which, int value) ICODE_ATTR;
|
| | 58 | +void button_unregister_all_of_thread(struct scheduler_thread* process);
|
| | 59 | +
|
| | 60 | +
|
| | 61 | +#endif
|
| Index: embios/trunk/target/ipodnano2g/target.h |
| — | — | @@ -50,6 +50,8 @@ |
| 51 | 51 |
|
| 52 | 52 | #define HAVE_I2C
|
| 53 | 53 |
|
| | 54 | +#define HAVE_BUTTON
|
| | 55 | +
|
| 54 | 56 | #define HAVE_BOOTFLASH
|
| 55 | 57 | #define BOOTFLASH_IS_MEMMAPPED
|
| 56 | 58 |
|
| Index: embios/trunk/export/syscallwrappers.h |
| — | — | @@ -175,6 +175,8 @@ |
| 176 | 176 | #define tlsf_block_size(args...) __embios_syscall->tlsf_block_size(args)
|
| 177 | 177 | #define tlsf_overhead(args...) __embios_syscall->tlsf_overhead(args)
|
| 178 | 178 | #define execfirmware(args...) __embios_syscall->execfirmware(args)
|
| | 179 | +#define button_register_handler(args...) __embios_syscall->button_register_handler(args)
|
| | 180 | +#define button_unregister_handler(args...) __embios_syscall->button_unregister_handler(args)
|
| 179 | 181 |
|
| 180 | 182 |
|
| 181 | 183 | #endif
|
| Index: embios/trunk/export/syscallapi.h |
| — | — | @@ -48,6 +48,7 @@ |
| 49 | 49 | #include "../backlight.h"
|
| 50 | 50 | #include "../syscall.h"
|
| 51 | 51 | #include "../progressbar.h"
|
| | 52 | +#include "../button.h"
|
| 52 | 53 | #include "../contextswitch.h"
|
| 53 | 54 | #include "../libc/include/string.h"
|
| 54 | 55 | #include "../libc/include/stdlib.h"
|
| — | — | @@ -211,6 +212,8 @@ |
| 212 | 213 | typeof(tlsf_block_size) *tlsf_block_size;
|
| 213 | 214 | typeof(tlsf_overhead) *tlsf_overhead;
|
| 214 | 215 | typeof(execfirmware) *execfirmware;
|
| | 216 | + typeof(button_register_handler) *button_register_handler;
|
| | 217 | + typeof(button_unregister_handler) *button_unregister_handler;
|
| 215 | 218 | };
|
| 216 | 219 |
|
| 217 | 220 |
|
| Index: embios/trunk/SOURCES |
| — | — | @@ -60,6 +60,9 @@ |
| 61 | 61 | dir.c
|
| 62 | 62 | storage.c
|
| 63 | 63 | #endif
|
| | 64 | +#ifdef HAVE_BUTTON
|
| | 65 | +button.c
|
| | 66 | +#endif
|
| 64 | 67 | strcasestr.c
|
| 65 | 68 | strcasecmp.c
|
| 66 | 69 | strlcpy.c
|
| Index: embios/trunk/syscallapi.c |
| — | — | @@ -179,4 +179,8 @@ |
| 180 | 180 | .nand_write_page_collect = nand_write_page_collect,
|
| 181 | 181 | .nand_get_device_type = nand_get_device_type,
|
| 182 | 182 | #endif
|
| | 183 | +#ifdef HAVE_BUTTON
|
| | 184 | + .button_register_handler = button_register_handler,
|
| | 185 | + .button_unregister_handler = button_unregister_handler,
|
| | 186 | +#endif
|
| 183 | 187 | };
|
| Index: embios/trunk/thread.c |
| — | — | @@ -30,6 +30,9 @@ |
| 31 | 31 | #include "dir.h"
|
| 32 | 32 | #include "file.h"
|
| 33 | 33 | #endif
|
| | 34 | +#ifdef HAVE_BUTTON
|
| | 35 | +#include "button.h"
|
| | 36 | +#endif
|
| 34 | 37 |
|
| 35 | 38 |
|
| 36 | 39 | struct scheduler_thread scheduler_threads[MAX_THREADS] IBSS_ATTR;
|
| — | — | @@ -438,6 +441,9 @@ |
| 439 | 442 | close_all_of_process(t);
|
| 440 | 443 | closedir_all_of_process(t);
|
| 441 | 444 | #endif
|
| | 445 | +#ifdef HAVE_BUTTON
|
| | 446 | + button_unregister_all_of_thread(t);
|
| | 447 | +#endif
|
| 442 | 448 | }
|
| 443 | 449 |
|
| 444 | 450 | leave_critical_section(mode);
|