mbed base bard check program for BlueTooth USB dongle module (3 switches, 6 leds, I2C LCD, A/D)

Dependencies:   USBHost mbed

Fork of BTstack by Norimasa Okamoto

Committer:
tamaki
Date:
Mon Oct 17 00:25:18 2016 +0000
Revision:
3:7b7d1273e2d5
Parent:
0:1ed23ab1345f
mbed base bard check program
; for BlueTooth USB dongle module
; (3 switches, 6 leds, I2C LCD, A/D)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 0:1ed23ab1345f 1 /*
va009039 0:1ed23ab1345f 2 * Copyright (C) 2009-2012 by Matthias Ringwald
va009039 0:1ed23ab1345f 3 *
va009039 0:1ed23ab1345f 4 * Redistribution and use in source and binary forms, with or without
va009039 0:1ed23ab1345f 5 * modification, are permitted provided that the following conditions
va009039 0:1ed23ab1345f 6 * are met:
va009039 0:1ed23ab1345f 7 *
va009039 0:1ed23ab1345f 8 * 1. Redistributions of source code must retain the above copyright
va009039 0:1ed23ab1345f 9 * notice, this list of conditions and the following disclaimer.
va009039 0:1ed23ab1345f 10 * 2. Redistributions in binary form must reproduce the above copyright
va009039 0:1ed23ab1345f 11 * notice, this list of conditions and the following disclaimer in the
va009039 0:1ed23ab1345f 12 * documentation and/or other materials provided with the distribution.
va009039 0:1ed23ab1345f 13 * 3. Neither the name of the copyright holders nor the names of
va009039 0:1ed23ab1345f 14 * contributors may be used to endorse or promote products derived
va009039 0:1ed23ab1345f 15 * from this software without specific prior written permission.
va009039 0:1ed23ab1345f 16 * 4. Any redistribution, use, or modification is done solely for
va009039 0:1ed23ab1345f 17 * personal benefit and not for any commercial purpose or for
va009039 0:1ed23ab1345f 18 * monetary gain.
va009039 0:1ed23ab1345f 19 *
va009039 0:1ed23ab1345f 20 * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS
va009039 0:1ed23ab1345f 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
va009039 0:1ed23ab1345f 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
va009039 0:1ed23ab1345f 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
va009039 0:1ed23ab1345f 24 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
va009039 0:1ed23ab1345f 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
va009039 0:1ed23ab1345f 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
va009039 0:1ed23ab1345f 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
va009039 0:1ed23ab1345f 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
va009039 0:1ed23ab1345f 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
va009039 0:1ed23ab1345f 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
va009039 0:1ed23ab1345f 31 * SUCH DAMAGE.
va009039 0:1ed23ab1345f 32 *
va009039 0:1ed23ab1345f 33 * Please inquire about commercial licensing options at btstack@ringwald.ch
va009039 0:1ed23ab1345f 34 *
va009039 0:1ed23ab1345f 35 */
va009039 0:1ed23ab1345f 36
va009039 0:1ed23ab1345f 37 /*
va009039 0:1ed23ab1345f 38 * linked_list.c
va009039 0:1ed23ab1345f 39 *
va009039 0:1ed23ab1345f 40 * Created by Matthias Ringwald on 7/13/09.
va009039 0:1ed23ab1345f 41 */
va009039 0:1ed23ab1345f 42
va009039 0:1ed23ab1345f 43 #include <btstack/linked_list.h>
va009039 0:1ed23ab1345f 44 #include <stdlib.h>
va009039 0:1ed23ab1345f 45 /**
va009039 0:1ed23ab1345f 46 * tests if list is empty
va009039 0:1ed23ab1345f 47 */
va009039 0:1ed23ab1345f 48 int linked_list_empty(linked_list_t * list){
va009039 0:1ed23ab1345f 49 return *list == (void *) 0;
va009039 0:1ed23ab1345f 50 }
va009039 0:1ed23ab1345f 51
va009039 0:1ed23ab1345f 52 /**
va009039 0:1ed23ab1345f 53 * linked_list_get_last_item
va009039 0:1ed23ab1345f 54 */
va009039 0:1ed23ab1345f 55 linked_item_t * linked_list_get_last_item(linked_list_t * list){ // <-- find the last item in the list
va009039 0:1ed23ab1345f 56 linked_item_t *lastItem = NULL;
va009039 0:1ed23ab1345f 57 linked_item_t *it;
va009039 0:1ed23ab1345f 58 for (it = *list; it ; it = it->next){
va009039 0:1ed23ab1345f 59 if (it) {
va009039 0:1ed23ab1345f 60 lastItem = it;
va009039 0:1ed23ab1345f 61 }
va009039 0:1ed23ab1345f 62 }
va009039 0:1ed23ab1345f 63 return lastItem;
va009039 0:1ed23ab1345f 64 }
va009039 0:1ed23ab1345f 65
va009039 0:1ed23ab1345f 66
va009039 0:1ed23ab1345f 67 /**
va009039 0:1ed23ab1345f 68 * linked_list_add
va009039 0:1ed23ab1345f 69 */
va009039 0:1ed23ab1345f 70 void linked_list_add(linked_list_t * list, linked_item_t *item){ // <-- add item to list
va009039 0:1ed23ab1345f 71 // check if already in list
va009039 0:1ed23ab1345f 72 linked_item_t *it;
va009039 0:1ed23ab1345f 73 for (it = *list; it ; it = it->next){
va009039 0:1ed23ab1345f 74 if (it == item) {
va009039 0:1ed23ab1345f 75 return;
va009039 0:1ed23ab1345f 76 }
va009039 0:1ed23ab1345f 77 }
va009039 0:1ed23ab1345f 78 // add first
va009039 0:1ed23ab1345f 79 item->next = *list;
va009039 0:1ed23ab1345f 80 *list = item;
va009039 0:1ed23ab1345f 81 }
va009039 0:1ed23ab1345f 82
va009039 0:1ed23ab1345f 83 void linked_list_add_tail(linked_list_t * list, linked_item_t *item){ // <-- add item to list as last element
va009039 0:1ed23ab1345f 84 // check if already in list
va009039 0:1ed23ab1345f 85 linked_item_t *it;
va009039 0:1ed23ab1345f 86 for (it = (linked_item_t *) list; it->next ; it = it->next){
va009039 0:1ed23ab1345f 87 if (it->next == item) {
va009039 0:1ed23ab1345f 88 return;
va009039 0:1ed23ab1345f 89 }
va009039 0:1ed23ab1345f 90 }
va009039 0:1ed23ab1345f 91 item->next = (linked_item_t*) 0;
va009039 0:1ed23ab1345f 92 it->next = item;
va009039 0:1ed23ab1345f 93 }
va009039 0:1ed23ab1345f 94
va009039 0:1ed23ab1345f 95 /**
va009039 0:1ed23ab1345f 96 * Remove data_source from run loop
va009039 0:1ed23ab1345f 97 *
va009039 0:1ed23ab1345f 98 * @note: assumes that data_source_t.next is first element in data_source
va009039 0:1ed23ab1345f 99 */
va009039 0:1ed23ab1345f 100 int linked_list_remove(linked_list_t * list, linked_item_t *item){ // <-- remove item from list
va009039 0:1ed23ab1345f 101 linked_item_t *it;
va009039 0:1ed23ab1345f 102 for (it = (linked_item_t *) list; it ; it = it->next){
va009039 0:1ed23ab1345f 103 if (it->next == item){
va009039 0:1ed23ab1345f 104 it->next = item->next;
va009039 0:1ed23ab1345f 105 return 0;
va009039 0:1ed23ab1345f 106 }
va009039 0:1ed23ab1345f 107 }
va009039 0:1ed23ab1345f 108 return -1;
va009039 0:1ed23ab1345f 109 }
va009039 0:1ed23ab1345f 110
va009039 0:1ed23ab1345f 111 void linked_item_set_user(linked_item_t *item, void *user_data){
va009039 0:1ed23ab1345f 112 item->next = (linked_item_t *) 0;
va009039 0:1ed23ab1345f 113 item->user_data = user_data;
va009039 0:1ed23ab1345f 114 }
va009039 0:1ed23ab1345f 115
va009039 0:1ed23ab1345f 116 void * linked_item_get_user(linked_item_t *item) {
va009039 0:1ed23ab1345f 117 return item->user_data;
va009039 0:1ed23ab1345f 118 }
va009039 0:1ed23ab1345f 119
va009039 0:1ed23ab1345f 120 #if 0
va009039 0:1ed23ab1345f 121 #include <stdio.h>
va009039 0:1ed23ab1345f 122 void test_linked_list(){
va009039 0:1ed23ab1345f 123 linked_list_t testList = 0;
va009039 0:1ed23ab1345f 124 linked_item_t itemA;
va009039 0:1ed23ab1345f 125 linked_item_t itemB;
va009039 0:1ed23ab1345f 126 linked_item_t itemC;
va009039 0:1ed23ab1345f 127 linked_item_set_user(&itemA, (void *) 0);
va009039 0:1ed23ab1345f 128 linked_item_set_user(&itemB, (void *) 0);
va009039 0:1ed23ab1345f 129 linked_list_add(&testList, &itemA);
va009039 0:1ed23ab1345f 130 linked_list_add(&testList, &itemB);
va009039 0:1ed23ab1345f 131 linked_list_add_tail(&testList, &itemC);
va009039 0:1ed23ab1345f 132 // linked_list_remove(&testList, &itemB);
va009039 0:1ed23ab1345f 133 linked_item_t *it;
va009039 0:1ed23ab1345f 134 for (it = (linked_item_t *) &testList; it ; it = it->next){
va009039 0:1ed23ab1345f 135 if (it->next == &itemA) printf("Item A\n");
va009039 0:1ed23ab1345f 136 if (it->next == &itemB) printf("Item B\n");
va009039 0:1ed23ab1345f 137 if (it->next == &itemC) printf("Item C\n");
va009039 0:1ed23ab1345f 138 /* if (it->next == &itemB){
va009039 0:1ed23ab1345f 139 it->next = it->next;
va009039 0:1ed23ab1345f 140 printf(" remove\n");
va009039 0:1ed23ab1345f 141 } else {
va009039 0:1ed23ab1345f 142 printf(" keep\n");
va009039 0:1ed23ab1345f 143
va009039 0:1ed23ab1345f 144 */
va009039 0:1ed23ab1345f 145 }
va009039 0:1ed23ab1345f 146 }
va009039 0:1ed23ab1345f 147 #endif