Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ST_I2S X_NUCLEO_COMMON
Dependents: HelloWorld_CCA01M1 HelloWorld_CCA01M1_mbedOS HelloWorld_CCA01M1_mbedOS Karaoke_CCA01M1_CCA02M1_mbedOS ... more
Fork of X_NUCLEO_CCA01M1 by
STA350BW.cpp
00001 /** 00002 ****************************************************************************** 00003 * @file STA350BW.cpp 00004 * @author Central Labs 00005 * @version V1.0.0 00006 * @date 18-August-2015 00007 * @brief This file provides the STA350BW SOUND TERMINAL audio driver. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 00038 00039 /* Generated with STM32CubeTOO -----------------------------------------------*/ 00040 00041 00042 /* Revision ------------------------------------------------------------------*/ 00043 /* 00044 Repository: http://svn.x-nucleodev.codex.cro.st.com/svnroot/X-NucleoDev 00045 Branch/Trunk/Tag: trunk 00046 Based on: X-CUBE-SOUNDTER1/trunk/Drivers/BSP/Components/sta350bw/sta350bw.c 00047 Revision: 0 00048 */ 00049 00050 00051 /* Includes ------------------------------------------------------------------*/ 00052 00053 #include "STA350BW.h" 00054 00055 00056 /* Methods -------------------------------------------------------------------*/ 00057 00058 /** 00059 * @brief Initializes the STA350BW and the control interface. 00060 * @param init: initialization data. 00061 * @retval COMPONENT_OK if correct setup, COMPONENT_ERROR otherwise 00062 */ 00063 int32_t STA350BW::STA350BW_Init(void *init) 00064 { 00065 uint8_t tmp = 0x00; 00066 00067 /* Reset Audio Device */ 00068 _reset = 0; 00069 wait_ms(100); 00070 _reset = 1; 00071 00072 /* Low level I2C init */ 00073 STA350BW_IO_Init(); 00074 00075 /* Set Master clock depending on sampling frequency */ 00076 if (STA350BW_SetFrequency((*((STA350BW_init_t *) init)).frequency) != 0) 00077 { 00078 return COMPONENT_ERROR; 00079 } 00080 00081 STA350BW_IO_Delay(500); 00082 00083 /* Read Status Register */ 00084 if (STA350BW_IO_Read(STA350BW_STATUS, &tmp) != 0) 00085 { 00086 return COMPONENT_ERROR; 00087 } 00088 00089 #if 0 00090 if (tmp != 0x7F) 00091 { 00092 /* Status register highlights undesired behaviour (PLL not locked, ...) */ 00093 return COMPONENT_ERROR; 00094 } 00095 #else 00096 if ((tmp & ~0x80) != 0x7F) 00097 { 00098 /*Status register highlights undesired behavior 00099 (betzw: excluding PLL not locked, ...) */ 00100 return COMPONENT_ERROR; 00101 } 00102 #endif 00103 00104 /* Setup Master volume */ 00105 uint8_t value = (*((STA350BW_init_t *) init)).volume; 00106 if (!(value >= MIN_VOLUME && value <= MAX_VOLUME)) 00107 return COMPONENT_ERROR; 00108 if (STA350BW_SetVolume(STA350BW_CHANNEL_MASTER, (uint8_t) MAX_VOLUME - value) != 0) 00109 { 00110 return COMPONENT_ERROR; 00111 } 00112 00113 if (STA350BW_IO_Read(STA350BW_CONF_REGF, &tmp) != 0) 00114 { 00115 return COMPONENT_ERROR; 00116 } 00117 00118 #if 0 00119 tmp &= ~0x80; 00120 tmp |= 0x80; 00121 00122 /* Enable Power Out Stage */ 00123 if (STA350BW_IO_Write(STA350BW_CONF_REGF, tmp) != 0) 00124 { 00125 return COMPONENT_ERROR; 00126 } 00127 #else 00128 /*Enable Power Out Stage*/ 00129 if (STA350BW_PowerOn() != 0) 00130 { 00131 return COMPONENT_ERROR; 00132 } 00133 00134 #endif 00135 00136 return COMPONENT_OK; 00137 } 00138 00139 /** 00140 * @brief Deinitializes the STA350BW and the control interface. 00141 * @param None. 00142 * @retval COMPONENT_OK if correct setup, COMPONENT_ERROR otherwise. 00143 */ 00144 int32_t STA350BW::STA350BW_DeInit(void) 00145 { 00146 if (STA350BW_PowerOff() != 0) 00147 { 00148 return COMPONENT_ERROR; 00149 } 00150 return COMPONENT_OK; 00151 } 00152 00153 /** 00154 * @brief Read the device ID. 00155 * @param id: identifier. 00156 * @retval COMPONENT_OK if correct setup, COMPONENT_ERROR otherwise 00157 */ 00158 int32_t STA350BW::STA350BW_ReadID(uint8_t *id) 00159 { 00160 return COMPONENT_OK; 00161 } 00162 00163 /** 00164 * @brief Start the audio play. 00165 * @param *pData: pointer to audio data. 00166 * @param Size: size of the data buffer. 00167 * @retval COMPONENT_OK if correct setup, COMPONENT_ERROR otherwise 00168 */ 00169 int32_t STA350BW::STA350BW_Play(int16_t *pData, uint16_t Size) 00170 { 00171 return COMPONENT_OK; 00172 } 00173 00174 /** 00175 * @brief Pause the audio play. 00176 * @param None. 00177 * @retval COMPONENT_OK if correct setup, COMPONENT_ERROR otherwise 00178 */ 00179 int32_t STA350BW::STA350BW_Pause(void) 00180 { 00181 /* Mute the output*/ 00182 if (STA350BW_SetMute(STA350BW_CHANNEL_MASTER, STA350BW_ENABLE) != 0) 00183 { 00184 return COMPONENT_ERROR; 00185 } 00186 return COMPONENT_OK; 00187 } 00188 00189 /** 00190 * @brief Resume the audio play. 00191 * @param None. 00192 * @retval COMPONENT_OK if correct setup, COMPONENT_ERROR otherwise 00193 */ 00194 int32_t STA350BW::STA350BW_Resume(void) 00195 { 00196 /* Unmute the output*/ 00197 if (STA350BW_SetMute(STA350BW_CHANNEL_MASTER, STA350BW_DISABLE) != 0) 00198 { 00199 return COMPONENT_ERROR; 00200 } 00201 return COMPONENT_OK; 00202 } 00203 00204 /** 00205 * @brief Control the mute features of the STA350BW. 00206 * @param channel: channel to be muted. 00207 * This parameter can be a value of @ref STA350BW_channel_define 00208 * @param state: enable disable parameter 00209 * This parameter can be a value of @ref STA350BW_state_define 00210 * @retval COMPONENT_OK if correct setup, COMPONENT_ERROR otherwise 00211 */ 00212 int32_t STA350BW::STA350BW_SetMute(uint8_t channel, uint8_t state) 00213 { 00214 uint8_t tmp; 00215 00216 if (STA350BW_IO_Read(STA350BW_MUTE, &tmp) != 0) 00217 { 00218 return COMPONENT_ERROR; 00219 } 00220 if (state == STA350BW_ENABLE) 00221 { 00222 tmp |= channel; 00223 } else 00224 { 00225 tmp &= ~channel; 00226 } 00227 00228 if (STA350BW_IO_Write(STA350BW_MUTE, tmp) != 0) 00229 { 00230 return COMPONENT_ERROR; 00231 } 00232 return COMPONENT_OK; 00233 } 00234 00235 /** 00236 * @brief Control the volume features of the STA350BW. 00237 * @param channel: channel to be controlled. 00238 * This parameter can be a value of @ref STA350BW_channel_define 00239 * @param volume: volume to be set 00240 * @retval COMPONENT_OK if correct setup, COMPONENT_ERROR otherwise 00241 */ 00242 int32_t STA350BW::STA350BW_SetVolume(uint8_t channel, uint8_t value) 00243 { 00244 /*Setup volume */ 00245 uint8_t tmp = value; 00246 if (STA350BW_IO_Write(STA350BW_MVOL + channel, tmp) != 0) 00247 { 00248 return COMPONENT_ERROR; 00249 } 00250 return COMPONENT_OK; 00251 } 00252 00253 /** 00254 * @brief set the sampling frequency for STA350BW. 00255 * @param audio_freq: audio frequency to be set. 00256 * @retval COMPONENT_OK if correct setup, COMPONENT_ERROR otherwise 00257 */ 00258 int32_t STA350BW::STA350BW_SetFrequency(uint32_t audio_freq) 00259 { 00260 uint8_t tmp; 00261 00262 if (STA350BW_IO_Read(STA350BW_CONF_REGA, &tmp) != 0) 00263 { 00264 return COMPONENT_ERROR; 00265 } 00266 00267 tmp &= ~0x1F; 00268 00269 if (audio_freq == STA350BW_Fs_32000 || audio_freq == STA350BW_Fs_44100 || audio_freq == STA350BW_Fs_48000) 00270 { 00271 tmp |= STA350BW_MCLK_256_LR_48K; 00272 } 00273 else if (audio_freq == STA350BW_Fs_88200 || audio_freq == STA350BW_Fs_96000) 00274 { 00275 tmp |= STA350BW_MCLK_256_LR_96K; 00276 } 00277 else 00278 return COMPONENT_ERROR; 00279 00280 if (STA350BW_IO_Write(STA350BW_CONF_REGA, tmp) != 0) 00281 { 00282 return COMPONENT_ERROR; 00283 } 00284 00285 /* Set I2S audio frequency. */ 00286 dev_i2s.audio_frequency(audio_freq); 00287 00288 return COMPONENT_OK; 00289 } 00290 00291 /** 00292 * @brief Set equalization parameters for STA350BW biquad section. 00293 * @param ram_block: ram block to be set 00294 * @param filter_number: filter number 00295 * @param *filter_values: pointer to a uint32_t array containing filter coefficients 00296 * @retval COMPONENT_OK if correct setup, COMPONENT_ERROR otherwise 00297 */ 00298 int32_t STA350BW::STA350BW_SetEq(uint8_t ram_block, uint8_t filter_number, uint32_t * filter_values) 00299 { 00300 /*5 is due to the ram adressing: first filter is on the adresses 0x00 to 0x04; the second is on 0x05 to 0x09 ...*/ 00301 STA350BW_WriteRAMSet(ram_block, filter_number * 5, (uint8_t *) filter_values); 00302 return COMPONENT_OK; 00303 } 00304 00305 /** 00306 * @brief Set tone value in the STA350BW tone register. 00307 * @param tone_gain: gain of the tone control 00308 * @retval COMPONENT_OK if correct setup, COMPONENT_ERROR otherwise 00309 */ 00310 int32_t STA350BW::STA350BW_SetTone(uint8_t tone_gain) 00311 { 00312 uint8_t tmp = tone_gain; 00313 00314 if (STA350BW_IO_Write(STA350BW_TONE, tmp) != 0) 00315 { 00316 return COMPONENT_ERROR; 00317 } 00318 return COMPONENT_OK; 00319 } 00320 00321 /** 00322 * @brief Power on the device. 00323 * @param None. 00324 * @retval COMPONENT_OK if correct setup, COMPONENT_ERROR otherwise 00325 */ 00326 int32_t STA350BW::STA350BW_PowerOn(void) 00327 { 00328 uint8_t tmp; 00329 if (STA350BW_IO_Read(STA350BW_CONF_REGF, &tmp) != 0) 00330 { 00331 return COMPONENT_ERROR; 00332 } 00333 tmp |= 0xC0; 00334 if (STA350BW_IO_Write(STA350BW_CONF_REGF, tmp) != 0) 00335 { 00336 return COMPONENT_ERROR; 00337 } 00338 return COMPONENT_OK; 00339 } 00340 00341 /** 00342 * @brief Power off the device. 00343 * @param None. 00344 * @retval COMPONENT_OK if correct setup, COMPONENT_ERROR otherwise 00345 */ 00346 int32_t STA350BW::STA350BW_PowerOff(void) 00347 { 00348 uint8_t tmp; 00349 if (STA350BW_IO_Read(STA350BW_CONF_REGF, &tmp) != 0) 00350 { 00351 return COMPONENT_ERROR; 00352 } 00353 tmp &= ~0xC0; 00354 if (STA350BW_IO_Write(STA350BW_CONF_REGF, tmp) != 0) 00355 { 00356 return COMPONENT_ERROR; 00357 } 00358 return COMPONENT_OK; 00359 } 00360 00361 /** 00362 * @brief Stop audio stream. 00363 * @param None. 00364 * @retval COMPONENT_OK if correct setup, COMPONENT_ERROR otherwise 00365 */ 00366 int32_t STA350BW::STA350BW_Stop(void) 00367 { 00368 return COMPONENT_OK; 00369 } 00370 00371 /** 00372 * @brief Reset device. 00373 * @param NOne. 00374 * @retval COMPONENT_OK if correct setup, COMPONENT_ERROR otherwise 00375 */ 00376 int32_t STA350BW::STA350BW_Reset(void) 00377 { 00378 return COMPONENT_OK; 00379 } 00380 00381 /** 00382 * @brief This function can be used to set advanced DSP options in order to 00383 * use advanced features on the STA350BW device. 00384 * @param option: specific option to be setted up 00385 * This parameter can be a value of @ref STA350BW_DSP_option_selection 00386 * @param state: state of the option to be controlled. Depending on the selected 00387 * DSP feature to be controlled, this value can be either ENABLE/DISABLE 00388 * or a specific numerical parameter related to the specific DSP function. 00389 * This parameter can be a value of @ref STA350BW_state_define 00390 * @retval COMPONENT_OK if correct setup, COMPONENT_ERROR otherwise 00391 */ 00392 int32_t STA350BW::STA350BW_SetDSPOption(uint8_t option, uint8_t state) 00393 { 00394 uint8_t tmp = 0; 00395 00396 switch (option) 00397 { 00398 case STA350BW_DSPB: 00399 { 00400 if (STA350BW_IO_Read(STA350BW_CONF_REGD, &tmp) != 0) 00401 { 00402 return COMPONENT_ERROR; 00403 } 00404 tmp &= ~0x04; 00405 tmp |= state << 0x02; 00406 00407 if (STA350BW_IO_Write(STA350BW_CONF_REGD, tmp) != 0) 00408 { 00409 return COMPONENT_ERROR; 00410 } 00411 break; 00412 } 00413 case STA350BW_HPB: 00414 { 00415 if (STA350BW_IO_Read(STA350BW_CONF_REGD, &tmp) != 0) 00416 { 00417 return COMPONENT_ERROR; 00418 } 00419 tmp &= ~0x01; 00420 tmp |= state << 0x00; 00421 00422 if (STA350BW_IO_Write(STA350BW_CONF_REGD, tmp) != 0) 00423 { 00424 return COMPONENT_ERROR; 00425 } 00426 break; 00427 } 00428 case STA350BW_DEMP: 00429 { 00430 if (STA350BW_IO_Read(STA350BW_CONF_REGD, &tmp) != 0) 00431 { 00432 return COMPONENT_ERROR; 00433 } 00434 tmp &= ~0x02; 00435 tmp |= state << 0x01; 00436 00437 if (STA350BW_IO_Write(STA350BW_CONF_REGD, tmp) != 0) 00438 { 00439 return COMPONENT_ERROR; 00440 } 00441 break; 00442 } 00443 case STA350BW_BQL: 00444 { 00445 if (STA350BW_IO_Read(STA350BW_CONF_REGD, &tmp) != 0) 00446 { 00447 return COMPONENT_ERROR; 00448 } 00449 tmp &= ~0x08; 00450 tmp |= state << 0x04; 00451 00452 if (STA350BW_IO_Write(STA350BW_CONF_REGD, tmp) != 0) 00453 { 00454 return COMPONENT_ERROR; 00455 } 00456 break; 00457 } 00458 case STA350BW_BQ5: 00459 { 00460 if (STA350BW_IO_Read(STA350BW_CONFX, &tmp) != 0) 00461 { 00462 return COMPONENT_ERROR; 00463 } 00464 tmp &= ~0x04; 00465 tmp |= state << 0x02; 00466 00467 if (STA350BW_IO_Write(STA350BW_CONFX, tmp) != 0) 00468 { 00469 return COMPONENT_ERROR; 00470 } 00471 break; 00472 } 00473 case STA350BW_BQ6: 00474 { 00475 if (STA350BW_IO_Read(STA350BW_CONFX, &tmp) != 0) 00476 { 00477 return COMPONENT_ERROR; 00478 } 00479 tmp &= ~0x02; 00480 tmp |= state << 0x01; 00481 00482 if (STA350BW_IO_Write(STA350BW_CONFX, tmp) != 0) 00483 { 00484 return COMPONENT_ERROR; 00485 } 00486 break; 00487 } 00488 case STA350BW_BQ7: 00489 { 00490 if (STA350BW_IO_Read(STA350BW_CONFX, &tmp) != 0) 00491 { 00492 return COMPONENT_ERROR; 00493 } 00494 tmp &= ~0x01; 00495 tmp |= state << 0x00; 00496 00497 if (STA350BW_IO_Write(STA350BW_CONFX, tmp) != 0) 00498 { 00499 return COMPONENT_ERROR; 00500 } 00501 break; 00502 } 00503 case STA350BW_C1EQBP: 00504 { 00505 if (STA350BW_IO_Read(STA350BW_C1CFG, &tmp) != 0) 00506 { 00507 return COMPONENT_ERROR; 00508 } 00509 tmp &= ~0x02; 00510 tmp |= state << 0x01; 00511 00512 if (STA350BW_IO_Write(STA350BW_C1CFG, tmp) != 0) 00513 { 00514 return COMPONENT_ERROR; 00515 } 00516 break; 00517 } 00518 case STA350BW_C2EQBP: 00519 { 00520 if (STA350BW_IO_Read(STA350BW_C2CFG, &tmp) != 0) 00521 { 00522 return COMPONENT_ERROR; 00523 } 00524 tmp &= ~0x02; 00525 tmp |= state << 0x01; 00526 00527 if (STA350BW_IO_Write(STA350BW_C2CFG, tmp) != 0) 00528 { 00529 return COMPONENT_ERROR; 00530 } 00531 break; 00532 } 00533 case STA350BW_C1TCB: 00534 { 00535 if (STA350BW_IO_Read(STA350BW_C1CFG, &tmp) != 0) 00536 { 00537 return COMPONENT_ERROR; 00538 } 00539 tmp &= ~0x01; 00540 tmp |= state << 0x00; 00541 00542 if (STA350BW_IO_Write(STA350BW_C1CFG, tmp) != 0) 00543 { 00544 return COMPONENT_ERROR; 00545 } 00546 break; 00547 } 00548 case STA350BW_C2TCB: 00549 { 00550 if (STA350BW_IO_Read(STA350BW_C2CFG, &tmp) != 0) 00551 { 00552 return COMPONENT_ERROR; 00553 } 00554 tmp &= ~0x01; 00555 tmp |= state << 0x00; 00556 00557 if (STA350BW_IO_Write(STA350BW_C2CFG, tmp) != 0) 00558 { 00559 return COMPONENT_ERROR; 00560 } 00561 break; 00562 } 00563 case STA350BW_C1VBP: 00564 { 00565 if (STA350BW_IO_Read(STA350BW_C1CFG, &tmp) != 0) 00566 { 00567 return COMPONENT_ERROR; 00568 } 00569 tmp &= ~0x04; 00570 tmp |= state << 0x02; 00571 00572 if (STA350BW_IO_Write(STA350BW_C1CFG, tmp) != 0) 00573 { 00574 return COMPONENT_ERROR; 00575 } 00576 break; 00577 } 00578 case STA350BW_C2VBP: 00579 { 00580 if (STA350BW_IO_Read(STA350BW_C2CFG, &tmp) != 0) 00581 { 00582 return COMPONENT_ERROR; 00583 } 00584 tmp &= ~0x04; 00585 tmp |= state << 0x02; 00586 00587 if (STA350BW_IO_Write(STA350BW_C2CFG, tmp) != 0) 00588 { 00589 return COMPONENT_ERROR; 00590 } 00591 break; 00592 } 00593 case STA350BW_EXT_RANGE_BQ1: 00594 { 00595 if (STA350BW_IO_Read(STA350BW_CXT_B4B1, &tmp) != 0) 00596 { 00597 return COMPONENT_ERROR; 00598 } 00599 tmp &= ~0x03; 00600 tmp |= (state>>1); 00601 00602 if (STA350BW_IO_Write(STA350BW_CXT_B4B1, tmp) != 0) 00603 { 00604 return COMPONENT_ERROR; 00605 } 00606 break; 00607 } 00608 case STA350BW_EXT_RANGE_BQ2: 00609 { 00610 if (STA350BW_IO_Read(STA350BW_CXT_B4B1, &tmp) != 0) 00611 { 00612 return COMPONENT_ERROR; 00613 } 00614 tmp &= ~0x0C; 00615 tmp |= (state>>1) << 2; 00616 00617 if (STA350BW_IO_Write(STA350BW_CXT_B4B1, tmp) != 0) 00618 { 00619 return COMPONENT_ERROR; 00620 } 00621 break; 00622 } 00623 case STA350BW_EXT_RANGE_BQ3: 00624 { 00625 if (STA350BW_IO_Read(STA350BW_CXT_B4B1, &tmp) != 0) 00626 { 00627 return COMPONENT_ERROR; 00628 } 00629 tmp &= ~0x30; 00630 tmp |= (state>>1) << 4; 00631 00632 if (STA350BW_IO_Write(STA350BW_CXT_B4B1, tmp) != 0) 00633 { 00634 return COMPONENT_ERROR; 00635 } 00636 break; 00637 } 00638 case STA350BW_EXT_RANGE_BQ4: 00639 { 00640 if (STA350BW_IO_Read(STA350BW_CXT_B4B1, &tmp) != 0) 00641 { 00642 return COMPONENT_ERROR; 00643 } 00644 tmp &= ~0xC0; 00645 tmp |= (state>>1) << 6; 00646 00647 if (STA350BW_IO_Write(STA350BW_CXT_B4B1, tmp) != 0) 00648 { 00649 return COMPONENT_ERROR; 00650 } 00651 break; 00652 } 00653 case STA350BW_EXT_RANGE_BQ5: 00654 { 00655 if (STA350BW_IO_Read(STA350BW_CXT_B7B5, &tmp) != 0) 00656 { 00657 return COMPONENT_ERROR; 00658 } 00659 tmp &= ~0x03; 00660 tmp |= (state>>1); 00661 00662 if (STA350BW_IO_Write(STA350BW_CXT_B7B5, tmp) != 0) 00663 { 00664 return COMPONENT_ERROR; 00665 } 00666 break; 00667 } 00668 case STA350BW_EXT_RANGE_BQ6: 00669 { 00670 if (STA350BW_IO_Read(STA350BW_CXT_B7B5, &tmp) != 0) 00671 { 00672 return COMPONENT_ERROR; 00673 } 00674 tmp &= ~0x0C; 00675 tmp |= (state>>1) << 2; 00676 00677 if (STA350BW_IO_Write(STA350BW_CXT_B7B5, tmp) != 0) 00678 { 00679 return COMPONENT_ERROR; 00680 } 00681 break; 00682 } 00683 case STA350BW_EXT_RANGE_BQ7: 00684 { 00685 if (STA350BW_IO_Read(STA350BW_CXT_B7B5, &tmp) != 0) 00686 { 00687 return COMPONENT_ERROR; 00688 } 00689 tmp &= ~0x30; 00690 tmp |= (state>>1) << 4; 00691 00692 if (STA350BW_IO_Write(STA350BW_CXT_B7B5, tmp) != 0) 00693 { 00694 return COMPONENT_ERROR; 00695 } 00696 break; 00697 } 00698 case STA350BW_RAM_BANK_SELECT: 00699 { 00700 if (STA350BW_IO_Read(STA350BW_EQCFG, &tmp) != 0) 00701 { 00702 return COMPONENT_ERROR; 00703 } 00704 tmp &= ~0x03; 00705 tmp |= state; 00706 00707 if (STA350BW_IO_Write(STA350BW_EQCFG, tmp) != 0) 00708 { 00709 return COMPONENT_ERROR; 00710 } 00711 break; 00712 } 00713 } 00714 return COMPONENT_OK; 00715 } 00716 00717 /** 00718 * @brief private function for writing a RAM set. 00719 * @param RAM_block: ram block to be written. 00720 * @param RAM_address: ram address to be written. 00721 * @param *pIn: pointer to the desired value to be write. 00722 * @retval COMPONENT_OK if correct setup, COMPONENT_ERROR otherwise 00723 */ 00724 int32_t STA350BW::STA350BW_WriteRAMSet(uint8_t RAM_block, uint8_t RAM_address, uint8_t * pIn) 00725 { 00726 uint8_t tmp = 0x00; 00727 /*choose block*/ 00728 if (STA350BW_IO_Read(STA350BW_EQCFG, &tmp) != 0) 00729 { 00730 return COMPONENT_ERROR; 00731 } 00732 tmp &= ~0x03; 00733 RAM_block &= 0x03; 00734 tmp |= RAM_block; 00735 if (STA350BW_IO_Write(STA350BW_EQCFG, tmp) != 0) 00736 { 00737 return COMPONENT_ERROR; 00738 } 00739 /*set address*/ 00740 if (STA350BW_IO_Read(STA350BW_CFADDR, &tmp) != 0) 00741 { 00742 return COMPONENT_ERROR; 00743 } 00744 tmp &= ~0x3F; 00745 RAM_address &= 0x3F; 00746 tmp |= RAM_address; 00747 if (STA350BW_IO_Write(STA350BW_CFADDR, tmp) != 0) 00748 { 00749 return COMPONENT_ERROR; 00750 } 00751 /*write*/ 00752 if (STA350BW_IO_Write(STA350BW_B1CF1, pIn[2]) != 0) 00753 { 00754 return COMPONENT_ERROR; 00755 } 00756 if (STA350BW_IO_Write(STA350BW_B1CF2, pIn[1]) != 0) 00757 { 00758 return COMPONENT_ERROR; 00759 } 00760 if (STA350BW_IO_Write(STA350BW_B1CF3, pIn[0]) != 0) 00761 { 00762 return COMPONENT_ERROR; 00763 } 00764 if (STA350BW_IO_Write(STA350BW_B2CF1, pIn[6]) != 0) 00765 { 00766 return COMPONENT_ERROR; 00767 } 00768 if (STA350BW_IO_Write(STA350BW_B2CF2, pIn[5]) != 0) 00769 { 00770 return COMPONENT_ERROR; 00771 } 00772 if (STA350BW_IO_Write(STA350BW_B2CF3, pIn[4]) != 0) 00773 { 00774 return COMPONENT_ERROR; 00775 } 00776 if (STA350BW_IO_Write(STA350BW_A1CF1, pIn[10]) != 0) 00777 { 00778 return COMPONENT_ERROR; 00779 } 00780 if (STA350BW_IO_Write(STA350BW_A1CF2, pIn[9]) != 0) 00781 { 00782 return COMPONENT_ERROR; 00783 } 00784 if (STA350BW_IO_Write(STA350BW_A1CF3, pIn[8]) != 0) 00785 { 00786 return COMPONENT_ERROR; 00787 } 00788 if (STA350BW_IO_Write(STA350BW_A2CF1, pIn[14]) != 0) 00789 { 00790 return COMPONENT_ERROR; 00791 } 00792 if (STA350BW_IO_Write(STA350BW_A2CF2, pIn[13]) != 0) 00793 { 00794 return COMPONENT_ERROR; 00795 } 00796 if (STA350BW_IO_Write(STA350BW_A2CF3, pIn[12]) != 0) 00797 { 00798 return COMPONENT_ERROR; 00799 } 00800 if (STA350BW_IO_Write(STA350BW_B0CF1, pIn[18]) != 0) 00801 { 00802 return COMPONENT_ERROR; 00803 } 00804 if (STA350BW_IO_Write(STA350BW_B0CF2, pIn[17]) != 0) 00805 { 00806 return COMPONENT_ERROR; 00807 } 00808 if (STA350BW_IO_Write(STA350BW_B0CF3, pIn[16]) != 0) 00809 { 00810 return COMPONENT_ERROR; 00811 } 00812 /*Set WA PIN*/ 00813 if (STA350BW_IO_Read(STA350BW_CFUD, &tmp) != 0) 00814 { 00815 return COMPONENT_ERROR; 00816 } 00817 tmp &= ~0x02; 00818 tmp = 0x02; 00819 00820 if (STA350BW_IO_Write(STA350BW_CFUD, tmp) != 0) 00821 { 00822 return COMPONENT_ERROR; 00823 } 00824 return COMPONENT_OK; 00825 } 00826 00827 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Sat Jul 23 2022 08:56:13 by
