Library to allo USB PTP device to be hosted by the mbed platform
Dependents: class_project_main
PIMA15740/PIMAArray.h@4:9c6f5867f050, 2013-08-28 (annotated)
- Committer:
- jakowisp
- Date:
- Wed Aug 28 03:25:53 2013 +0000
- Revision:
- 4:9c6f5867f050
- Parent:
- 3:1fcb46ab18df
- Child:
- 10:fc1cb68fc91e
Documentation and initial publishing;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jakowisp | 3:1fcb46ab18df | 1 | /** |
jakowisp | 3:1fcb46ab18df | 2 | * @file PIMAArray.h |
jakowisp | 3:1fcb46ab18df | 3 | * @brief PIMA Array class definition |
jakowisp | 3:1fcb46ab18df | 4 | * @author Dwayne Dilbeck |
jakowisp | 3:1fcb46ab18df | 5 | * @date 8/23/2013 |
jakowisp | 3:1fcb46ab18df | 6 | * |
jakowisp | 3:1fcb46ab18df | 7 | * mbed USBHostPTP Library(PIMA15740 Array definition) |
jakowisp | 4:9c6f5867f050 | 8 | * |
jakowisp | 3:1fcb46ab18df | 9 | * @par Copyright: |
jakowisp | 3:1fcb46ab18df | 10 | * Copyright (c) 2013 Dwayne Dilbeck |
jakowisp | 3:1fcb46ab18df | 11 | * @par License: |
jakowisp | 3:1fcb46ab18df | 12 | * This software is distributed under the terms of the GNU Lesser General Public License |
jakowisp | 3:1fcb46ab18df | 13 | */ |
jakowisp | 0:98cf19bcd828 | 14 | |
jakowisp | 0:98cf19bcd828 | 15 | /** |
jakowisp | 0:98cf19bcd828 | 16 | * Class PIMA array |
jakowisp | 0:98cf19bcd828 | 17 | * |
jakowisp | 3:1fcb46ab18df | 18 | * The PIMA15740 standard defines an array as an unsigned 32bit number of elements followed by a list |
jakowisp | 3:1fcb46ab18df | 19 | * of insinged 16bit codes; |
jakowisp | 0:98cf19bcd828 | 20 | */ |
jakowisp | 0:98cf19bcd828 | 21 | class PIMAArray { |
jakowisp | 0:98cf19bcd828 | 22 | public: |
jakowisp | 0:98cf19bcd828 | 23 | /** |
jakowisp | 0:98cf19bcd828 | 24 | * Constructor |
jakowisp | 3:1fcb46ab18df | 25 | * @param None |
jakowisp | 0:98cf19bcd828 | 26 | * |
jakowisp | 3:1fcb46ab18df | 27 | * Zeros the number of elements and sets codes pointer to NUll |
jakowisp | 0:98cf19bcd828 | 28 | */ |
jakowisp | 0:98cf19bcd828 | 29 | PIMAArray() { |
jakowisp | 0:98cf19bcd828 | 30 | numberOfElements=0; |
jakowisp | 0:98cf19bcd828 | 31 | codes=NULL; |
jakowisp | 0:98cf19bcd828 | 32 | }; |
jakowisp | 0:98cf19bcd828 | 33 | |
jakowisp | 3:1fcb46ab18df | 34 | /** |
jakowisp | 3:1fcb46ab18df | 35 | * Destructor |
jakowisp | 3:1fcb46ab18df | 36 | * |
jakowisp | 3:1fcb46ab18df | 37 | * Frees assigned storage for codes. |
jakowisp | 3:1fcb46ab18df | 38 | * @param None |
jakowisp | 3:1fcb46ab18df | 39 | */ |
jakowisp | 0:98cf19bcd828 | 40 | ~PIMAArray() { |
jakowisp | 0:98cf19bcd828 | 41 | if( codes !=NULL) |
jakowisp | 0:98cf19bcd828 | 42 | free(codes); |
jakowisp | 0:98cf19bcd828 | 43 | }; |
jakowisp | 0:98cf19bcd828 | 44 | |
jakowisp | 3:1fcb46ab18df | 45 | /** |
jakowisp | 3:1fcb46ab18df | 46 | * Create and fill array storage from a supplied buffer pointer |
jakowisp | 3:1fcb46ab18df | 47 | * |
jakowisp | 3:1fcb46ab18df | 48 | * @param currentPtr a unit8_t pointer to a buffer location where a PIMAArray should be read |
jakowisp | 3:1fcb46ab18df | 49 | * |
jakowisp | 3:1fcb46ab18df | 50 | * @return The number of bytes used from the buffer to create the PIMA array. |
jakowisp | 3:1fcb46ab18df | 51 | */ |
jakowisp | 0:98cf19bcd828 | 52 | int FillArray(uint8_t *currentPtr) { |
jakowisp | 0:98cf19bcd828 | 53 | SetNumberOfElements(*((uint32_t *)currentPtr)); |
jakowisp | 0:98cf19bcd828 | 54 | SetCodes((uint16_t *)(currentPtr+4)); |
jakowisp | 0:98cf19bcd828 | 55 | return (2*numberOfElements) + 4; |
jakowisp | 0:98cf19bcd828 | 56 | } |
jakowisp | 0:98cf19bcd828 | 57 | |
jakowisp | 3:1fcb46ab18df | 58 | ///Number of elelments stored in the array |
jakowisp | 3:1fcb46ab18df | 59 | uint32_t numberOfElements; |
jakowisp | 3:1fcb46ab18df | 60 | ///Pointer to Code storage |
jakowisp | 3:1fcb46ab18df | 61 | uint16_t *codes; |
jakowisp | 3:1fcb46ab18df | 62 | |
jakowisp | 3:1fcb46ab18df | 63 | private: |
jakowisp | 3:1fcb46ab18df | 64 | /** |
jakowisp | 3:1fcb46ab18df | 65 | * Function to allocate array storage space and set the number of elements |
jakowisp | 3:1fcb46ab18df | 66 | * |
jakowisp | 3:1fcb46ab18df | 67 | * @param uint8_t The number of elements to create storage space for. |
jakowisp | 3:1fcb46ab18df | 68 | * @return none |
jakowisp | 3:1fcb46ab18df | 69 | */ |
jakowisp | 0:98cf19bcd828 | 70 | void SetNumberOfElements(uint8_t length) { |
jakowisp | 0:98cf19bcd828 | 71 | this->numberOfElements=length; |
jakowisp | 0:98cf19bcd828 | 72 | if( codes !=NULL) |
jakowisp | 0:98cf19bcd828 | 73 | free(codes); |
jakowisp | 0:98cf19bcd828 | 74 | codes = (uint16_t *) malloc(sizeof(uint16_t)*length); |
jakowisp | 0:98cf19bcd828 | 75 | }; |
jakowisp | 0:98cf19bcd828 | 76 | |
jakowisp | 3:1fcb46ab18df | 77 | /** |
jakowisp | 3:1fcb46ab18df | 78 | * Function to read codes form a uint8t buffer and store them. |
jakowisp | 3:1fcb46ab18df | 79 | * @param buffer pointer to a uint8_t buffer |
jakowisp | 3:1fcb46ab18df | 80 | */ |
jakowisp | 0:98cf19bcd828 | 81 | void SetCodes(uint16_t *buffer){ |
jakowisp | 0:98cf19bcd828 | 82 | if(buffer!=NULL && codes !=NULL) |
jakowisp | 0:98cf19bcd828 | 83 | for(int i=0;i<this->numberOfElements;i++) |
jakowisp | 0:98cf19bcd828 | 84 | codes[i]=buffer[i]; |
jakowisp | 0:98cf19bcd828 | 85 | }; |
jakowisp | 0:98cf19bcd828 | 86 | |
jakowisp | 0:98cf19bcd828 | 87 | }; |
jakowisp | 1:71c0e9dc153d | 88 | |
jakowisp | 3:1fcb46ab18df | 89 |