|
| 1 | +/**************************************************************************** |
| 2 | + * boards/arm/nrf53/thingy53/src/nrf53_composite.c |
| 3 | + * |
| 4 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 5 | + * contributor license agreements. See the NOTICE file distributed with |
| 6 | + * this work for additional information regarding copyright ownership. The |
| 7 | + * ASF licenses this file to you under the Apache License, Version 2.0 (the |
| 8 | + * "License"); you may not use this file except in compliance with the |
| 9 | + * License. You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 15 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 16 | + * License for the specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + * |
| 19 | + ****************************************************************************/ |
| 20 | + |
| 21 | +/**************************************************************************** |
| 22 | + * Included Files |
| 23 | + ****************************************************************************/ |
| 24 | + |
| 25 | +#include <nuttx/config.h> |
| 26 | + |
| 27 | +#include <assert.h> |
| 28 | + |
| 29 | +#include <nuttx/usb/usbdev.h> |
| 30 | +#include <nuttx/usb/cdcacm.h> |
| 31 | +#include <nuttx/usb/rndis.h> |
| 32 | +#include <nuttx/usb/composite.h> |
| 33 | + |
| 34 | +#include "nrf53_usbd.h" |
| 35 | + |
| 36 | +#include "thingy53.h" |
| 37 | + |
| 38 | +/**************************************************************************** |
| 39 | + * Pre-processor Definitions |
| 40 | + ****************************************************************************/ |
| 41 | + |
| 42 | +/**************************************************************************** |
| 43 | + * Private Functions |
| 44 | + ****************************************************************************/ |
| 45 | + |
| 46 | +void *board_composite0_connect(void) |
| 47 | +{ |
| 48 | + struct composite_devdesc_s dev[2]; |
| 49 | + int ifnobase = 0; |
| 50 | + int strbase = COMPOSITE_NSTRIDS; |
| 51 | + int dev_idx = 0; |
| 52 | + int epin = 1; |
| 53 | + int epout = 1; |
| 54 | + |
| 55 | +#ifdef CONFIG_RNDIS_COMPOSITE |
| 56 | + /* Configure the RNDIS USB device */ |
| 57 | + |
| 58 | + /* Ask the rndis driver to fill in the constants we didn't |
| 59 | + * know here. |
| 60 | + */ |
| 61 | + |
| 62 | + usbdev_rndis_get_composite_devdesc(&dev[dev_idx]); |
| 63 | + |
| 64 | + /* Interfaces */ |
| 65 | + |
| 66 | + dev[dev_idx].devinfo.ifnobase = ifnobase; |
| 67 | + dev[dev_idx].minor = 0; |
| 68 | + |
| 69 | + /* Strings */ |
| 70 | + |
| 71 | + dev[dev_idx].devinfo.strbase = strbase; |
| 72 | + |
| 73 | + /* Endpoints */ |
| 74 | + |
| 75 | + dev[dev_idx].devinfo.epno[RNDIS_EP_INTIN_IDX] = epin++; |
| 76 | + dev[dev_idx].devinfo.epno[RNDIS_EP_BULKIN_IDX] = epin++; |
| 77 | + dev[dev_idx].devinfo.epno[RNDIS_EP_BULKOUT_IDX] = epout++; |
| 78 | + |
| 79 | + /* Count up the base numbers */ |
| 80 | + |
| 81 | + ifnobase += dev[dev_idx].devinfo.ninterfaces; |
| 82 | + strbase += dev[dev_idx].devinfo.nstrings; |
| 83 | + |
| 84 | + dev_idx += 1; |
| 85 | +#endif |
| 86 | + |
| 87 | +#ifdef CONFIG_CDCACM_COMPOSITE |
| 88 | + /* Configure the CDC/ACM device */ |
| 89 | + |
| 90 | + /* Ask the cdcacm driver to fill in the constants we didn't |
| 91 | + * know here. |
| 92 | + */ |
| 93 | + |
| 94 | + cdcacm_get_composite_devdesc(&dev[dev_idx]); |
| 95 | + |
| 96 | + /* Overwrite and correct some values... */ |
| 97 | + |
| 98 | + /* The callback functions for the CDC/ACM class */ |
| 99 | + |
| 100 | + dev[dev_idx].classobject = cdcacm_classobject; |
| 101 | + dev[dev_idx].uninitialize = cdcacm_uninitialize; |
| 102 | + |
| 103 | + /* Interfaces */ |
| 104 | + |
| 105 | + dev[dev_idx].devinfo.ifnobase = ifnobase; /* Offset to Interface-IDs */ |
| 106 | + dev[dev_idx].minor = 0; /* The minor interface number */ |
| 107 | + |
| 108 | + /* Strings */ |
| 109 | + |
| 110 | + dev[dev_idx].devinfo.strbase = strbase; /* Offset to String Numbers */ |
| 111 | + |
| 112 | + /* Endpoints */ |
| 113 | + |
| 114 | + dev[dev_idx].devinfo.epno[CDCACM_EP_INTIN_IDX] = epin++; |
| 115 | + dev[dev_idx].devinfo.epno[CDCACM_EP_BULKIN_IDX] = epin++; |
| 116 | + dev[dev_idx].devinfo.epno[CDCACM_EP_BULKOUT_IDX] = epout++; |
| 117 | + |
| 118 | + /* Count up the base numbers */ |
| 119 | + |
| 120 | + ifnobase += dev[dev_idx].devinfo.ninterfaces; |
| 121 | + strbase += dev[dev_idx].devinfo.nstrings; |
| 122 | + |
| 123 | + dev_idx += 1; |
| 124 | +#endif |
| 125 | + |
| 126 | + DEBUGASSERT(epin <= NRF53_NENDPOINTS); |
| 127 | + DEBUGASSERT(epout <= NRF53_NENDPOINTS); |
| 128 | + |
| 129 | + return composite_initialize(dev_idx, dev); |
| 130 | +} |
| 131 | + |
| 132 | +/**************************************************************************** |
| 133 | + * Public Functions |
| 134 | + ****************************************************************************/ |
| 135 | + |
| 136 | +/**************************************************************************** |
| 137 | + * Name: board_composite_initialize |
| 138 | + * |
| 139 | + * Description: |
| 140 | + * Perform architecture specific initialization of a composite USB device. |
| 141 | + * |
| 142 | + ****************************************************************************/ |
| 143 | + |
| 144 | +int board_composite_initialize(int port) |
| 145 | +{ |
| 146 | + return OK; |
| 147 | +} |
| 148 | + |
| 149 | +/**************************************************************************** |
| 150 | + * Name: board_composite_connect |
| 151 | + * |
| 152 | + * Description: |
| 153 | + * Connect the USB composite device on the specified USB device port using |
| 154 | + * the specified configuration. The interpretation of the configid is |
| 155 | + * board specific. |
| 156 | + * |
| 157 | + * Input Parameters: |
| 158 | + * port - The USB device port. |
| 159 | + * configid - The USB composite configuration |
| 160 | + * |
| 161 | + * Returned Value: |
| 162 | + * A non-NULL handle value is returned on success. NULL is returned on |
| 163 | + * any failure. |
| 164 | + * |
| 165 | + ****************************************************************************/ |
| 166 | + |
| 167 | +void *board_composite_connect(int port, int configid) |
| 168 | +{ |
| 169 | + if (configid == 0) |
| 170 | + { |
| 171 | + return board_composite0_connect(); |
| 172 | + } |
| 173 | + else |
| 174 | + { |
| 175 | + return NULL; |
| 176 | + } |
| 177 | +} |
0 commit comments