bmi160.c 627 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791
  1. /*
  2. ****************************************************************************
  3. * Copyright (C) 2016 Bosch Sensortec GmbH
  4. *
  5. * bmi160.c
  6. * Date: 2016/06/27
  7. * Revision: 2.2.1 $
  8. *
  9. * Usage: Sensor Driver for BMI160 sensor
  10. *
  11. ****************************************************************************
  12. * License:
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. *
  20. * Redistributions in binary form must reproduce the above copyright
  21. * notice, this list of conditions and the following disclaimer in the
  22. * documentation and/or other materials provided with the distribution.
  23. *
  24. * Neither the name of the copyright holder nor the names of the
  25. * contributors may be used to endorse or promote products derived from
  26. * this software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  29. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  30. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  31. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  32. * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
  33. * OR CONTRIBUTORS BE LIABLE FOR ANY
  34. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  35. * OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
  36. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  39. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  40. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  41. * ANY WAY OUT OF THE USE OF THIS
  42. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  43. *
  44. * The information provided is believed to be accurate and reliable.
  45. * The copyright holder assumes no responsibility
  46. * for the consequences of use
  47. * of such information nor for any infringement of patents or
  48. * other rights of third parties which may result from its use.
  49. * No license is granted by implication or otherwise under any patent or
  50. * patent rights of the copyright holder.
  51. **************************************************************************/
  52. /*! file BMI160
  53. @brief Sensor driver for BMI160 */
  54. #include "bmi160.h"
  55. struct bmi160_t *p_bmi160;
  56. /* Used for reading the Mag trim values for compensation*/
  57. struct trim_data_t mag_trim;
  58. /* the following variable is used for avoiding the selecting of auto mode
  59. when it is running in the manual mode of BMM150 Mag interface*/
  60. u8 bmm150_manual_auto_condition_u8_g;
  61. /*Power mode monitoring variable used to introduce delays after primary
  62. interface write in low power and suspend modes of sensor */
  63. u8 bmi160_power_mode_status_u8_g;
  64. /* FIFO data read for 1024 bytes of data */
  65. #ifdef FIFO_ENABLE
  66. static u8 v_fifo_data_u8[FIFO_FRAME];
  67. struct bmi160_mag_fifo_data_t mag_data;
  68. #endif
  69. /* YAMAHA-YAS532*/
  70. /* value of coefficient*/
  71. #ifdef YAS532
  72. static const int yas532_version_ac_coef[] = {YAS532_VERSION_AC_COEF_X,
  73. YAS532_VERSION_AC_COEF_Y1, YAS532_VERSION_AC_COEF_Y2};
  74. /* used for reading the yas532 calibration data*/
  75. struct yas532_t yas532_data;
  76. struct yas532_vector fifo_xyz_data;
  77. #endif
  78. #ifdef YAS537
  79. /* used for reading the yas537 calibration data*/
  80. struct yas537_t yas537_data;
  81. struct yas_vector fifo_vector_xyz;
  82. /*!
  83. * @brief This function is used to process the
  84. * YAMAHA YAS537 xy1y2 raw data
  85. *
  86. * @param xy1y2: The value of raw xy1y2 data
  87. * @param xyz: The value of xyz data
  88. *
  89. *
  90. * @return None
  91. *
  92. *
  93. */
  94. static void xy1y2_to_xyz(u16 *xy1y2, s32 *xyz);
  95. /*!
  96. * @brief This function is used to detect whether the mag
  97. * data obtained is valid or not
  98. *
  99. *
  100. * @param v_cur_u16: The value of current Mag data
  101. * @param v_last_u16: The value of last Mag data
  102. *
  103. *
  104. * @return result of magnetic field data's validity
  105. * @retval 0 -> VALID DATA
  106. * @retval 1 -> INVALID DATA
  107. *
  108. *
  109. */
  110. static BMI160_RETURN_FUNCTION_TYPE invalid_magnetic_field(
  111. u16 *v_cur_u16, u16 *v_last_u16);
  112. #endif
  113. #if defined AKM09911 || defined AKM09912
  114. /* used to read the AKM compensating data */
  115. struct bst_akm_sensitivity_data_t akm_asa_data;
  116. #endif
  117. struct bmi160_mag_xyz_s32_t processed_data;
  118. /*!
  119. * @brief
  120. * This API is used to initialize
  121. * bus read and bus write functions
  122. * assign the chip id and device address.
  123. * chip id is read in the register 0x00 bit from 0 to 7
  124. *
  125. * @param bmi160 : structure pointer of bmi160 instance
  126. *
  127. * @return results of bus communication function
  128. * @retval 0 -> Success
  129. * @retval -1 -> Error
  130. *
  131. * @note
  132. * While changing the parameter of the bmi160_t
  133. * consider the following points:
  134. * Changing the reference value of the parameter
  135. * will change the local copy or local reference
  136. * make sure your changes will not
  137. * affect the reference value of the parameter
  138. * (Better don't change the reference value of the parameter)
  139. *
  140. */
  141. BMI160_RETURN_FUNCTION_TYPE bmi160_init(struct bmi160_t *bmi160)
  142. {
  143. /* variable used to return the status of communication result*/
  144. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  145. u8 v_data_u8 = BMI160_INIT_VALUE;
  146. u8 v_pmu_data_u8 = BMI160_INIT_VALUE;
  147. /* assign bmi160 pointer */
  148. p_bmi160 = bmi160;
  149. com_rslt =
  150. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  151. BMI160_USER_CHIP_ID__REG,
  152. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  153. /* store the chip id which is read from the sensor */
  154. p_bmi160->chip_id = v_data_u8;
  155. /* To avoid gyro wakeup it is required to write 0x00 to 0x6C*/
  156. com_rslt += bmi160_write_reg(BMI160_USER_PMU_TRIGGER_ADDR,
  157. &v_pmu_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  158. return com_rslt;
  159. }
  160. /*!
  161. * @brief
  162. * This API writes the data to
  163. * the given register
  164. *
  165. *
  166. * @param v_addr_u8 -> Address of the register
  167. * @param v_data_u8 -> The data to write to the register
  168. * @param v_len_u8 -> no of bytes to write
  169. *
  170. *
  171. * @return results of bus communication function
  172. * @retval 0 -> Success
  173. * @retval -1 -> Error
  174. *
  175. *
  176. */
  177. BMI160_RETURN_FUNCTION_TYPE bmi160_write_reg(u8 v_addr_u8,
  178. u8 *v_data_u8, u8 v_len_u8)
  179. {
  180. /* variable used to return the status of communication result*/
  181. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  182. /* check the p_bmi160 structure for NULL pointer assignment*/
  183. if (p_bmi160 == BMI160_NULL) {
  184. return E_BMI160_NULL_PTR;
  185. } else {
  186. /* write data from register*/
  187. com_rslt =
  188. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->dev_addr,
  189. v_addr_u8, v_data_u8, v_len_u8);
  190. /*Accel and Gyro power mode check*/
  191. if (bmi160_power_mode_status_u8_g !=
  192. BMI160_NORMAL_MODE)
  193. /*interface idle time delay */
  194. p_bmi160->delay_msec(
  195. BMI160_GEN_READ_WRITE_DELAY);
  196. }
  197. return com_rslt;
  198. }
  199. /*!
  200. * @brief
  201. * This API reads the data from
  202. * the given register
  203. *
  204. *
  205. * @param v_addr_u8 -> Address of the register
  206. * @param v_data_u8 -> The data read from the register
  207. * @param v_len_u8 -> no of bytes to read
  208. *
  209. *
  210. * @return results of bus communication function
  211. * @retval 0 -> Success
  212. * @retval -1 -> Error
  213. *
  214. *
  215. */
  216. BMI160_RETURN_FUNCTION_TYPE bmi160_read_reg(u8 v_addr_u8,
  217. u8 *v_data_u8, u8 v_len_u8)
  218. {
  219. /* variable used to return the status of communication result*/
  220. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  221. /* check the p_bmi160 structure for NULL pointer assignment*/
  222. if (p_bmi160 == BMI160_NULL) {
  223. return E_BMI160_NULL_PTR;
  224. } else {
  225. /* Read data from register*/
  226. com_rslt =
  227. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  228. v_addr_u8, v_data_u8, v_len_u8);
  229. }
  230. return com_rslt;
  231. }
  232. /*!
  233. * @brief This API is used to read the fatal error
  234. * from the register 0x02 bit 0
  235. * This flag will be reset only by power-on-reset and soft reset
  236. *
  237. *
  238. * @param v_fatal_err_u8 : The status of fatal error
  239. *
  240. *
  241. *
  242. * @return results of bus communication function
  243. * @retval 0 -> Success
  244. * @retval -1 -> Error
  245. *
  246. *
  247. */
  248. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fatal_err(u8
  249. *v_fatal_err_u8)
  250. {
  251. /* variable used to return the status of communication result*/
  252. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  253. u8 v_data_u8 = BMI160_INIT_VALUE;
  254. /* check the p_bmi160 structure for NULL pointer assignment*/
  255. if (p_bmi160 == BMI160_NULL) {
  256. return E_BMI160_NULL_PTR;
  257. } else {
  258. /* read the fatal error status*/
  259. com_rslt =
  260. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  261. BMI160_USER_FATAL_ERR__REG,
  262. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  263. *v_fatal_err_u8 = BMI160_GET_BITSLICE(v_data_u8,
  264. BMI160_USER_FATAL_ERR);
  265. }
  266. return com_rslt;
  267. }
  268. /*!
  269. * @brief This API is used to read the error code
  270. * from register 0x02 bit 1 to 4
  271. *
  272. *
  273. * @param v_err_code_u8 : The status of error codes
  274. * error_code | description
  275. * ------------|---------------
  276. * 0x00 |no error
  277. * 0x01 |ACC_CONF error (Accel ODR and bandwidth not compatible)
  278. * 0x02 |GYR_CONF error (Gyro ODR and bandwidth not compatible)
  279. * 0x03 |Under sampling mode and interrupt uses pre filtered data
  280. * 0x04 |reserved
  281. * 0x05 |Selected trigger-readout offset in MAG_IF is greater than
  282. * |selected ODR
  283. * 0x06 |FIFO configuration error for header less mode
  284. * 0x07 |Under sampling mode and pre filtered data as FIFO source
  285. *
  286. * @return results of bus communication function
  287. * @retval 0 -> Success
  288. * @retval -1 -> Error
  289. *
  290. *
  291. */
  292. BMI160_RETURN_FUNCTION_TYPE bmi160_get_err_code(u8
  293. *v_err_code_u8)
  294. {
  295. /* variable used to return the status of communication result*/
  296. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  297. u8 v_data_u8 = BMI160_INIT_VALUE;
  298. /* check the p_bmi160 structure for NULL pointer assignment*/
  299. if (p_bmi160 == BMI160_NULL) {
  300. return E_BMI160_NULL_PTR;
  301. } else {
  302. com_rslt =
  303. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  304. BMI160_USER_ERR_CODE__REG,
  305. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  306. *v_err_code_u8 = BMI160_GET_BITSLICE(v_data_u8,
  307. BMI160_USER_ERR_CODE);
  308. }
  309. return com_rslt;
  310. }
  311. /*!
  312. * @brief This API reads the i2c error code from the
  313. * Register 0x02 bit 5.
  314. * This error occurred in I2C master detected
  315. *
  316. * @param v_i2c_err_code_u8 : The status of i2c fail error
  317. *
  318. *
  319. *
  320. * @return results of bus communication function
  321. * @retval 0 -> Success
  322. * @retval -1 -> Error
  323. *
  324. *
  325. */
  326. BMI160_RETURN_FUNCTION_TYPE bmi160_get_i2c_fail_err(u8
  327. *v_i2c_err_code_u8)
  328. {
  329. /* variable used to return the status of communication result*/
  330. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  331. u8 v_data_u8 = BMI160_INIT_VALUE;
  332. /* check the p_bmi160 structure for NULL pointer assignment*/
  333. if (p_bmi160 == BMI160_NULL) {
  334. return E_BMI160_NULL_PTR;
  335. } else {
  336. com_rslt =
  337. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  338. BMI160_USER_I2C_FAIL_ERR__REG,
  339. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  340. *v_i2c_err_code_u8 = BMI160_GET_BITSLICE(v_data_u8,
  341. BMI160_USER_I2C_FAIL_ERR);
  342. }
  343. return com_rslt;
  344. }
  345. /*!
  346. * @brief This API reads the dropped command error
  347. * from the register 0x02 bit 6
  348. *
  349. *
  350. * @param v_drop_cmd_err_u8 : The status of dropped command error
  351. *
  352. *
  353. *
  354. * @return results of bus communication function
  355. * @retval 0 -> Success
  356. * @retval -1 -> Error
  357. *
  358. *
  359. */
  360. BMI160_RETURN_FUNCTION_TYPE bmi160_get_drop_cmd_err(u8
  361. *v_drop_cmd_err_u8)
  362. {
  363. /* variable used to return the status of communication result*/
  364. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  365. u8 v_data_u8 = BMI160_INIT_VALUE;
  366. /* check the p_bmi160 structure for NULL pointer assignment*/
  367. if (p_bmi160 == BMI160_NULL) {
  368. return E_BMI160_NULL_PTR;
  369. } else {
  370. com_rslt =
  371. p_bmi160->BMI160_BUS_READ_FUNC(
  372. p_bmi160->dev_addr,
  373. BMI160_USER_DROP_CMD_ERR__REG,
  374. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  375. *v_drop_cmd_err_u8 = BMI160_GET_BITSLICE(
  376. v_data_u8,
  377. BMI160_USER_DROP_CMD_ERR);
  378. }
  379. return com_rslt;
  380. }
  381. /*!
  382. * @brief This API reads the Mag data ready
  383. * error interrupt
  384. * It reads from the error register 0x02 bit 7
  385. *
  386. *
  387. *
  388. *
  389. * @param v_mag_data_rdy_err_u8 : The status of Mag data ready error interrupt
  390. *
  391. *
  392. *
  393. * @return results of bus communication function
  394. * @retval 0 -> Success
  395. * @retval -1 -> Error
  396. *
  397. *
  398. */
  399. BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_data_rdy_err(
  400. u8 *v_mag_data_rdy_err_u8)
  401. {
  402. /* variable used to return the status of communication result*/
  403. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  404. u8 v_data_u8 = BMI160_INIT_VALUE;
  405. /* check the p_bmi160 structure for NULL pointer assignment*/
  406. if (p_bmi160 == BMI160_NULL) {
  407. return E_BMI160_NULL_PTR;
  408. } else {
  409. com_rslt =
  410. p_bmi160->BMI160_BUS_READ_FUNC(
  411. p_bmi160->dev_addr,
  412. BMI160_USER_MAG_DATA_RDY_ERR__REG,
  413. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  414. *v_mag_data_rdy_err_u8 =
  415. BMI160_GET_BITSLICE(v_data_u8,
  416. BMI160_USER_MAG_DATA_RDY_ERR);
  417. }
  418. return com_rslt;
  419. }
  420. /*!
  421. * @brief This API reads the error status
  422. * from the error register 0x02 bit 0 to 7
  423. *
  424. * @param v_mag_data_rdy_err_u8 : The status of Mag data ready interrupt
  425. * @param v_fatal_err_u8 : The status of fatal error
  426. * @param v_err_code_u8 : The status of error code
  427. * @param v_i2c_fail_err_u8 : The status of I2C fail error
  428. * @param v_drop_cmd_err_u8 : The status of drop command error
  429. *
  430. *
  431. *
  432. * @return results of bus communication function
  433. * @retval 0 -> Success
  434. * @retval -1 -> Error
  435. *
  436. *
  437. */
  438. BMI160_RETURN_FUNCTION_TYPE bmi160_get_error_status(u8 *v_fatal_err_u8,
  439. u8 *v_err_code_u8, u8 *v_i2c_fail_err_u8,
  440. u8 *v_drop_cmd_err_u8, u8 *v_mag_data_rdy_err_u8)
  441. {
  442. /* variable used to return the status of communication result*/
  443. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  444. u8 v_data_u8 = BMI160_INIT_VALUE;
  445. /* check the p_bmi160 structure for NULL pointer assignment*/
  446. if (p_bmi160 == BMI160_NULL) {
  447. return E_BMI160_NULL_PTR;
  448. } else {
  449. /* read the error codes*/
  450. com_rslt =
  451. p_bmi160->BMI160_BUS_READ_FUNC(
  452. p_bmi160->dev_addr,
  453. BMI160_USER_ERR_STAT__REG,
  454. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  455. /* fatal error*/
  456. *v_fatal_err_u8 =
  457. BMI160_GET_BITSLICE(v_data_u8,
  458. BMI160_USER_FATAL_ERR);
  459. /* user error*/
  460. *v_err_code_u8 =
  461. BMI160_GET_BITSLICE(v_data_u8,
  462. BMI160_USER_ERR_CODE);
  463. /* i2c fail error*/
  464. *v_i2c_fail_err_u8 =
  465. BMI160_GET_BITSLICE(v_data_u8,
  466. BMI160_USER_I2C_FAIL_ERR);
  467. /* drop command error*/
  468. *v_drop_cmd_err_u8 =
  469. BMI160_GET_BITSLICE(v_data_u8,
  470. BMI160_USER_DROP_CMD_ERR);
  471. /* Mag data ready error*/
  472. *v_mag_data_rdy_err_u8 =
  473. BMI160_GET_BITSLICE(v_data_u8,
  474. BMI160_USER_MAG_DATA_RDY_ERR);
  475. }
  476. return com_rslt;
  477. }
  478. /*!
  479. * @brief This API reads the Mag power mode from
  480. * PMU status register 0x03 bit 0 and 1
  481. *
  482. * @param v_mag_power_mode_stat_u8 : The value of Mag power mode
  483. * mag_powermode | value
  484. * ------------------|----------
  485. * SUSPEND | 0x00
  486. * NORMAL | 0x01
  487. * LOW POWER | 0x02
  488. *
  489. *
  490. * @note The power mode of Mag is set by the 0x7E command register
  491. * using the function "bmi160_set_command_register()"
  492. * value | mode
  493. * ---------|----------------
  494. * 0x18 | MAG_MODE_SUSPEND
  495. * 0x19 | MAG_MODE_NORMAL
  496. * 0x1A | MAG_MODE_LOWPOWER
  497. *
  498. * @return results of bus communication function
  499. * @retval 0 -> Success
  500. * @retval -1 -> Error
  501. *
  502. *
  503. */
  504. BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_power_mode_stat(u8
  505. *v_mag_power_mode_stat_u8)
  506. {
  507. /* variable used to return the status of communication result*/
  508. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  509. u8 v_data_u8 = BMI160_INIT_VALUE;
  510. /* check the p_bmi160 structure for NULL pointer assignment*/
  511. if (p_bmi160 == BMI160_NULL) {
  512. return E_BMI160_NULL_PTR;
  513. } else {
  514. com_rslt =
  515. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  516. BMI160_USER_MAG_POWER_MODE_STAT__REG,
  517. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  518. *v_mag_power_mode_stat_u8 =
  519. BMI160_GET_BITSLICE(v_data_u8,
  520. BMI160_USER_MAG_POWER_MODE_STAT);
  521. }
  522. return com_rslt;
  523. }
  524. /*!
  525. * @brief This API reads the Gyro power mode from
  526. * PMU status register 0x03 bit 2 and 3
  527. *
  528. * @param v_gyro_power_mode_stat_u8 : The value of gyro power mode
  529. * gyro_powermode | value
  530. * ------------------|----------
  531. * SUSPEND | 0x00
  532. * NORMAL | 0x01
  533. * FAST POWER UP | 0x03
  534. *
  535. * @note The power mode of gyro is set by the 0x7E command register
  536. * using the function "bmi160_set_command_register()"
  537. * value | mode
  538. * ---------|----------------
  539. * 0x14 | GYRO_MODE_SUSPEND
  540. * 0x15 | GYRO_MODE_NORMAL
  541. * 0x17 | GYRO_MODE_FASTSTARTUP
  542. *
  543. * @return results of bus communication function
  544. * @retval 0 -> Success
  545. * @retval -1 -> Error
  546. *
  547. *
  548. */
  549. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_power_mode_stat(u8
  550. *v_gyro_power_mode_stat_u8)
  551. {
  552. /* variable used to return the status of communication result*/
  553. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  554. u8 v_data_u8 = BMI160_INIT_VALUE;
  555. /* check the p_bmi160 structure for NULL pointer assignment*/
  556. if (p_bmi160 == BMI160_NULL) {
  557. return E_BMI160_NULL_PTR;
  558. } else {
  559. com_rslt =
  560. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  561. BMI160_USER_GYRO_POWER_MODE_STAT__REG,
  562. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  563. *v_gyro_power_mode_stat_u8 =
  564. BMI160_GET_BITSLICE(v_data_u8,
  565. BMI160_USER_GYRO_POWER_MODE_STAT);
  566. }
  567. return com_rslt;
  568. }
  569. /*!
  570. * @brief This API reads the Accel power mode from
  571. * PMU status register 0x03 bit 4 and 5
  572. *
  573. *
  574. * @param v_accel_power_mode_stat_u8 : The value of Accel power mode
  575. * accel_powermode | value
  576. * ------------------|----------
  577. * SUSPEND | 0x00
  578. * NORMAL | 0x01
  579. * LOW POWER | 0x02
  580. *
  581. * @note The power mode of Accel is set by the 0x7E command register
  582. * using the function "bmi160_set_command_register()"
  583. * value | mode
  584. * ---------|----------------
  585. * 0x11 | ACCEL_MODE_NORMAL
  586. * 0x12 | ACCEL_LOWPOWER
  587. * 0x10 | ACCEL_SUSPEND
  588. *
  589. * @return results of bus communication function
  590. * @retval 0 -> Success
  591. * @retval -1 -> Error
  592. *
  593. *
  594. */
  595. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_power_mode_stat(u8
  596. *v_accel_power_mode_stat_u8)
  597. {
  598. /* variable used to return the status of communication result*/
  599. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  600. u8 v_data_u8 = BMI160_INIT_VALUE;
  601. /* check the p_bmi160 structure for NULL pointer assignment*/
  602. if (p_bmi160 == BMI160_NULL) {
  603. return E_BMI160_NULL_PTR;
  604. } else {
  605. com_rslt =
  606. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  607. BMI160_USER_ACCEL_POWER_MODE_STAT__REG,
  608. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  609. *v_accel_power_mode_stat_u8 =
  610. BMI160_GET_BITSLICE(v_data_u8,
  611. BMI160_USER_ACCEL_POWER_MODE_STAT);
  612. }
  613. return com_rslt;
  614. }
  615. /*!
  616. * @brief This API switches the Mag interface to normal mode
  617. * and confirm whether the mode switching is done successfully or not
  618. *
  619. * @return results of bus communication function
  620. * @retval 0 -> Success
  621. * @retval -1 -> Error
  622. *
  623. */
  624. BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_interface_normal(void)
  625. {
  626. /* variable used to return the status of communication result*/
  627. BMI160_RETURN_FUNCTION_TYPE com_rslt = BMI160_INIT_VALUE;
  628. /* aim to check the result of switching Mag normal */
  629. u8 v_try_times_u8 = BMI160_MAG_NORMAL_SWITCH_TIMES;
  630. u8 v_mag_pmu_status_u8 = BMI160_INIT_VALUE;
  631. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  632. com_rslt = bmi160_set_command_register(MAG_MODE_NORMAL);
  633. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  634. while (v_try_times_u8 != 0) {
  635. com_rslt = bmi160_get_mag_power_mode_stat(&v_mag_pmu_status_u8);
  636. if (v_mag_pmu_status_u8 == MAG_INTERFACE_PMU_ENABLE)
  637. break;
  638. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  639. v_try_times_u8--;
  640. }
  641. if (v_mag_pmu_status_u8 == MAG_INTERFACE_PMU_ENABLE)
  642. com_rslt += SUCCESS;
  643. else
  644. com_rslt += E_BMI160_COMM_RES;
  645. return com_rslt;
  646. }
  647. /*!
  648. * @brief This API reads Mag data X values
  649. * from the register 0x04 and 0x05
  650. * @brief The Mag sensor data read from auxiliary mag
  651. *
  652. * @param v_mag_x_s16 : The value of Mag x
  653. * @param v_sensor_select_u8 : Mag selection value
  654. * value | sensor
  655. * ---------|----------------
  656. * 0 | BMM150
  657. * 1 | AKM09911 or AKM09912
  658. *
  659. * @note For Mag output data rate configuration use the following function
  660. * bmi160_set_mag_output_data_rate()
  661. *
  662. *
  663. *
  664. * @return results of bus communication function
  665. * @retval 0 -> Success
  666. * @retval -1 -> Error
  667. *
  668. */
  669. BMI160_RETURN_FUNCTION_TYPE bmi160_read_mag_x(s16 *v_mag_x_s16,
  670. u8 v_sensor_select_u8)
  671. {
  672. /* variable used to return the status of communication result*/
  673. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  674. /* Array contains the Mag X LSB and MSB data
  675. v_data_u8[0] - LSB
  676. v_data_u8[1] - MSB*/
  677. u8 v_data_u8[BMI160_MAG_X_DATA_SIZE] = {BMI160_INIT_VALUE,
  678. BMI160_INIT_VALUE};
  679. /* check the p_bmi160 structure for NULL pointer assignment*/
  680. if (p_bmi160 == BMI160_NULL) {
  681. return E_BMI160_NULL_PTR;
  682. } else {
  683. switch (v_sensor_select_u8) {
  684. case BST_BMM:
  685. com_rslt =
  686. p_bmi160->BMI160_BUS_READ_FUNC(
  687. p_bmi160->dev_addr,
  688. BMI160_USER_DATA_MAG_X_LSB__REG,
  689. v_data_u8, BMI160_MAG_X_DATA_LENGTH);
  690. /* X axis*/
  691. v_data_u8[BMI160_MAG_X_LSB_BYTE] =
  692. BMI160_GET_BITSLICE(v_data_u8[BMI160_MAG_X_LSB_BYTE],
  693. BMI160_USER_DATA_MAG_X_LSB);
  694. *v_mag_x_s16 = (s16)
  695. ((((s32)((s8)v_data_u8[BMI160_MAG_X_MSB_BYTE]))
  696. << BMI160_SHIFT_BIT_POSITION_BY_05_BITS) |
  697. (v_data_u8[BMI160_MAG_X_LSB_BYTE]));
  698. break;
  699. case BST_AKM:
  700. com_rslt =
  701. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  702. BMI160_USER_DATA_0_MAG_X_LSB__REG,
  703. v_data_u8, BMI160_MAG_X_DATA_LENGTH);
  704. *v_mag_x_s16 = (s16)
  705. ((((s32)((s8)v_data_u8[BMI160_MAG_X_MSB_BYTE]))
  706. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) |
  707. (v_data_u8[BMI160_MAG_X_LSB_BYTE]));
  708. break;
  709. default:
  710. com_rslt = E_BMI160_OUT_OF_RANGE;
  711. break;
  712. }
  713. }
  714. return com_rslt;
  715. }
  716. /*!
  717. * @brief This API reads Mag data Y values
  718. * from the register 0x06 and 0x07
  719. * @brief The Mag sensor data read from auxiliary mag
  720. *
  721. * @param v_mag_y_s16 : The value of Mag y
  722. * @param v_sensor_select_u8 : Mag selection value
  723. * value | sensor
  724. * ---------|----------------
  725. * 0 | BMM150
  726. * 1 | AKM09911 or AKM09912
  727. *
  728. * @note For Mag output data rate configuration use the following function
  729. * bmi160_set_mag_output_data_rate()
  730. *
  731. * @return results of bus communication function
  732. * @retval 0 -> Success
  733. * @retval -1 -> Error
  734. *
  735. *
  736. */
  737. BMI160_RETURN_FUNCTION_TYPE bmi160_read_mag_y(s16 *v_mag_y_s16,
  738. u8 v_sensor_select_u8)
  739. {
  740. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_OUT_OF_RANGE;
  741. /* Array contains the Mag Y LSB and MSB data
  742. v_data_u8[0] - LSB
  743. v_data_u8[1] - MSB*/
  744. u8 v_data_u8[BMI160_MAG_Y_DATA_SIZE] = {BMI160_INIT_VALUE,
  745. BMI160_INIT_VALUE};
  746. /* check the p_bmi160 structure for NULL pointer assignment*/
  747. if (p_bmi160 == BMI160_NULL) {
  748. return E_BMI160_NULL_PTR;
  749. } else {
  750. switch (v_sensor_select_u8) {
  751. case BST_BMM:
  752. com_rslt =
  753. p_bmi160->BMI160_BUS_READ_FUNC(
  754. p_bmi160->dev_addr,
  755. BMI160_USER_DATA_MAG_Y_LSB__REG,
  756. v_data_u8, BMI160_MAG_Y_DATA_LENGTH);
  757. /*Y-axis LSB value shifting*/
  758. v_data_u8[BMI160_MAG_Y_LSB_BYTE] =
  759. BMI160_GET_BITSLICE(v_data_u8[BMI160_MAG_Y_LSB_BYTE],
  760. BMI160_USER_DATA_MAG_Y_LSB);
  761. *v_mag_y_s16 = (s16)
  762. ((((s32)((s8)v_data_u8[BMI160_MAG_Y_MSB_BYTE]))
  763. << BMI160_SHIFT_BIT_POSITION_BY_05_BITS) |
  764. (v_data_u8[BMI160_MAG_Y_LSB_BYTE]));
  765. break;
  766. case BST_AKM:
  767. com_rslt =
  768. p_bmi160->BMI160_BUS_READ_FUNC(
  769. p_bmi160->dev_addr,
  770. BMI160_USER_DATA_2_MAG_Y_LSB__REG,
  771. v_data_u8, BMI160_MAG_Y_DATA_LENGTH);
  772. *v_mag_y_s16 = (s16)
  773. ((((s32)((s8)v_data_u8[BMI160_MAG_Y_MSB_BYTE]))
  774. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) |
  775. (v_data_u8[BMI160_MAG_Y_LSB_BYTE]));
  776. break;
  777. default:
  778. com_rslt = E_BMI160_OUT_OF_RANGE;
  779. break;
  780. }
  781. }
  782. return com_rslt;
  783. }
  784. /*!
  785. * @brief This API reads Mag data Z values
  786. * from the register 0x08 and 0x09
  787. * @brief The Mag sensor data read from auxiliary mag
  788. *
  789. * @param v_mag_z_s16 : The value of Mag z
  790. * @param v_sensor_select_u8 : Mag selection value
  791. * value | sensor
  792. * ---------|----------------
  793. * 0 | BMM150
  794. * 1 | AKM09911 or AKM09912
  795. *
  796. * @note For Mag output data rate configuration use the following function
  797. * bmi160_set_mag_output_data_rate()
  798. *
  799. * @return results of bus communication function
  800. * @retval 0 -> Success
  801. * @retval -1 -> Error
  802. *
  803. *
  804. */
  805. BMI160_RETURN_FUNCTION_TYPE bmi160_read_mag_z(s16 *v_mag_z_s16,
  806. u8 v_sensor_select_u8)
  807. {
  808. /* variable used to return the status of communication result*/
  809. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  810. /* Array contains the Mag Z LSB and MSB data
  811. v_data_u8[0] - LSB
  812. v_data_u8[1] - MSB*/
  813. u8 v_data_u8[BMI160_MAG_Z_DATA_SIZE] = {BMI160_INIT_VALUE,
  814. BMI160_INIT_VALUE};
  815. /* check the p_bmi160 structure for NULL pointer assignment*/
  816. if (p_bmi160 == BMI160_NULL) {
  817. return E_BMI160_NULL_PTR;
  818. } else {
  819. switch (v_sensor_select_u8) {
  820. case BST_BMM:
  821. com_rslt =
  822. p_bmi160->BMI160_BUS_READ_FUNC(
  823. p_bmi160->dev_addr,
  824. BMI160_USER_DATA_MAG_Z_LSB__REG,
  825. v_data_u8, BMI160_MAG_Z_DATA_LENGTH);
  826. /*Z-axis LSB value shifting*/
  827. v_data_u8[BMI160_MAG_Z_LSB_BYTE] =
  828. BMI160_GET_BITSLICE(v_data_u8[BMI160_MAG_Z_LSB_BYTE],
  829. BMI160_USER_DATA_MAG_Z_LSB);
  830. *v_mag_z_s16 = (s16)
  831. ((((s32)((s8)v_data_u8[BMI160_MAG_Z_MSB_BYTE]))
  832. << BMI160_SHIFT_BIT_POSITION_BY_07_BITS) |
  833. (v_data_u8[BMI160_MAG_Z_LSB_BYTE]));
  834. break;
  835. case BST_AKM:
  836. com_rslt =
  837. p_bmi160->BMI160_BUS_READ_FUNC(
  838. p_bmi160->dev_addr,
  839. BMI160_USER_DATA_4_MAG_Z_LSB__REG,
  840. v_data_u8, BMI160_MAG_Z_DATA_LENGTH);
  841. *v_mag_z_s16 = (s16)
  842. ((((s32)((s8)v_data_u8[BMI160_MAG_Z_MSB_BYTE]))
  843. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) | (
  844. v_data_u8[BMI160_MAG_Z_LSB_BYTE]));
  845. break;
  846. default:
  847. com_rslt = E_BMI160_OUT_OF_RANGE;
  848. break;
  849. }
  850. }
  851. return com_rslt;
  852. }
  853. /*!
  854. * @brief This API reads Mag data RHALL values
  855. * from the register 0x0A and 0x0B
  856. *
  857. *
  858. * @param v_mag_r_s16 : The value of BMM150 r data
  859. *
  860. *
  861. *
  862. * @return results of bus communication function
  863. * @retval 0 -> Success
  864. * @retval -1 -> Error
  865. *
  866. *
  867. */
  868. BMI160_RETURN_FUNCTION_TYPE bmi160_read_mag_r(s16 *v_mag_r_s16)
  869. {
  870. /* variable used to return the status of communication result*/
  871. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  872. /* Array contains the Mag R LSB and MSB data
  873. v_data_u8[0] - LSB
  874. v_data_u8[1] - MSB*/
  875. u8 v_data_u8[BMI160_MAG_R_DATA_SIZE] = {BMI160_INIT_VALUE,
  876. BMI160_INIT_VALUE};
  877. /* check the p_bmi160 structure for NULL pointer assignment*/
  878. if (p_bmi160 == BMI160_NULL) {
  879. return E_BMI160_NULL_PTR;
  880. } else {
  881. com_rslt =
  882. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  883. BMI160_USER_DATA_6_RHALL_LSB__REG,
  884. v_data_u8, BMI160_MAG_R_DATA_LENGTH);
  885. /*R-axis LSB value shifting*/
  886. v_data_u8[BMI160_MAG_R_LSB_BYTE] =
  887. BMI160_GET_BITSLICE(v_data_u8[BMI160_MAG_R_LSB_BYTE],
  888. BMI160_USER_DATA_MAG_R_LSB);
  889. *v_mag_r_s16 = (s16)
  890. ((((s32)((s8)v_data_u8[BMI160_MAG_R_MSB_BYTE]))
  891. << BMI160_SHIFT_BIT_POSITION_BY_06_BITS) |
  892. (v_data_u8[BMI160_MAG_R_LSB_BYTE]));
  893. }
  894. return com_rslt;
  895. }
  896. /*!
  897. * @brief This API reads Mag data X,Y,Z values
  898. * from the register 0x04 to 0x09
  899. *
  900. * @brief The Mag sensor data read from auxiliary mag
  901. *
  902. * @param Mag : The value of Mag xyz data
  903. * @param v_sensor_select_u8 : Mag selection value
  904. * value | sensor
  905. * ---------|----------------
  906. * 0 | BMM150
  907. * 1 | AKM09911 or AKM09912
  908. *
  909. * @note For Mag output data rate configuration use the following function
  910. * @note bmi160_set_mag_output_data_rate()
  911. *
  912. * @return results of bus communication function
  913. * @retval 0 -> Success
  914. * @retval -1 -> Error *
  915. *
  916. */
  917. BMI160_RETURN_FUNCTION_TYPE bmi160_read_mag_xyz(
  918. struct bmi160_mag_t *mag, u8 v_sensor_select_u8)
  919. {
  920. /* variable used to return the status of communication result*/
  921. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  922. /* Array contains the Mag XYZ LSB and MSB data
  923. v_data_u8[0] - X-LSB
  924. v_data_u8[1] - X-MSB
  925. v_data_u8[0] - Y-LSB
  926. v_data_u8[1] - Y-MSB
  927. v_data_u8[0] - Z-LSB
  928. v_data_u8[1] - Z-MSB
  929. */
  930. u8 v_data_u8[BMI160_MAG_XYZ_DATA_SIZE] = {
  931. BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  932. BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  933. BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  934. /* check the p_bmi160 structure for NULL pointer assignment*/
  935. if (p_bmi160 == BMI160_NULL) {
  936. return E_BMI160_NULL_PTR;
  937. } else {
  938. switch (v_sensor_select_u8) {
  939. case BST_BMM:
  940. com_rslt =
  941. p_bmi160->BMI160_BUS_READ_FUNC(
  942. p_bmi160->dev_addr,
  943. BMI160_USER_DATA_MAG_X_LSB__REG,
  944. v_data_u8, BMI160_MAG_XYZ_DATA_LENGTH);
  945. /*X-axis LSB value shifting*/
  946. v_data_u8[BMI160_DATA_FRAME_MAG_X_LSB_BYTE] =
  947. BMI160_GET_BITSLICE(
  948. v_data_u8[BMI160_DATA_FRAME_MAG_X_LSB_BYTE],
  949. BMI160_USER_DATA_MAG_X_LSB);
  950. /* Data X */
  951. mag->x = (s16)
  952. ((((s32)((s8)v_data_u8[
  953. BMI160_DATA_FRAME_MAG_X_MSB_BYTE]))
  954. << BMI160_SHIFT_BIT_POSITION_BY_05_BITS) |
  955. (v_data_u8[BMI160_DATA_FRAME_MAG_X_LSB_BYTE]));
  956. /* Data Y */
  957. /*Y-axis LSB value shifting*/
  958. v_data_u8[BMI160_DATA_FRAME_MAG_Y_LSB_BYTE] =
  959. BMI160_GET_BITSLICE(
  960. v_data_u8[BMI160_DATA_FRAME_MAG_Y_LSB_BYTE],
  961. BMI160_USER_DATA_MAG_Y_LSB);
  962. mag->y = (s16)
  963. ((((s32)((s8)v_data_u8[
  964. BMI160_DATA_FRAME_MAG_Y_MSB_BYTE]))
  965. << BMI160_SHIFT_BIT_POSITION_BY_05_BITS) |
  966. (v_data_u8[BMI160_DATA_FRAME_MAG_Y_LSB_BYTE]));
  967. /* Data Z */
  968. /*Z-axis LSB value shifting*/
  969. v_data_u8[BMI160_DATA_FRAME_MAG_Z_LSB_BYTE]
  970. = BMI160_GET_BITSLICE(
  971. v_data_u8[BMI160_DATA_FRAME_MAG_Z_LSB_BYTE],
  972. BMI160_USER_DATA_MAG_Z_LSB);
  973. mag->z = (s16)
  974. ((((s32)((s8)v_data_u8[
  975. BMI160_DATA_FRAME_MAG_Z_MSB_BYTE]))
  976. << BMI160_SHIFT_BIT_POSITION_BY_07_BITS) |
  977. (v_data_u8[BMI160_DATA_FRAME_MAG_Z_LSB_BYTE]));
  978. break;
  979. case BST_AKM:
  980. com_rslt =
  981. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  982. BMI160_USER_DATA_0_MAG_X_LSB__REG,
  983. v_data_u8, BMI160_MAG_XYZ_DATA_LENGTH);
  984. /* Data X */
  985. mag->x = (s16)
  986. ((((s32)((s8)v_data_u8[
  987. BMI160_DATA_FRAME_MAG_X_MSB_BYTE]))
  988. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) |
  989. (v_data_u8[BMI160_DATA_FRAME_MAG_X_LSB_BYTE]));
  990. /* Data Y */
  991. mag->y = ((((s32)((s8)v_data_u8[
  992. BMI160_DATA_FRAME_MAG_Y_MSB_BYTE]))
  993. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) |
  994. (v_data_u8[BMI160_DATA_FRAME_MAG_Y_LSB_BYTE]));
  995. /* Data Z */
  996. mag->z = (s16)
  997. ((((s32)((s8)v_data_u8[
  998. BMI160_DATA_FRAME_MAG_Z_MSB_BYTE]))
  999. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) |
  1000. (v_data_u8[BMI160_DATA_FRAME_MAG_Z_LSB_BYTE]));
  1001. break;
  1002. default:
  1003. com_rslt = E_BMI160_OUT_OF_RANGE;
  1004. break;
  1005. }
  1006. }
  1007. return com_rslt;
  1008. }
  1009. /*!*
  1010. * @brief This API reads Mag data X,Y,Z,r
  1011. * values from the register 0x04 to 0x0B.
  1012. *
  1013. * @brief The Mag sensor data read from auxiliary mag.
  1014. *
  1015. * @param Mag : The value of mag-BMM150 xyzr data.
  1016. *
  1017. * @note For Mag data output rate configuration use the following function
  1018. * @note bmi160_set_mag_output_data_rate().
  1019. *
  1020. * @return results of bus communication function.
  1021. * @retval 0 -> Success
  1022. * @retval -1 -> Error
  1023. *
  1024. *
  1025. */
  1026. BMI160_RETURN_FUNCTION_TYPE bmi160_read_mag_xyzr(
  1027. struct bmi160_mag_xyzr_t *mag)
  1028. {
  1029. /* variable used to return the status of communication result*/
  1030. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1031. u8 v_data_u8[BMI160_MAG_XYZR_DATA_SIZE] = {
  1032. BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  1033. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  1034. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  1035. /* check the p_bmi160 structure for NULL pointer assignment*/
  1036. if (p_bmi160 == BMI160_NULL) {
  1037. return E_BMI160_NULL_PTR;
  1038. } else {
  1039. com_rslt =
  1040. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1041. BMI160_USER_DATA_MAG_X_LSB__REG,
  1042. v_data_u8, BMI160_MAG_XYZR_DATA_LENGTH);
  1043. /* Data X */
  1044. /*X-axis LSB value shifting*/
  1045. v_data_u8[BMI160_DATA_FRAME_MAG_X_LSB_BYTE]
  1046. = BMI160_GET_BITSLICE(
  1047. v_data_u8[BMI160_DATA_FRAME_MAG_X_LSB_BYTE],
  1048. BMI160_USER_DATA_MAG_X_LSB);
  1049. mag->x = (s16)
  1050. ((((s32)((s8)v_data_u8[
  1051. BMI160_DATA_FRAME_MAG_X_MSB_BYTE]))
  1052. << BMI160_SHIFT_BIT_POSITION_BY_05_BITS)
  1053. | (v_data_u8[BMI160_DATA_FRAME_MAG_X_LSB_BYTE]));
  1054. /* Data Y */
  1055. /*Y-axis LSB value shifting*/
  1056. v_data_u8[BMI160_DATA_FRAME_MAG_Y_LSB_BYTE]
  1057. = BMI160_GET_BITSLICE(
  1058. v_data_u8[BMI160_DATA_FRAME_MAG_Y_LSB_BYTE],
  1059. BMI160_USER_DATA_MAG_Y_LSB);
  1060. mag->y = (s16)
  1061. ((((s32)((s8)v_data_u8[
  1062. BMI160_DATA_FRAME_MAG_Y_MSB_BYTE]))
  1063. << BMI160_SHIFT_BIT_POSITION_BY_05_BITS)
  1064. | (v_data_u8[
  1065. BMI160_DATA_FRAME_MAG_Y_LSB_BYTE]));
  1066. /* Data Z */
  1067. /*Z-axis LSB value shifting*/
  1068. v_data_u8[BMI160_DATA_FRAME_MAG_Z_LSB_BYTE]
  1069. = BMI160_GET_BITSLICE(
  1070. v_data_u8[BMI160_DATA_FRAME_MAG_Z_LSB_BYTE],
  1071. BMI160_USER_DATA_MAG_Z_LSB);
  1072. mag->z = (s16)
  1073. ((((s32)((s8)v_data_u8[
  1074. BMI160_DATA_FRAME_MAG_Z_MSB_BYTE]))
  1075. << BMI160_SHIFT_BIT_POSITION_BY_07_BITS)
  1076. | (v_data_u8[BMI160_DATA_FRAME_MAG_Z_LSB_BYTE]));
  1077. /* RHall */
  1078. /*R-axis LSB value shifting*/
  1079. v_data_u8[BMI160_DATA_FRAME_MAG_R_LSB_BYTE]
  1080. = BMI160_GET_BITSLICE(
  1081. v_data_u8[BMI160_DATA_FRAME_MAG_R_LSB_BYTE],
  1082. BMI160_USER_DATA_MAG_R_LSB);
  1083. mag->r = (s16)
  1084. ((((s32)((s8)v_data_u8[
  1085. BMI160_DATA_FRAME_MAG_R_MSB_BYTE]))
  1086. << BMI160_SHIFT_BIT_POSITION_BY_06_BITS)
  1087. | (v_data_u8[BMI160_DATA_FRAME_MAG_R_LSB_BYTE]));
  1088. }
  1089. return com_rslt;
  1090. }
  1091. /*!
  1092. * @brief This API reads gyro data X values
  1093. * from the register 0x0C and 0x0D.
  1094. *
  1095. * @param v_gyro_x_s16 : The value of gyro x data.
  1096. *
  1097. * @note Gyro configuration use the following functions.
  1098. * @note bmi160_set_gyro_output_data_rate()
  1099. * @note bmi160_set_gyro_bw()
  1100. * @note bmi160_set_gyro_range()
  1101. *
  1102. * @return results of bus communication function.
  1103. * @retval 0 -> Success
  1104. * @retval -1 -> Error
  1105. *
  1106. */
  1107. BMI160_RETURN_FUNCTION_TYPE bmi160_read_gyro_x(s16 *v_gyro_x_s16)
  1108. {
  1109. /* variable used to return the status of communication result*/
  1110. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1111. /* Array contains the gyro X LSB and MSB data
  1112. v_data_u8[0] - LSB
  1113. v_data_u8[MSB_ONE] - MSB*/
  1114. u8 v_data_u8[BMI160_GYRO_X_DATA_SIZE] = {BMI160_INIT_VALUE,
  1115. BMI160_INIT_VALUE};
  1116. /* check the p_bmi160 structure for NULL pointer assignment*/
  1117. if (p_bmi160 == BMI160_NULL) {
  1118. return E_BMI160_NULL_PTR;
  1119. } else {
  1120. com_rslt =
  1121. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1122. BMI160_USER_DATA_8_GYRO_X_LSB__REG,
  1123. v_data_u8, BMI160_GYRO_DATA_LENGTH);
  1124. *v_gyro_x_s16 = (s16)
  1125. ((((s32)((s8)v_data_u8[BMI160_GYRO_X_MSB_BYTE]))
  1126. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1127. | (v_data_u8[BMI160_GYRO_X_LSB_BYTE]));
  1128. }
  1129. return com_rslt;
  1130. }
  1131. /*!
  1132. * @brief This API reads gyro data Y values
  1133. * from the register 0x0E and 0x0F.
  1134. *
  1135. * @param v_gyro_y_s16 : The value of gyro y data.
  1136. *
  1137. * @note Gyro configuration use the following function
  1138. * @note bmi160_set_gyro_output_data_rate()
  1139. * @note bmi160_set_gyro_bw()
  1140. * @note bmi160_set_gyro_range()
  1141. *
  1142. * @return results of bus communication function.
  1143. * @retval 0 -> Success
  1144. * @retval -1 -> Error result of communication routines
  1145. *
  1146. */
  1147. BMI160_RETURN_FUNCTION_TYPE bmi160_read_gyro_y(s16 *v_gyro_y_s16)
  1148. {
  1149. /* variable used to return the status of communication result*/
  1150. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1151. /* Array contains the gyro Y LSB and MSB data
  1152. v_data_u8[LSB_ZERO] - LSB
  1153. v_data_u8[MSB_ONE] - MSB*/
  1154. u8 v_data_u8[BMI160_GYRO_Y_DATA_SIZE] = {BMI160_INIT_VALUE,
  1155. BMI160_INIT_VALUE};
  1156. /* check the p_bmi160 structure for NULL pointer assignment*/
  1157. if (p_bmi160 == BMI160_NULL) {
  1158. return E_BMI160_NULL_PTR;
  1159. } else {
  1160. /* read gyro y data*/
  1161. com_rslt =
  1162. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1163. BMI160_USER_DATA_10_GYRO_Y_LSB__REG,
  1164. v_data_u8, BMI160_GYRO_DATA_LENGTH);
  1165. *v_gyro_y_s16 = (s16)
  1166. ((((s32)((s8)v_data_u8[BMI160_GYRO_Y_MSB_BYTE]))
  1167. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1168. | (v_data_u8[BMI160_GYRO_Y_LSB_BYTE]));
  1169. }
  1170. return com_rslt;
  1171. }
  1172. /*!
  1173. * @brief This API reads gyro data Z values
  1174. * from the register 0x10 and 0x11.
  1175. *
  1176. * @param v_gyro_z_s16 : The value of gyro z data.
  1177. *
  1178. * @note Gyro configuration use the following functions.
  1179. * @note bmi160_set_gyro_output_data_rate()
  1180. * @note bmi160_set_gyro_bw()
  1181. * @note bmi160_set_gyro_range()
  1182. *
  1183. * @return results of the bus communication function
  1184. * @retval 0 -> Success
  1185. * @retval -1 -> Error
  1186. *
  1187. */
  1188. BMI160_RETURN_FUNCTION_TYPE bmi160_read_gyro_z(s16 *v_gyro_z_s16)
  1189. {
  1190. /* variable used to return the status of communication result*/
  1191. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1192. /* Array contains the gyro Z LSB and MSB data
  1193. v_data_u8[LSB_ZERO] - LSB
  1194. v_data_u8[MSB_ONE] - MSB*/
  1195. u8 v_data_u8[BMI160_GYRO_Z_DATA_SIZE] = {BMI160_INIT_VALUE,
  1196. BMI160_INIT_VALUE};
  1197. /* check the p_bmi160 structure for NULL pointer assignment*/
  1198. if (p_bmi160 == BMI160_NULL) {
  1199. return E_BMI160_NULL_PTR;
  1200. } else {
  1201. /* read gyro z data */
  1202. com_rslt =
  1203. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1204. BMI160_USER_DATA_12_GYRO_Z_LSB__REG,
  1205. v_data_u8, BMI160_GYRO_DATA_LENGTH);
  1206. *v_gyro_z_s16 = (s16)
  1207. ((((s32)((s8)v_data_u8[BMI160_GYRO_Z_MSB_BYTE]))
  1208. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1209. | (v_data_u8[BMI160_GYRO_Z_LSB_BYTE]));
  1210. }
  1211. return com_rslt;
  1212. }
  1213. /*!
  1214. * @brief This API reads gyro data X,Y,Z values
  1215. * from the register 0x0C to 0x11.
  1216. *
  1217. * @param gyro : The value of gyro xyz.
  1218. *
  1219. * @note Gyro configuration use the following functions.
  1220. * @note bmi160_set_gyro_output_data_rate()
  1221. * @note bmi160_set_gyro_bw()
  1222. * @note bmi160_set_gyro_range()
  1223. *
  1224. * @return results of bus communication function
  1225. * @retval 0 -> Success
  1226. * @retval -1 -> Error
  1227. *
  1228. */
  1229. BMI160_RETURN_FUNCTION_TYPE bmi160_read_gyro_xyz(struct bmi160_gyro_t *gyro)
  1230. {
  1231. /* variable used to return the status of communication result*/
  1232. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1233. /* Array contains the Mag XYZ LSB and MSB data
  1234. v_data_u8[0] - X-LSB
  1235. v_data_u8[1] - X-MSB
  1236. v_data_u8[0] - Y-LSB
  1237. v_data_u8[1] - Y-MSB
  1238. v_data_u8[0] - Z-LSB
  1239. v_data_u8[1] - Z-MSB
  1240. */
  1241. u8 v_data_u8[BMI160_GYRO_XYZ_DATA_SIZE] = {
  1242. BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  1243. BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  1244. BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  1245. /* check the p_bmi160 structure for NULL pointer assignment*/
  1246. if (p_bmi160 == BMI160_NULL) {
  1247. return E_BMI160_NULL_PTR;
  1248. } else {
  1249. /* read the gyro xyz data*/
  1250. com_rslt =
  1251. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1252. BMI160_USER_DATA_8_GYRO_X_LSB__REG,
  1253. v_data_u8, BMI160_GYRO_XYZ_DATA_LENGTH);
  1254. /* Data X */
  1255. gyro->x = (s16)
  1256. ((((s32)((s8)v_data_u8[
  1257. BMI160_DATA_FRAME_GYRO_X_MSB_BYTE]))
  1258. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1259. | (v_data_u8[BMI160_DATA_FRAME_GYRO_X_LSB_BYTE]));
  1260. /* Data Y */
  1261. gyro->y = (s16)
  1262. ((((s32)((s8)v_data_u8[
  1263. BMI160_DATA_FRAME_GYRO_Y_MSB_BYTE]))
  1264. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1265. | (v_data_u8[BMI160_DATA_FRAME_GYRO_Y_LSB_BYTE]));
  1266. /* Data Z */
  1267. gyro->z = (s16)
  1268. ((((s32)((s8)v_data_u8[
  1269. BMI160_DATA_FRAME_GYRO_Z_MSB_BYTE]))
  1270. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1271. | (v_data_u8[BMI160_DATA_FRAME_GYRO_Z_LSB_BYTE]));
  1272. }
  1273. return com_rslt;
  1274. }
  1275. /*!
  1276. * @brief This API reads the Accel data for X axis
  1277. * from the register 0x12 and 0x13.
  1278. *
  1279. * @param v_accel_x_s16 : The value of Accel x axis.
  1280. *
  1281. * @note For Accel configuration use the following functions.
  1282. * @note bmi160_set_accel_output_data_rate()
  1283. * @note bmi160_set_accel_bw()
  1284. * @note bmi160_set_accel_under_sampling_parameter()
  1285. * @note bmi160_set_accel_range()
  1286. *
  1287. * @return results of bus communication function
  1288. * @retval 0 -> Success
  1289. * @retval -1 -> Error
  1290. *
  1291. */
  1292. BMI160_RETURN_FUNCTION_TYPE bmi160_read_accel_x(s16 *v_accel_x_s16)
  1293. {
  1294. /* variable used to return the status of communication result*/
  1295. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1296. /* Array contains the Accel X LSB and MSB data
  1297. v_data_u8[0] - LSB
  1298. v_data_u8[1] - MSB*/
  1299. u8 v_data_u8[BMI160_ACCEL_X_DATA_SIZE] = {BMI160_INIT_VALUE,
  1300. BMI160_INIT_VALUE};
  1301. /* check the p_bmi160 structure for NULL pointer assignment*/
  1302. if (p_bmi160 == BMI160_NULL) {
  1303. return E_BMI160_NULL_PTR;
  1304. } else {
  1305. com_rslt =
  1306. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1307. BMI160_USER_DATA_14_ACCEL_X_LSB__REG,
  1308. v_data_u8, BMI160_ACCEL_DATA_LENGTH);
  1309. *v_accel_x_s16 = (s16)
  1310. ((((s32)((s8)v_data_u8[BMI160_ACCEL_X_MSB_BYTE]))
  1311. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1312. | (v_data_u8[BMI160_ACCEL_X_LSB_BYTE]));
  1313. }
  1314. return com_rslt;
  1315. }
  1316. /*!
  1317. * @brief This API reads Accel data for Y axis
  1318. * from the register 0x14 and 0x15.
  1319. *
  1320. * @param v_accel_y_s16 : The value of Accel y axis.
  1321. *
  1322. * @note For Accel configuration use the following functions.
  1323. * @note bmi160_set_accel_output_data_rate()
  1324. * @note bmi160_set_accel_bw()
  1325. * @note bmi160_set_accel_under_sampling_parameter()
  1326. * @note bmi160_set_accel_range()
  1327. *
  1328. * @return results of bus communication function
  1329. * @retval 0 -> Success
  1330. * @retval -1 -> Error
  1331. *
  1332. */
  1333. BMI160_RETURN_FUNCTION_TYPE bmi160_read_accel_y(s16 *v_accel_y_s16)
  1334. {
  1335. /* variable used to return the status of communication result*/
  1336. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1337. /* Array contains the Accel Y LSB and MSB data
  1338. v_data_u8[0] - LSB
  1339. v_data_u8[1] - MSB*/
  1340. u8 v_data_u8[BMI160_ACCEL_Y_DATA_SIZE] = {BMI160_INIT_VALUE,
  1341. BMI160_INIT_VALUE};
  1342. /* check the p_bmi160 structure for NULL pointer assignment*/
  1343. if (p_bmi160 == BMI160_NULL) {
  1344. return E_BMI160_NULL_PTR;
  1345. } else {
  1346. com_rslt =
  1347. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1348. BMI160_USER_DATA_16_ACCEL_Y_LSB__REG,
  1349. v_data_u8, BMI160_ACCEL_DATA_LENGTH);
  1350. *v_accel_y_s16 = (s16)
  1351. ((((s32)((s8)v_data_u8[BMI160_ACCEL_Y_MSB_BYTE]))
  1352. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1353. | (v_data_u8[BMI160_ACCEL_Y_LSB_BYTE]));
  1354. }
  1355. return com_rslt;
  1356. }
  1357. /*!
  1358. * @brief This API reads Accel data Z values
  1359. * from the register 0x16 and 0x17.
  1360. *
  1361. * @param v_accel_z_s16 : The value of Accel z axis.
  1362. *
  1363. * @note For Accel configuration use the following functions.
  1364. * @note bmi160_set_accel_output_data_rate()
  1365. * @note bmi160_set_accel_bw()
  1366. * @note bmi160_set_accel_under_sampling_parameter()
  1367. * @note bmi160_set_accel_range()
  1368. *
  1369. * @return results of bus communication function
  1370. * @retval 0 -> Success
  1371. * @retval -1 -> Error
  1372. *
  1373. */
  1374. BMI160_RETURN_FUNCTION_TYPE bmi160_read_accel_z(s16 *v_accel_z_s16)
  1375. {
  1376. /* variable used to return the status of communication result*/
  1377. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1378. /* Array contains the Accel Z LSB and MSB data
  1379. a_data_u8r[LSB_ZERO] - LSB
  1380. a_data_u8r[MSB_ONE] - MSB*/
  1381. u8 a_data_u8r[BMI160_ACCEL_Z_DATA_SIZE] = {
  1382. BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  1383. /* check the p_bmi160 structure for NULL pointer assignment*/
  1384. if (p_bmi160 == BMI160_NULL) {
  1385. return E_BMI160_NULL_PTR;
  1386. } else {
  1387. com_rslt =
  1388. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1389. BMI160_USER_DATA_18_ACCEL_Z_LSB__REG,
  1390. a_data_u8r, BMI160_ACCEL_DATA_LENGTH);
  1391. *v_accel_z_s16 = (s16)
  1392. ((((s32)((s8)a_data_u8r[BMI160_ACCEL_Z_MSB_BYTE]))
  1393. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1394. | (a_data_u8r[BMI160_ACCEL_Z_LSB_BYTE]));
  1395. }
  1396. return com_rslt;
  1397. }
  1398. /*!
  1399. * @brief This API reads Accel data X,Y,Z values
  1400. * from the register 0x12 to 0x17.
  1401. *
  1402. * @param Accel :The value of Accel xyz axis.
  1403. *
  1404. * @note For Accel configuration use the following functions.
  1405. * @note bmi160_set_accel_output_data_rate()
  1406. * @note bmi160_set_accel_bw()
  1407. * @note bmi160_set_accel_under_sampling_parameter()
  1408. * @note bmi160_set_accel_range()
  1409. *
  1410. * @return results of bus communication function
  1411. * @retval 0 -> Success
  1412. * @retval -1 -> Error
  1413. *
  1414. */
  1415. BMI160_RETURN_FUNCTION_TYPE bmi160_read_accel_xyz(
  1416. struct bmi160_accel_t *accel)
  1417. {
  1418. /* variable used to return the status of communication result*/
  1419. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1420. /* Array contains the Accel XYZ LSB and MSB data
  1421. a_data_u8r[0] - X-LSB
  1422. a_data_u8r[1] - X-MSB
  1423. a_data_u8r[0] - Y-LSB
  1424. a_data_u8r[1] - Y-MSB
  1425. a_data_u8r[0] - Z-LSB
  1426. a_data_u8r[1] - Z-MSB
  1427. */
  1428. u8 a_data_u8r[BMI160_ACCEL_XYZ_DATA_SIZE] = {
  1429. BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  1430. BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  1431. BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  1432. /* check the p_bmi160 structure for NULL pointer assignment*/
  1433. if (p_bmi160 == BMI160_NULL) {
  1434. return E_BMI160_NULL_PTR;
  1435. } else {
  1436. com_rslt =
  1437. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1438. BMI160_USER_DATA_14_ACCEL_X_LSB__REG,
  1439. a_data_u8r, BMI160_ACCEL_XYZ_DATA_LENGTH);
  1440. /* Data X */
  1441. accel->x = (s16)
  1442. ((((s32)((s8)a_data_u8r[
  1443. BMI160_DATA_FRAME_ACCEL_X_MSB_BYTE]))
  1444. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1445. | (a_data_u8r[BMI160_DATA_FRAME_ACCEL_X_LSB_BYTE]));
  1446. /* Data Y */
  1447. accel->y = (s16)
  1448. ((((s32)((s8)a_data_u8r[
  1449. BMI160_DATA_FRAME_ACCEL_Y_MSB_BYTE]))
  1450. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1451. | (a_data_u8r[BMI160_DATA_FRAME_ACCEL_Y_LSB_BYTE]));
  1452. /* Data Z */
  1453. accel->z = (s16)
  1454. ((((s32)((s8)a_data_u8r[
  1455. BMI160_DATA_FRAME_ACCEL_Z_MSB_BYTE]))
  1456. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1457. | (a_data_u8r[BMI160_DATA_FRAME_ACCEL_Z_LSB_BYTE]));
  1458. }
  1459. return com_rslt;
  1460. }
  1461. /*!
  1462. * @brief This API reads sensor_time from the register
  1463. * 0x18 to 0x1A.
  1464. *
  1465. * @param v_sensor_time_u32 : The value of sensor time.
  1466. *
  1467. * @return results of bus communication function
  1468. * @retval 0 -> Success
  1469. * @retval -1 -> Error
  1470. *
  1471. */
  1472. BMI160_RETURN_FUNCTION_TYPE bmi160_get_sensor_time(u32 *v_sensor_time_u32)
  1473. {
  1474. /* variable used to return the status of communication result*/
  1475. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1476. /* Array contains the sensor time it is 32 bit data
  1477. a_data_u8r[0] - sensor time
  1478. a_data_u8r[1] - sensor time
  1479. a_data_u8r[0] - sensor time
  1480. */
  1481. u8 a_data_u8r[BMI160_SENSOR_TIME_DATA_SIZE] = {BMI160_INIT_VALUE,
  1482. BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  1483. /* check the p_bmi160 structure for NULL pointer assignment*/
  1484. if (p_bmi160 == BMI160_NULL) {
  1485. return E_BMI160_NULL_PTR;
  1486. } else {
  1487. com_rslt =
  1488. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1489. BMI160_USER_SENSORTIME_0_SENSOR_TIME_LSB__REG,
  1490. a_data_u8r, BMI160_SENSOR_TIME_LENGTH);
  1491. *v_sensor_time_u32 = (u32)
  1492. ((((u32)a_data_u8r[BMI160_SENSOR_TIME_MSB_BYTE])
  1493. << BMI160_SHIFT_BIT_POSITION_BY_16_BITS)
  1494. |(((u32)a_data_u8r[BMI160_SENSOR_TIME_XLSB_BYTE])
  1495. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1496. | (a_data_u8r[BMI160_SENSOR_TIME_LSB_BYTE]));
  1497. }
  1498. return com_rslt;
  1499. }
  1500. /*!
  1501. * @brief This API reads sensor_time, Accel data, gyro data from the
  1502. * register 0x0C to 0x1A.
  1503. *
  1504. * @param accel_gyro_sensortime_select : to select the configuration
  1505. * value | output
  1506. * ---------|----------------
  1507. * 0 | Accel data and Sensor time
  1508. * 1 | Accel data ,Gyro data and Sensor time
  1509. *
  1510. * @param accel_gyro_sensor_time : the value of Accel data, gyro data and
  1511. * sensor time data
  1512. *
  1513. * @return results of bus communication function
  1514. * @retval 0 -> Success
  1515. * @retval -1 -> Error
  1516. *
  1517. */
  1518. BMI160_RETURN_FUNCTION_TYPE bmi160_read_accel_gyro_sensor_time(
  1519. u8 accel_gyro_sensortime_select,
  1520. struct bmi160_sensortime_accel_gyro_data *accel_gyro_sensor_time)
  1521. {
  1522. u8 a_data_u8r[BMI160_GYRO_ACCEL_SENSORTIME_DATA_SIZE];
  1523. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1524. switch (accel_gyro_sensortime_select) {
  1525. case BMI160_ACCEL_SENSORTIME_DATA:
  1526. com_rslt = p_bmi160->BMI160_BURST_READ_FUNC(
  1527. p_bmi160->dev_addr,
  1528. BMI160_USER_DATA_14_ACCEL_X_LSB__REG, a_data_u8r,
  1529. BMI160_ACCEL_SENSORTIME_DATA_SIZE);
  1530. /* Accel Data X */
  1531. accel_gyro_sensor_time->accel.x = (s16)((((s32)
  1532. ((s8)a_data_u8r[BMI160_DATA_FRAME_ACCEL_X_MSB_BYTE]))
  1533. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1534. | (a_data_u8r[BMI160_DATA_FRAME_ACCEL_X_LSB_BYTE]));
  1535. /* Accel Data Y */
  1536. accel_gyro_sensor_time->accel.y = (s16)((((s32)
  1537. ((s8)a_data_u8r[BMI160_DATA_FRAME_ACCEL_Y_MSB_BYTE]))
  1538. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1539. | (a_data_u8r[BMI160_DATA_FRAME_ACCEL_Y_LSB_BYTE]));
  1540. /* Accel Data Z */
  1541. accel_gyro_sensor_time->accel.z = (s16)((((s32)
  1542. ((s8)a_data_u8r[BMI160_DATA_FRAME_ACCEL_Z_MSB_BYTE]))
  1543. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1544. | (a_data_u8r[BMI160_DATA_FRAME_ACCEL_Z_LSB_BYTE]));
  1545. /* Sensor time data */
  1546. accel_gyro_sensor_time->v_sensor_time_u32 = (u32)((
  1547. ((u32)a_data_u8r[BMI160_DATA_FRAME_ACCEL_Z_MSB_BYTE+3])
  1548. << BMI160_SHIFT_BIT_POSITION_BY_16_BITS)|
  1549. (((u32)a_data_u8r[BMI160_DATA_FRAME_ACCEL_Z_MSB_BYTE+2])
  1550. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1551. | (a_data_u8r[BMI160_DATA_FRAME_ACCEL_Z_MSB_BYTE+1]));
  1552. break;
  1553. case BMI160_GYRO_ACCEL_SENSORTIME_DATA:
  1554. com_rslt = p_bmi160->BMI160_BURST_READ_FUNC(
  1555. p_bmi160->dev_addr,
  1556. BMI160_USER_DATA_8_GYRO_X_LSB__REG, a_data_u8r,
  1557. BMI160_GYRO_ACCEL_SENSORTIME_DATA_SIZE);
  1558. /* Gyro Data X */
  1559. accel_gyro_sensor_time->gyro.x = (s16)((((s32)((s8)
  1560. a_data_u8r[BMI160_DATA_FRAME_GYRO_X_MSB_BYTE]))
  1561. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1562. | (a_data_u8r[BMI160_DATA_FRAME_GYRO_X_LSB_BYTE]));
  1563. /* Gyro Data Y */
  1564. accel_gyro_sensor_time->gyro.y = (s16)((((s32)
  1565. ((s8)a_data_u8r[BMI160_DATA_FRAME_GYRO_Y_MSB_BYTE]))
  1566. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1567. | (a_data_u8r[BMI160_DATA_FRAME_GYRO_Y_LSB_BYTE]));
  1568. /* Gyro Data Z */
  1569. accel_gyro_sensor_time->gyro.z = (s16)((((s32)
  1570. ((s8)a_data_u8r[BMI160_DATA_FRAME_GYRO_Z_MSB_BYTE]))
  1571. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1572. | (a_data_u8r[BMI160_DATA_FRAME_GYRO_Z_LSB_BYTE]));
  1573. /* Accel Data X */
  1574. accel_gyro_sensor_time->accel.x = (s16)((((s32)
  1575. ((s8)a_data_u8r[BMI160_DATA_FRAME_GYRO_Z_MSB_BYTE+2]))
  1576. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1577. | (a_data_u8r[BMI160_DATA_FRAME_GYRO_Z_MSB_BYTE+1]));
  1578. /* Accel Data Y */
  1579. accel_gyro_sensor_time->accel.y = (s16)((((s32)
  1580. ((s8)a_data_u8r[BMI160_DATA_FRAME_GYRO_Z_MSB_BYTE+4]))
  1581. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1582. | (a_data_u8r[BMI160_DATA_FRAME_GYRO_Z_MSB_BYTE+3]));
  1583. /* Accel Data Z */
  1584. accel_gyro_sensor_time->accel.z = (s16)((((s32)
  1585. ((s8)a_data_u8r[BMI160_DATA_FRAME_GYRO_Z_MSB_BYTE+6]))
  1586. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1587. | (a_data_u8r[BMI160_DATA_FRAME_GYRO_Z_MSB_BYTE+5]));
  1588. /* Sensor time data */
  1589. accel_gyro_sensor_time->v_sensor_time_u32 = (u32)
  1590. ((((u32)a_data_u8r[BMI160_DATA_FRAME_GYRO_Z_MSB_BYTE+9])
  1591. << BMI160_SHIFT_BIT_POSITION_BY_16_BITS)
  1592. |(((u32)a_data_u8r[BMI160_DATA_FRAME_GYRO_Z_MSB_BYTE+8])
  1593. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  1594. | (a_data_u8r[BMI160_DATA_FRAME_GYRO_Z_MSB_BYTE+7]));
  1595. break;
  1596. }
  1597. return com_rslt;
  1598. }
  1599. /*!
  1600. * @brief This API reads the Gyro self test
  1601. * status from the register 0x1B bit 1
  1602. *
  1603. * @param v_gyro_selftest_u8 : The value of gyro self test status
  1604. * value | status
  1605. * ---------|----------------
  1606. * 0 | Gyro self test is running or failed
  1607. * 1 | Gyro self test completed successfully
  1608. *
  1609. * @return results of bus communication function
  1610. * @retval 0 -> Success
  1611. * @retval -1 -> Error
  1612. *
  1613. */
  1614. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_selftest(u8
  1615. *v_gyro_selftest_u8)
  1616. {
  1617. /* variable used to return the status of communication result*/
  1618. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1619. u8 v_data_u8 = BMI160_INIT_VALUE;
  1620. /* check the p_bmi160 structure for NULL pointer assignment*/
  1621. if (p_bmi160 == BMI160_NULL) {
  1622. return E_BMI160_NULL_PTR;
  1623. } else {
  1624. com_rslt =
  1625. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1626. BMI160_USER_STAT_GYRO_SELFTEST_OK__REG,
  1627. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  1628. *v_gyro_selftest_u8 = BMI160_GET_BITSLICE(v_data_u8,
  1629. BMI160_USER_STAT_GYRO_SELFTEST_OK);
  1630. }
  1631. return com_rslt;
  1632. }
  1633. /*!
  1634. * @brief This API reads the status of
  1635. * mag manual interface operation from the register 0x1B bit 2.
  1636. *
  1637. * @param v_mag_manual_stat_u8 : The value of Mag manual operation status
  1638. * value | status
  1639. * ---------|----------------
  1640. * 0 | Indicates no manual Mag
  1641. * - | interface operation is ongoing
  1642. * 1 | Indicates manual Mag
  1643. * - | interface operation is ongoing
  1644. *
  1645. * @return results of bus communication function
  1646. * @retval 0 -> Success
  1647. * @retval -1 -> Error
  1648. *
  1649. */
  1650. BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_manual_operation_stat(u8
  1651. *v_mag_manual_stat_u8)
  1652. {
  1653. /* variable used to return the status of communication result*/
  1654. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1655. u8 v_data_u8 = BMI160_INIT_VALUE;
  1656. /* check the p_bmi160 structure for NULL pointer assignment*/
  1657. if (p_bmi160 == BMI160_NULL) {
  1658. return E_BMI160_NULL_PTR;
  1659. } else {
  1660. /* read manual operation*/
  1661. com_rslt =
  1662. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1663. BMI160_USER_STAT_MAG_MANUAL_OPERATION__REG,
  1664. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  1665. *v_mag_manual_stat_u8 = BMI160_GET_BITSLICE(v_data_u8,
  1666. BMI160_USER_STAT_MAG_MANUAL_OPERATION);
  1667. }
  1668. return com_rslt;
  1669. }
  1670. /*!
  1671. * @brief This API reads the fast offset compensation
  1672. * status from the register 0x1B bit 3
  1673. *
  1674. *
  1675. * @param v_foc_rdy_u8 : The status of fast compensation
  1676. *
  1677. *
  1678. *
  1679. * @return results of bus communication function
  1680. * @retval 0 -> Success
  1681. * @retval -1 -> Error
  1682. *
  1683. *
  1684. */
  1685. BMI160_RETURN_FUNCTION_TYPE bmi160_get_foc_rdy(u8
  1686. *v_foc_rdy_u8)
  1687. {
  1688. /* variable used to return the status of communication result*/
  1689. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1690. u8 v_data_u8 = BMI160_INIT_VALUE;
  1691. /* check the p_bmi160 structure for NULL pointer assignment*/
  1692. if (p_bmi160 == BMI160_NULL) {
  1693. return E_BMI160_NULL_PTR;
  1694. } else {
  1695. /* read the FOC status*/
  1696. com_rslt =
  1697. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1698. BMI160_USER_STAT_FOC_RDY__REG,
  1699. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  1700. *v_foc_rdy_u8 = BMI160_GET_BITSLICE(v_data_u8,
  1701. BMI160_USER_STAT_FOC_RDY);
  1702. }
  1703. return com_rslt;
  1704. }
  1705. /*!
  1706. * @brief This API reads the status of Mag data ready
  1707. * from the register 0x1B bit 5
  1708. * The status get reset when one Mag data register is read out
  1709. *
  1710. * @param v_data_rdy_u8 : The value of Mag data ready status
  1711. *
  1712. *
  1713. *
  1714. * @return results of bus communication function
  1715. * @retval 0 -> Success
  1716. * @retval -1 -> Error
  1717. *
  1718. *
  1719. */
  1720. BMI160_RETURN_FUNCTION_TYPE bmi160_get_data_rdy_mag(u8
  1721. *v_data_rdy_u8)
  1722. {
  1723. /* variable used to return the status of communication result*/
  1724. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1725. u8 v_data_u8 = BMI160_INIT_VALUE;
  1726. /* check the p_bmi160 structure for NULL pointer assignment*/
  1727. if (p_bmi160 == BMI160_NULL) {
  1728. return E_BMI160_NULL_PTR;
  1729. } else {
  1730. com_rslt =
  1731. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1732. BMI160_USER_STAT_DATA_RDY_MAG__REG, &v_data_u8,
  1733. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  1734. *v_data_rdy_u8 = BMI160_GET_BITSLICE(v_data_u8,
  1735. BMI160_USER_STAT_DATA_RDY_MAG);
  1736. }
  1737. return com_rslt;
  1738. }
  1739. /*!
  1740. * @brief This API reads the status of gyro data ready from the
  1741. * register 0x1B bit 6
  1742. * The status get reset when gyro data register read out
  1743. *
  1744. *
  1745. * @param v_data_rdy_u8 : The value of gyro data ready
  1746. *
  1747. *
  1748. *
  1749. * @return results of bus communication function
  1750. * @retval 0 -> Success
  1751. * @retval -1 -> Error
  1752. *
  1753. *
  1754. */
  1755. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_data_rdy(u8
  1756. *v_data_rdy_u8)
  1757. {
  1758. /* variable used to return the status of communication result*/
  1759. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1760. u8 v_data_u8 = BMI160_INIT_VALUE;
  1761. /* check the p_bmi160 structure for NULL pointer assignment*/
  1762. if (p_bmi160 == BMI160_NULL) {
  1763. return E_BMI160_NULL_PTR;
  1764. } else {
  1765. com_rslt =
  1766. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1767. BMI160_USER_STAT_DATA_RDY_GYRO__REG, &v_data_u8,
  1768. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  1769. *v_data_rdy_u8 = BMI160_GET_BITSLICE(v_data_u8,
  1770. BMI160_USER_STAT_DATA_RDY_GYRO);
  1771. }
  1772. return com_rslt;
  1773. }
  1774. /*!
  1775. * @brief This API reads the status of Accel data ready from the
  1776. * register 0x1B bit 7
  1777. * The status get reset when Accel data register is read
  1778. *
  1779. *
  1780. * @param v_data_rdy_u8 : The value of Accel data ready status
  1781. *
  1782. *
  1783. *
  1784. * @return results of bus communication function
  1785. * @retval 0 -> Success
  1786. * @retval -1 -> Error
  1787. *
  1788. *
  1789. */
  1790. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_data_rdy(u8
  1791. *v_data_rdy_u8)
  1792. {
  1793. /* variable used to return the status of communication result*/
  1794. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1795. u8 v_data_u8 = BMI160_INIT_VALUE;
  1796. /* check the p_bmi160 structure for NULL pointer assignment*/
  1797. if (p_bmi160 == BMI160_NULL) {
  1798. return E_BMI160_NULL_PTR;
  1799. } else {
  1800. /*reads the status of Accel data ready*/
  1801. com_rslt =
  1802. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1803. BMI160_USER_STAT_DATA_RDY_ACCEL__REG, &v_data_u8,
  1804. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  1805. *v_data_rdy_u8 = BMI160_GET_BITSLICE(v_data_u8,
  1806. BMI160_USER_STAT_DATA_RDY_ACCEL);
  1807. }
  1808. return com_rslt;
  1809. }
  1810. /*!
  1811. * @brief This API reads the step detector interrupt status
  1812. * from the register 0x1C bit 0
  1813. * flag is associated with a specific interrupt function.
  1814. * It is set when the single tab interrupt triggers. The
  1815. * setting of INT_LATCH controls the interrupt
  1816. * signal and hence the
  1817. * respective interrupt flag will be
  1818. * permanently latched, temporarily latched
  1819. * or not latched.
  1820. *
  1821. *
  1822. *
  1823. *
  1824. * @param v_step_intr_u8 : The status of step detector interrupt
  1825. *
  1826. *
  1827. *
  1828. * @return results of bus communication function
  1829. * @retval 0 -> Success
  1830. * @retval -1 -> Error
  1831. *
  1832. *
  1833. */
  1834. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_step_intr(u8
  1835. *v_step_intr_u8)
  1836. {
  1837. /* variable used to return the status of communication result*/
  1838. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1839. u8 v_data_u8 = BMI160_INIT_VALUE;
  1840. /* check the p_bmi160 structure for NULL pointer assignment*/
  1841. if (p_bmi160 == BMI160_NULL) {
  1842. return E_BMI160_NULL_PTR;
  1843. } else {
  1844. com_rslt =
  1845. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1846. BMI160_USER_INTR_STAT_0_STEP_INTR__REG, &v_data_u8,
  1847. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  1848. *v_step_intr_u8 = BMI160_GET_BITSLICE(v_data_u8,
  1849. BMI160_USER_INTR_STAT_0_STEP_INTR);
  1850. }
  1851. return com_rslt;
  1852. }
  1853. /*!
  1854. * @brief This API reads the
  1855. * significant motion interrupt status
  1856. * from the register 0x1C bit 1
  1857. * flag is associated with a specific interrupt function.
  1858. * It is set when the single tab interrupt triggers. The
  1859. * setting of INT_LATCH controls the interrupt
  1860. * signal and hence the
  1861. * respective interrupt flag will be
  1862. * permanently latched, temporarily latched
  1863. * or not latched.
  1864. *
  1865. *
  1866. *
  1867. *
  1868. *
  1869. * @param v_significant_intr_u8 : The status of step
  1870. * motion interrupt
  1871. *
  1872. *
  1873. *
  1874. * @return results of bus communication function
  1875. * @retval 0 -> Success
  1876. * @retval -1 -> Error
  1877. *
  1878. *
  1879. */
  1880. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_significant_intr(u8
  1881. *v_significant_intr_u8)
  1882. {
  1883. /* variable used to return the status of communication result*/
  1884. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1885. u8 v_data_u8 = BMI160_INIT_VALUE;
  1886. /* check the p_bmi160 structure for NULL pointer assignment*/
  1887. if (p_bmi160 == BMI160_NULL) {
  1888. return E_BMI160_NULL_PTR;
  1889. } else {
  1890. com_rslt =
  1891. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1892. BMI160_USER_INTR_STAT_0_SIGNIFICANT_INTR__REG,
  1893. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  1894. *v_significant_intr_u8 = BMI160_GET_BITSLICE(v_data_u8,
  1895. BMI160_USER_INTR_STAT_0_SIGNIFICANT_INTR);
  1896. }
  1897. return com_rslt;
  1898. }
  1899. /*!
  1900. * @brief This API reads the any motion interrupt status
  1901. * from the register 0x1C bit 2
  1902. * flag is associated with a specific interrupt function.
  1903. * It is set when the single tab interrupt triggers. The
  1904. * setting of INT_LATCH controls the interrupt
  1905. * signal and hence the
  1906. * respective interrupt flag will be
  1907. * permanently latched, temporarily latched
  1908. * or not latched.
  1909. *
  1910. *
  1911. *
  1912. * @param v_any_motion_intr_u8 : The status of any-motion interrupt
  1913. *
  1914. *
  1915. *
  1916. * @return results of bus communication function
  1917. * @retval 0 -> Success
  1918. * @retval -1 -> Error
  1919. *
  1920. *
  1921. */
  1922. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_any_motion_intr(u8
  1923. *v_any_motion_intr_u8)
  1924. {
  1925. /* variable used to return the status of communication result*/
  1926. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1927. u8 v_data_u8 = BMI160_INIT_VALUE;
  1928. /* check the p_bmi160 structure for NULL pointer assignment*/
  1929. if (p_bmi160 == BMI160_NULL) {
  1930. return E_BMI160_NULL_PTR;
  1931. } else {
  1932. com_rslt =
  1933. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1934. BMI160_USER_INTR_STAT_0_ANY_MOTION__REG, &v_data_u8,
  1935. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  1936. *v_any_motion_intr_u8 = BMI160_GET_BITSLICE(v_data_u8,
  1937. BMI160_USER_INTR_STAT_0_ANY_MOTION);
  1938. }
  1939. return com_rslt;
  1940. }
  1941. /*!
  1942. * @brief This API reads the power mode trigger interrupt status
  1943. * from the register 0x1C bit 3
  1944. * flag is associated with a specific interrupt function.
  1945. * It is set when the single tab interrupt triggers. The
  1946. * setting of INT_LATCH controls the interrupt
  1947. * signal and hence the
  1948. * respective interrupt flag will be
  1949. * permanently latched, temporarily latched
  1950. * or not latched.
  1951. *
  1952. *
  1953. *
  1954. *
  1955. *
  1956. * @param v_pmu_trigger_intr_u8 : The status of power mode trigger interrupt
  1957. *
  1958. *
  1959. *
  1960. * @return results of bus communication function
  1961. * @retval 0 -> Success
  1962. * @retval -1 -> Error
  1963. *
  1964. *
  1965. */
  1966. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_pmu_trigger_intr(u8
  1967. *v_pmu_trigger_intr_u8)
  1968. {
  1969. /* variable used to return the status of communication result*/
  1970. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1971. u8 v_data_u8 = BMI160_INIT_VALUE;
  1972. /* check the p_bmi160 structure for NULL pointer assignment*/
  1973. if (p_bmi160 == BMI160_NULL) {
  1974. return E_BMI160_NULL_PTR;
  1975. } else {
  1976. com_rslt =
  1977. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1978. BMI160_USER_INTR_STAT_0_PMU_TRIGGER__REG,
  1979. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  1980. *v_pmu_trigger_intr_u8 = BMI160_GET_BITSLICE(v_data_u8,
  1981. BMI160_USER_INTR_STAT_0_PMU_TRIGGER);
  1982. }
  1983. return com_rslt;
  1984. }
  1985. /*!
  1986. * @brief This API reads the double tab status
  1987. * from the register 0x1C bit 4
  1988. * flag is associated with a specific interrupt function.
  1989. * It is set when the single tab interrupt triggers. The
  1990. * setting of INT_LATCH controls the interrupt
  1991. * signal and hence the
  1992. * respective interrupt flag will be
  1993. * permanently latched, temporarily latched
  1994. * or not latched.
  1995. *
  1996. *
  1997. *
  1998. *
  1999. * @param v_double_tap_intr_u8 :The status of double tab interrupt
  2000. *
  2001. * @note Double tap interrupt can be configured by the following functions
  2002. * @note INTERRUPT MAPPING
  2003. * @note bmi160_set_intr_double_tap()
  2004. * @note AXIS MAPPING
  2005. * @note bmi160_get_stat2_tap_first_x()
  2006. * @note bmi160_get_stat2_tap_first_y()
  2007. * @note bmi160_get_stat2_tap_first_z()
  2008. * @note DURATION
  2009. * @note bmi160_set_intr_tap_durn()
  2010. * @note THRESHOLD
  2011. * @note bmi160_set_intr_tap_thres()
  2012. * @note TAP QUIET
  2013. * @note bmi160_set_intr_tap_quiet()
  2014. * @note TAP SHOCK
  2015. * @note bmi160_set_intr_tap_shock()
  2016. * @note TAP SOURCE
  2017. * @note bmi160_set_intr_tap_source()
  2018. *
  2019. * @return results of bus communication function
  2020. * @retval 0 -> Success
  2021. * @retval -1 -> Error
  2022. *
  2023. *
  2024. */
  2025. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_double_tap_intr(u8
  2026. *v_double_tap_intr_u8)
  2027. {
  2028. /* variable used to return the status of communication result*/
  2029. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2030. u8 v_data_u8 = BMI160_INIT_VALUE;
  2031. /* check the p_bmi160 structure for NULL pointer assignment*/
  2032. if (p_bmi160 == BMI160_NULL) {
  2033. return E_BMI160_NULL_PTR;
  2034. } else {
  2035. com_rslt =
  2036. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2037. BMI160_USER_INTR_STAT_0_DOUBLE_TAP_INTR__REG,
  2038. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  2039. *v_double_tap_intr_u8 = BMI160_GET_BITSLICE(v_data_u8,
  2040. BMI160_USER_INTR_STAT_0_DOUBLE_TAP_INTR);
  2041. }
  2042. return com_rslt;
  2043. }
  2044. /*!
  2045. * @brief This API reads the single tab status
  2046. * from the register 0x1C bit 5
  2047. * flag is associated with a specific interrupt function.
  2048. * It is set when the single tab interrupt triggers. The
  2049. * setting of INT_LATCH controls the interrupt
  2050. * signal and hence the
  2051. * respective interrupt flag will be
  2052. * permanently latched, temporarily latched
  2053. * or not latched.
  2054. *
  2055. *
  2056. *
  2057. *
  2058. * @param v_single_tap_intr_u8 :The status of single tap interrupt
  2059. *
  2060. * @note Single tap interrupt can be configured by the following functions
  2061. * @note INTERRUPT MAPPING
  2062. * @note bmi160_set_intr_single_tap()
  2063. * @note AXIS MAPPING
  2064. * @note bmi160_get_stat2_tap_first_x()
  2065. * @note bmi160_get_stat2_tap_first_y()
  2066. * @note bmi160_get_stat2_tap_first_z()
  2067. * @note DURATION
  2068. * @note bmi160_set_intr_tap_durn()
  2069. * @note THRESHOLD
  2070. * @note bmi160_set_intr_tap_thres()
  2071. * @note TAP QUIET
  2072. * @note bmi160_set_intr_tap_quiet()
  2073. * @note TAP SHOCK
  2074. * @note bmi160_set_intr_tap_shock()
  2075. * @note TAP SOURCE
  2076. * @note bmi160_set_intr_tap_source()
  2077. *
  2078. * @return results of bus communication function
  2079. * @retval 0 -> Success
  2080. * @retval -1 -> Error
  2081. *
  2082. *
  2083. */
  2084. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_single_tap_intr(u8
  2085. *v_single_tap_intr_u8)
  2086. {
  2087. /* variable used to return the status of communication result*/
  2088. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2089. u8 v_data_u8 = BMI160_INIT_VALUE;
  2090. /* check the p_bmi160 structure for NULL pointer assignment*/
  2091. if (p_bmi160 == BMI160_NULL) {
  2092. return E_BMI160_NULL_PTR;
  2093. } else {
  2094. com_rslt =
  2095. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2096. BMI160_USER_INTR_STAT_0_SINGLE_TAP_INTR__REG,
  2097. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  2098. *v_single_tap_intr_u8 =
  2099. BMI160_GET_BITSLICE(v_data_u8,
  2100. BMI160_USER_INTR_STAT_0_SINGLE_TAP_INTR);
  2101. }
  2102. return com_rslt;
  2103. }
  2104. /*!
  2105. * @brief This API reads the orient status
  2106. * from the register 0x1C bit 6
  2107. * flag is associated with a specific interrupt function.
  2108. * It is set when the orient interrupt triggers. The
  2109. * setting of INT_LATCH controls the
  2110. * interrupt signal and hence the
  2111. * respective interrupt flag will be
  2112. * permanently latched, temporarily latched
  2113. * or not latched.
  2114. *
  2115. *
  2116. *
  2117. *
  2118. * @param v_orient_intr_u8 : The status of orient interrupt
  2119. *
  2120. * @note For orient interrupt configuration use the following functions
  2121. * @note STATUS
  2122. * @note bmi160_get_stat0_orient_intr()
  2123. * @note AXIS MAPPING
  2124. * @note bmi160_get_stat3_orient_xy()
  2125. * @note bmi160_get_stat3_orient_z()
  2126. * @note bmi160_set_intr_orient_axes_enable()
  2127. * @note INTERRUPT MAPPING
  2128. * @note bmi160_set_intr_orient()
  2129. * @note INTERRUPT OUTPUT
  2130. * @note bmi160_set_intr_orient_ud_enable()
  2131. * @note THETA
  2132. * @note bmi160_set_intr_orient_theta()
  2133. * @note HYSTERESIS
  2134. * @note bmi160_set_intr_orient_hyst()
  2135. * @note BLOCKING
  2136. * @note bmi160_set_intr_orient_blocking()
  2137. * @note MODE
  2138. * @note bmi160_set_intr_orient_mode()
  2139. *
  2140. * @return results of bus communication function
  2141. * @retval 0 -> Success
  2142. * @retval -1 -> Error
  2143. *
  2144. *
  2145. */
  2146. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_orient_intr(u8
  2147. *v_orient_intr_u8)
  2148. {
  2149. /* variable used to return the status of communication result*/
  2150. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2151. u8 v_data_u8 = BMI160_INIT_VALUE;
  2152. /* check the p_bmi160 structure for NULL pointer assignment*/
  2153. if (p_bmi160 == BMI160_NULL) {
  2154. return E_BMI160_NULL_PTR;
  2155. } else {
  2156. com_rslt =
  2157. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2158. BMI160_USER_INTR_STAT_0_ORIENT__REG, &v_data_u8,
  2159. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  2160. *v_orient_intr_u8 =
  2161. BMI160_GET_BITSLICE(v_data_u8,
  2162. BMI160_USER_INTR_STAT_0_ORIENT);
  2163. }
  2164. return com_rslt;
  2165. }
  2166. /*!
  2167. * @brief This API reads the flat interrupt status
  2168. * from the register 0x1C bit 7
  2169. * flag is associated with a specific interrupt function.
  2170. * It is set when the flat interrupt triggers. The
  2171. * setting of INT_LATCH controls the
  2172. * interrupt signal and hence the
  2173. * respective interrupt flag will be
  2174. * permanently latched, temporarily latched
  2175. * or not latched.
  2176. *
  2177. *
  2178. *
  2179. *
  2180. * @param v_flat_intr_u8 : The status of flat interrupt
  2181. *
  2182. * @note For flat configuration use the following functions
  2183. * @note STATS
  2184. * @note bmi160_get_stat0_flat_intr()
  2185. * @note bmi160_get_stat3_flat()
  2186. * @note INTERRUPT MAPPING
  2187. * @note bmi160_set_intr_flat()
  2188. * @note THETA
  2189. * @note bmi160_set_intr_flat_theta()
  2190. * @note HOLD TIME
  2191. * @note bmi160_set_intr_flat_hold()
  2192. * @note HYSTERESIS
  2193. * @note bmi160_set_intr_flat_hyst()
  2194. *
  2195. * @return results of bus communication function
  2196. * @retval 0 -> Success
  2197. * @retval -1 -> Error
  2198. *
  2199. *
  2200. */
  2201. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_flat_intr(u8
  2202. *v_flat_intr_u8)
  2203. {
  2204. /* variable used to return the status of communication result*/
  2205. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2206. u8 v_data_u8 = BMI160_INIT_VALUE;
  2207. /* check the p_bmi160 structure for NULL pointer assignment*/
  2208. if (p_bmi160 == BMI160_NULL) {
  2209. return E_BMI160_NULL_PTR;
  2210. } else {
  2211. com_rslt =
  2212. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2213. BMI160_USER_INTR_STAT_0_FLAT__REG, &v_data_u8,
  2214. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  2215. *v_flat_intr_u8 =
  2216. BMI160_GET_BITSLICE(v_data_u8,
  2217. BMI160_USER_INTR_STAT_0_FLAT);
  2218. }
  2219. return com_rslt;
  2220. }
  2221. /*!
  2222. * @brief This API reads the high_g interrupt status
  2223. * from the register 0x1D bit 2
  2224. * flag is associated with a specific interrupt function.
  2225. * It is set when the high g interrupt triggers. The
  2226. * setting of INT_LATCH controls the interrupt signal and hence the
  2227. * respective interrupt flag will be permanently
  2228. * latched, temporarily latched
  2229. * or not latched.
  2230. *
  2231. *
  2232. *
  2233. *
  2234. * @param v_high_g_intr_u8 : The status of high_g interrupt
  2235. *
  2236. * @note High_g interrupt configured by following functions
  2237. * @note STATUS
  2238. * @note bmi160_get_stat1_high_g_intr()
  2239. * @note AXIS MAPPING
  2240. * @note bmi160_get_stat3_high_g_first_x()
  2241. * @note bmi160_get_stat3_high_g_first_y()
  2242. * @note bmi160_get_stat3_high_g_first_z()
  2243. * @note SIGN MAPPING
  2244. * @note bmi160_get_stat3_high_g_first_sign()
  2245. * @note INTERRUPT MAPPING
  2246. * @note bmi160_set_intr_high_g()
  2247. * @note HYSTERESIS
  2248. * @note bmi160_set_intr_high_g_hyst()
  2249. * @note DURATION
  2250. * @note bmi160_set_intr_high_g_durn()
  2251. * @note THRESHOLD
  2252. * @note bmi160_set_intr_high_g_thres()
  2253. * @note SOURCE
  2254. * @note bmi160_set_intr_low_high_source()
  2255. *
  2256. * @return results of bus communication function
  2257. * @retval 0 -> Success
  2258. * @retval -1 -> Error
  2259. *
  2260. */
  2261. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat1_high_g_intr(u8
  2262. *v_high_g_intr_u8)
  2263. {
  2264. /* variable used to return the status of communication result*/
  2265. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2266. u8 v_data_u8 = BMI160_INIT_VALUE;
  2267. /* check the p_bmi160 structure for NULL pointer assignment*/
  2268. if (p_bmi160 == BMI160_NULL) {
  2269. return E_BMI160_NULL_PTR;
  2270. } else {
  2271. com_rslt =
  2272. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2273. BMI160_USER_INTR_STAT_1_HIGH_G_INTR__REG,
  2274. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  2275. *v_high_g_intr_u8 =
  2276. BMI160_GET_BITSLICE(v_data_u8,
  2277. BMI160_USER_INTR_STAT_1_HIGH_G_INTR);
  2278. }
  2279. return com_rslt;
  2280. }
  2281. /*!
  2282. * @brief This API reads the low g interrupt status
  2283. * from the register 0x1D bit 3
  2284. * flag is associated with a specific interrupt function.
  2285. * It is set when the low g interrupt triggers. The
  2286. * setting of INT_LATCH controls the interrupt signal and hence the
  2287. * respective interrupt flag will be
  2288. * permanently latched, temporarily latched
  2289. * or not latched.
  2290. *
  2291. *
  2292. *
  2293. *
  2294. * @param v_low_g_intr_u8 : The status of low_g interrupt
  2295. *
  2296. * @note Low_g interrupt configured by following functions
  2297. * @note STATUS
  2298. * @note bmi160_get_stat1_low_g_intr()
  2299. * @note INTERRUPT MAPPING
  2300. * @note bmi160_set_intr_low_g()
  2301. * @note SOURCE
  2302. * @note bmi160_set_intr_low_high_source()
  2303. * @note DURATION
  2304. * @note bmi160_set_intr_low_g_durn()
  2305. * @note THRESHOLD
  2306. * @note bmi160_set_intr_low_g_thres()
  2307. * @note HYSTERESIS
  2308. * @note bmi160_set_intr_low_g_hyst()
  2309. * @note MODE
  2310. * @note bmi160_set_intr_low_g_mode()
  2311. *
  2312. * @return results of bus communication function
  2313. * @retval 0 -> Success
  2314. * @retval -1 -> Error
  2315. *
  2316. *
  2317. */
  2318. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat1_low_g_intr(u8
  2319. *v_low_g_intr_u8)
  2320. {
  2321. /* variable used to return the status of communication result*/
  2322. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2323. u8 v_data_u8 = BMI160_INIT_VALUE;
  2324. /* check the p_bmi160 structure for NULL pointer assignment*/
  2325. if (p_bmi160 == BMI160_NULL) {
  2326. return E_BMI160_NULL_PTR;
  2327. } else {
  2328. com_rslt =
  2329. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2330. BMI160_USER_INTR_STAT_1_LOW_G_INTR__REG, &v_data_u8,
  2331. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  2332. *v_low_g_intr_u8 =
  2333. BMI160_GET_BITSLICE(v_data_u8,
  2334. BMI160_USER_INTR_STAT_1_LOW_G_INTR);
  2335. }
  2336. return com_rslt;
  2337. }
  2338. /*!
  2339. * @brief This API reads data ready interrupt status
  2340. * from the register 0x1D bit 4
  2341. * flag is associated with a specific interrupt function.
  2342. * It is set when the data ready interrupt triggers. The
  2343. * setting of INT_LATCH controls the interrupt signal and hence the
  2344. * respective interrupt flag will be
  2345. * permanently latched, temporarily latched
  2346. * or not latched.
  2347. *
  2348. *
  2349. *
  2350. *
  2351. * @param v_data_rdy_intr_u8 : The status of data ready interrupt
  2352. *
  2353. * @note Data ready interrupt configured by following functions
  2354. * @note STATUS
  2355. * @note bmi160_get_stat1_data_rdy_intr()
  2356. * @note INTERRUPT MAPPING
  2357. * @note bmi160_set_intr_data_rdy()
  2358. *
  2359. * @return results of bus communication function
  2360. * @retval 0 -> Success
  2361. * @retval -1 -> Error
  2362. *
  2363. *
  2364. */
  2365. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat1_data_rdy_intr(u8
  2366. *v_data_rdy_intr_u8)
  2367. {
  2368. /* variable used to return the status of communication result*/
  2369. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2370. u8 v_data_u8 = BMI160_INIT_VALUE;
  2371. /* check the p_bmi160 structure for NULL pointer assignment*/
  2372. if (p_bmi160 == BMI160_NULL) {
  2373. return E_BMI160_NULL_PTR;
  2374. } else {
  2375. com_rslt =
  2376. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2377. BMI160_USER_INTR_STAT_1_DATA_RDY_INTR__REG,
  2378. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  2379. *v_data_rdy_intr_u8 = BMI160_GET_BITSLICE(v_data_u8,
  2380. BMI160_USER_INTR_STAT_1_DATA_RDY_INTR);
  2381. }
  2382. return com_rslt;
  2383. }
  2384. #ifdef FIFO_ENABLE
  2385. /*!
  2386. * @brief This API reads data ready FIFO full interrupt status
  2387. * from the register 0x1D bit 5
  2388. * flag is associated with a specific interrupt function.
  2389. * It is set when the FIFO full interrupt triggers. The
  2390. * setting of INT_LATCH controls the
  2391. * interrupt signal and hence the
  2392. * respective interrupt flag will
  2393. * be permanently latched, temporarily latched
  2394. * or not latched.
  2395. *
  2396. *
  2397. *
  2398. *
  2399. * @param v_fifo_full_intr_u8 : The status of FIFO full interrupt
  2400. *
  2401. * @note FIFO full interrupt can be configured by following functions
  2402. * @note bmi160_set_intr_fifo_full()
  2403. *
  2404. * @return results of bus communication function
  2405. * @retval 0 -> Success
  2406. * @retval -1 -> Error
  2407. *
  2408. *
  2409. */
  2410. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat1_fifo_full_intr(u8
  2411. *v_fifo_full_intr_u8)
  2412. {
  2413. /* variable used to return the status of communication result*/
  2414. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2415. u8 v_data_u8 = BMI160_INIT_VALUE;
  2416. /* check the p_bmi160 structure for NULL pointer assignment*/
  2417. if (p_bmi160 == BMI160_NULL) {
  2418. return E_BMI160_NULL_PTR;
  2419. } else {
  2420. com_rslt =
  2421. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2422. BMI160_USER_INTR_STAT_1_FIFO_FULL_INTR__REG,
  2423. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  2424. *v_fifo_full_intr_u8 =
  2425. BMI160_GET_BITSLICE(v_data_u8,
  2426. BMI160_USER_INTR_STAT_1_FIFO_FULL_INTR);
  2427. }
  2428. return com_rslt;
  2429. }
  2430. /*!
  2431. * @brief This API reads data
  2432. * ready FIFO watermark interrupt status
  2433. * from the register 0x1D bit 6
  2434. * flag is associated with a specific interrupt function.
  2435. * It is set when the FIFO watermark interrupt triggers. The
  2436. * setting of INT_LATCH controls the
  2437. * interrupt signal and hence the
  2438. * respective interrupt flag will be
  2439. * permanently latched, temporarily latched
  2440. * or not latched.
  2441. *
  2442. *
  2443. *
  2444. *
  2445. * @param v_fifo_wm_intr_u8 : The status of FIFO water mark interrupt
  2446. *
  2447. * @note FIFO full interrupt can be configured by following functions
  2448. * @note bmi160_set_intr_fifo_wm()
  2449. *
  2450. * @return results of bus communication function
  2451. * @retval 0 -> Success
  2452. * @retval -1 -> Error
  2453. *
  2454. *
  2455. */
  2456. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat1_fifo_wm_intr(u8
  2457. *v_fifo_wm_intr_u8)
  2458. {
  2459. /* variable used to return the status of communication result*/
  2460. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2461. u8 v_data_u8 = BMI160_INIT_VALUE;
  2462. /* check the p_bmi160 structure for NULL pointer assignment*/
  2463. if (p_bmi160 == BMI160_NULL) {
  2464. return E_BMI160_NULL_PTR;
  2465. } else {
  2466. com_rslt =
  2467. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2468. BMI160_USER_INTR_STAT_1_FIFO_WM_INTR__REG,
  2469. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  2470. *v_fifo_wm_intr_u8 =
  2471. BMI160_GET_BITSLICE(v_data_u8,
  2472. BMI160_USER_INTR_STAT_1_FIFO_WM_INTR);
  2473. }
  2474. return com_rslt;
  2475. }
  2476. #endif
  2477. /*!
  2478. * @brief This API reads data ready no motion interrupt status
  2479. * from the register 0x1D bit 7
  2480. * flag is associated with a specific interrupt function.
  2481. * It is set when the no motion interrupt triggers. The
  2482. * setting of INT_LATCH controls the interrupt signal and hence the
  2483. * respective interrupt flag will be permanently
  2484. * latched, temporarily latched
  2485. * or not latched.
  2486. *
  2487. *
  2488. *
  2489. *
  2490. * @param v_nomotion_intr_u8 : The status of no motion interrupt
  2491. *
  2492. * @note No motion interrupt can be configured by following function
  2493. * @note STATUS
  2494. * @note bmi160_get_stat1_nomotion_intr()
  2495. * @note INTERRUPT MAPPING
  2496. * @note bmi160_set_intr_nomotion()
  2497. * @note DURATION
  2498. * @note bmi160_set_intr_slow_no_motion_durn()
  2499. * @note THRESHOLD
  2500. * @note bmi160_set_intr_slow_no_motion_thres()
  2501. * @note SLOW/NO MOTION SELECT
  2502. * @note bmi160_set_intr_slow_no_motion_select()
  2503. *
  2504. * @return results of bus communication function
  2505. * @retval 0 -> Success
  2506. * @retval -1 -> Error
  2507. *
  2508. *
  2509. */
  2510. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat1_nomotion_intr(u8
  2511. *v_nomotion_intr_u8)
  2512. {
  2513. /* variable used to return the status of communication result*/
  2514. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2515. u8 v_data_u8 = BMI160_INIT_VALUE;
  2516. /* check the p_bmi160 structure for NULL pointer assignment*/
  2517. if (p_bmi160 == BMI160_NULL) {
  2518. return E_BMI160_NULL_PTR;
  2519. } else {
  2520. /* read the no motion interrupt*/
  2521. com_rslt =
  2522. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2523. BMI160_USER_INTR_STAT_1_NOMOTION_INTR__REG,
  2524. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  2525. *v_nomotion_intr_u8 =
  2526. BMI160_GET_BITSLICE(v_data_u8,
  2527. BMI160_USER_INTR_STAT_1_NOMOTION_INTR);
  2528. }
  2529. return com_rslt;
  2530. }
  2531. /*!
  2532. *@brief This API reads the status of any motion first x
  2533. * from the register 0x1E bit 0
  2534. *
  2535. *
  2536. *@param v_anymotion_first_x_u8 : The status of any motion first x interrupt
  2537. * value | status
  2538. * -----------|-------------
  2539. * 0 | not triggered
  2540. * 1 | triggered by x axis
  2541. *
  2542. * @return results of bus communication function
  2543. * @retval 0 -> Success
  2544. * @retval -1 -> Error
  2545. *
  2546. *
  2547. */
  2548. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_any_motion_first_x(u8
  2549. *v_anymotion_first_x_u8)
  2550. {
  2551. /* variable used to return the status of communication result*/
  2552. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2553. u8 v_data_u8 = BMI160_INIT_VALUE;
  2554. /* check the p_bmi160 structure for NULL pointer assignment*/
  2555. if (p_bmi160 == BMI160_NULL) {
  2556. return E_BMI160_NULL_PTR;
  2557. } else {
  2558. /* read the any motion first x interrupt*/
  2559. com_rslt =
  2560. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2561. BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_X__REG,
  2562. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  2563. *v_anymotion_first_x_u8 =
  2564. BMI160_GET_BITSLICE(v_data_u8,
  2565. BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_X);
  2566. }
  2567. return com_rslt;
  2568. }
  2569. /*!
  2570. * @brief This API reads the status of any motion first y interrupt
  2571. * from the register 0x1E bit 1
  2572. *
  2573. *
  2574. *
  2575. *@param v_any_motion_first_y_u8 : The status of any motion first y interrupt
  2576. * value | status
  2577. * -----------|-------------
  2578. * 0 | not triggered
  2579. * 1 | triggered by y axis
  2580. *
  2581. *
  2582. *
  2583. * @return results of bus communication function
  2584. * @retval 0 -> Success
  2585. * @retval -1 -> Error
  2586. *
  2587. *
  2588. */
  2589. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_any_motion_first_y(u8
  2590. *v_any_motion_first_y_u8)
  2591. {
  2592. /* variable used to return the status of communication result*/
  2593. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2594. u8 v_data_u8 = BMI160_INIT_VALUE;
  2595. /* check the p_bmi160 structure for NULL pointer assignment*/
  2596. if (p_bmi160 == BMI160_NULL) {
  2597. return E_BMI160_NULL_PTR;
  2598. } else {
  2599. /* read the any motion first y interrupt*/
  2600. com_rslt =
  2601. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2602. BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_Y__REG,
  2603. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  2604. *v_any_motion_first_y_u8 =
  2605. BMI160_GET_BITSLICE(v_data_u8,
  2606. BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_Y);
  2607. }
  2608. return com_rslt;
  2609. }
  2610. /*!
  2611. * @brief This API reads the status of any motion first z interrupt
  2612. * from the register 0x1E bit 2
  2613. *
  2614. *
  2615. *
  2616. *
  2617. *@param v_any_motion_first_z_u8 : The status of any motion first z interrupt
  2618. * value | status
  2619. * -----------|-------------
  2620. * 0 | not triggered
  2621. * 1 | triggered by y axis
  2622. *
  2623. *
  2624. *
  2625. * @return results of bus communication function
  2626. * @retval 0 -> Success
  2627. * @retval -1 -> Error
  2628. *
  2629. *
  2630. */
  2631. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_any_motion_first_z(u8
  2632. *v_any_motion_first_z_u8)
  2633. {
  2634. /* variable used to return the status of communication result*/
  2635. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2636. u8 v_data_u8 = BMI160_INIT_VALUE;
  2637. /* check the p_bmi160 structure for NULL pointer assignment*/
  2638. if (p_bmi160 == BMI160_NULL) {
  2639. return E_BMI160_NULL_PTR;
  2640. } else {
  2641. /* read the any motion first z interrupt*/
  2642. com_rslt =
  2643. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2644. BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_Z__REG,
  2645. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  2646. *v_any_motion_first_z_u8 =
  2647. BMI160_GET_BITSLICE(v_data_u8,
  2648. BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_Z);
  2649. }
  2650. return com_rslt;
  2651. }
  2652. /*!
  2653. * @brief This API reads the any motion sign status from the
  2654. * register 0x1E bit 3
  2655. *
  2656. *
  2657. *
  2658. *
  2659. * @param v_anymotion_sign_u8 : The status of any motion sign
  2660. * value | sign
  2661. * -----------|-------------
  2662. * 0 | positive
  2663. * 1 | negative
  2664. *
  2665. *
  2666. * @return results of bus communication function
  2667. * @retval 0 -> Success
  2668. * @retval -1 -> Error
  2669. *
  2670. *
  2671. */
  2672. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_any_motion_sign(u8
  2673. *v_anymotion_sign_u8)
  2674. {
  2675. /* variable used to return the status of communication result*/
  2676. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2677. u8 v_data_u8 = BMI160_INIT_VALUE;
  2678. /* check the p_bmi160 structure for NULL pointer assignment*/
  2679. if (p_bmi160 == BMI160_NULL) {
  2680. return E_BMI160_NULL_PTR;
  2681. } else {
  2682. /* read any motion sign interrupt status */
  2683. com_rslt =
  2684. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2685. BMI160_USER_INTR_STAT_2_ANY_MOTION_SIGN__REG,
  2686. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  2687. *v_anymotion_sign_u8 =
  2688. BMI160_GET_BITSLICE(v_data_u8,
  2689. BMI160_USER_INTR_STAT_2_ANY_MOTION_SIGN);
  2690. }
  2691. return com_rslt;
  2692. }
  2693. /*!
  2694. * @brief This API reads the any motion tap first x status from the
  2695. * register 0x1E bit 4
  2696. *
  2697. *
  2698. *
  2699. *
  2700. * @param v_tap_first_x_u8 :The status of any motion tap first x
  2701. * value | status
  2702. * -----------|-------------
  2703. * 0 | not triggered
  2704. * 1 | triggered by x axis
  2705. *
  2706. * @return results of bus communication function
  2707. * @retval 0 -> Success
  2708. * @retval -1 -> Error
  2709. *
  2710. *
  2711. */
  2712. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_tap_first_x(u8
  2713. *v_tap_first_x_u8)
  2714. {
  2715. /* variable used to return the status of communication result*/
  2716. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2717. u8 v_data_u8 = BMI160_INIT_VALUE;
  2718. /* check the p_bmi160 structure for NULL pointer assignment*/
  2719. if (p_bmi160 == BMI160_NULL) {
  2720. return E_BMI160_NULL_PTR;
  2721. } else {
  2722. /* read tap first x interrupt status */
  2723. com_rslt =
  2724. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2725. BMI160_USER_INTR_STAT_2_TAP_FIRST_X__REG,
  2726. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  2727. *v_tap_first_x_u8 =
  2728. BMI160_GET_BITSLICE(v_data_u8,
  2729. BMI160_USER_INTR_STAT_2_TAP_FIRST_X);
  2730. }
  2731. return com_rslt;
  2732. }
  2733. /*!
  2734. * @brief This API reads the tap first y interrupt status from the
  2735. * register 0x1E bit 5
  2736. *
  2737. *
  2738. *
  2739. *
  2740. * @param v_tap_first_y_u8 :The status of tap first y interrupt
  2741. * value | status
  2742. * -----------|-------------
  2743. * 0 | not triggered
  2744. * 1 | triggered by y axis
  2745. *
  2746. *
  2747. *
  2748. * @return results of bus communication function
  2749. * @retval 0 -> Success
  2750. * @retval -1 -> Error
  2751. *
  2752. *
  2753. */
  2754. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_tap_first_y(u8
  2755. *v_tap_first_y_u8)
  2756. {
  2757. /* variable used to return the status of communication result*/
  2758. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2759. u8 v_data_u8 = BMI160_INIT_VALUE;
  2760. /* check the p_bmi160 structure for NULL pointer assignment*/
  2761. if (p_bmi160 == BMI160_NULL) {
  2762. return E_BMI160_NULL_PTR;
  2763. } else {
  2764. /* read tap first y interrupt status */
  2765. com_rslt =
  2766. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2767. BMI160_USER_INTR_STAT_2_TAP_FIRST_Y__REG,
  2768. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  2769. *v_tap_first_y_u8 =
  2770. BMI160_GET_BITSLICE(v_data_u8,
  2771. BMI160_USER_INTR_STAT_2_TAP_FIRST_Y);
  2772. }
  2773. return com_rslt;
  2774. }
  2775. /*!
  2776. * @brief This API reads the tap first z interrupt status from the
  2777. * register 0x1E bit 6
  2778. *
  2779. *
  2780. *
  2781. *
  2782. * @param v_tap_first_z_u8 :The status of tap first z interrupt
  2783. * value | status
  2784. * -----------|-------------
  2785. * 0 | not triggered
  2786. * 1 | triggered by z axis
  2787. *
  2788. *
  2789. *
  2790. * @return results of bus communication function
  2791. * @retval 0 -> Success
  2792. * @retval -1 -> Error
  2793. *
  2794. *
  2795. */
  2796. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_tap_first_z(u8
  2797. *v_tap_first_z_u8)
  2798. {
  2799. /* variable used to return the status of communication result*/
  2800. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2801. u8 v_data_u8 = BMI160_INIT_VALUE;
  2802. /* check the p_bmi160 structure for NULL pointer assignment*/
  2803. if (p_bmi160 == BMI160_NULL) {
  2804. return E_BMI160_NULL_PTR;
  2805. } else {
  2806. /* read tap first z interrupt status */
  2807. com_rslt =
  2808. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2809. BMI160_USER_INTR_STAT_2_TAP_FIRST_Z__REG,
  2810. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  2811. *v_tap_first_z_u8 =
  2812. BMI160_GET_BITSLICE(v_data_u8,
  2813. BMI160_USER_INTR_STAT_2_TAP_FIRST_Z);
  2814. }
  2815. return com_rslt;
  2816. }
  2817. /*!
  2818. * @brief This API reads the tap sign status from the
  2819. * register 0x1E bit 7
  2820. *
  2821. *
  2822. *
  2823. *
  2824. * @param v_tap_sign_u8 : The status of tap sign
  2825. * value | sign
  2826. * -----------|-------------
  2827. * 0 | positive
  2828. * 1 | negative
  2829. *
  2830. *
  2831. * @return results of bus communication function
  2832. * @retval 0 -> Success
  2833. * @retval -1 -> Error
  2834. *
  2835. *
  2836. */
  2837. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_tap_sign(u8
  2838. *v_tap_sign_u8)
  2839. {
  2840. /* variable used to return the status of communication result*/
  2841. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2842. u8 v_data_u8 = BMI160_INIT_VALUE;
  2843. /* check the p_bmi160 structure for NULL pointer assignment*/
  2844. if (p_bmi160 == BMI160_NULL) {
  2845. return E_BMI160_NULL_PTR;
  2846. } else {
  2847. /* read tap_sign interrupt status */
  2848. com_rslt =
  2849. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2850. BMI160_USER_INTR_STAT_2_TAP_SIGN__REG, &v_data_u8,
  2851. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  2852. *v_tap_sign_u8 =
  2853. BMI160_GET_BITSLICE(v_data_u8,
  2854. BMI160_USER_INTR_STAT_2_TAP_SIGN);
  2855. }
  2856. return com_rslt;
  2857. }
  2858. /*!
  2859. * @brief This API reads the high_g first x status from the
  2860. * register 0x1F bit 0
  2861. *
  2862. *
  2863. *
  2864. *
  2865. * @param v_high_g_first_x_u8 :The status of high_g first x
  2866. * value | status
  2867. * -----------|-------------
  2868. * 0 | not triggered
  2869. * 1 | triggered by x axis
  2870. *
  2871. *
  2872. *
  2873. * @return results of bus communication function
  2874. * @retval 0 -> Success
  2875. * @retval -1 -> Error
  2876. *
  2877. *
  2878. */
  2879. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat3_high_g_first_x(u8
  2880. *v_high_g_first_x_u8)
  2881. {
  2882. /* variable used to return the status of communication result*/
  2883. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2884. u8 v_data_u8 = BMI160_INIT_VALUE;
  2885. /* check the p_bmi160 structure for NULL pointer assignment*/
  2886. if (p_bmi160 == BMI160_NULL) {
  2887. return E_BMI160_NULL_PTR;
  2888. } else {
  2889. /* read highg_x interrupt status */
  2890. com_rslt =
  2891. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2892. BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_X__REG,
  2893. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  2894. *v_high_g_first_x_u8 =
  2895. BMI160_GET_BITSLICE(v_data_u8,
  2896. BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_X);
  2897. }
  2898. return com_rslt;
  2899. }
  2900. /*!
  2901. * @brief This API reads the high_g first y status from the
  2902. * register 0x1F bit 1
  2903. *
  2904. *
  2905. *
  2906. *
  2907. * @param v_high_g_first_y_u8 : The status of high_g first y
  2908. * value | status
  2909. * -----------|-------------
  2910. * 0 | not triggered
  2911. * 1 | triggered by y axis
  2912. *
  2913. *
  2914. *
  2915. * @return results of bus communication function
  2916. * @retval 0 -> Success
  2917. * @retval -1 -> Error
  2918. *
  2919. *
  2920. */
  2921. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat3_high_g_first_y(u8
  2922. *v_high_g_first_y_u8)
  2923. {
  2924. /* variable used to return the status of communication result*/
  2925. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2926. u8 v_data_u8 = BMI160_INIT_VALUE;
  2927. /* check the p_bmi160 structure for NULL pointer assignment*/
  2928. if (p_bmi160 == BMI160_NULL) {
  2929. return E_BMI160_NULL_PTR;
  2930. } else {
  2931. /* read highg_y interrupt status */
  2932. com_rslt =
  2933. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2934. BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_Y__REG,
  2935. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  2936. *v_high_g_first_y_u8 =
  2937. BMI160_GET_BITSLICE(v_data_u8,
  2938. BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_Y);
  2939. }
  2940. return com_rslt;
  2941. }
  2942. /*!
  2943. * @brief This API reads the high_g first z status from the
  2944. * register 0x1F bit 3
  2945. *
  2946. *
  2947. *
  2948. *
  2949. * @param v_high_g_first_z_u8 : The status of high_g first z
  2950. * value | status
  2951. * -----------|-------------
  2952. * 0 | not triggered
  2953. * 1 | triggered by z axis
  2954. *
  2955. *
  2956. *
  2957. * @return results of bus communication function
  2958. * @retval 0 -> Success
  2959. * @retval -1 -> Error
  2960. *
  2961. *
  2962. */
  2963. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat3_high_g_first_z(u8
  2964. *v_high_g_first_z_u8)
  2965. {
  2966. /* variable used to return the status of communication result*/
  2967. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2968. u8 v_data_u8 = BMI160_INIT_VALUE;
  2969. /* check the p_bmi160 structure for NULL pointer assignment*/
  2970. if (p_bmi160 == BMI160_NULL) {
  2971. return E_BMI160_NULL_PTR;
  2972. } else {
  2973. /* read highg_z interrupt status */
  2974. com_rslt =
  2975. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2976. BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_Z__REG,
  2977. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  2978. *v_high_g_first_z_u8 =
  2979. BMI160_GET_BITSLICE(v_data_u8,
  2980. BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_Z);
  2981. }
  2982. return com_rslt;
  2983. }
  2984. /*!
  2985. * @brief This API reads the high g sign status from the
  2986. * register 0x1F bit 3
  2987. *
  2988. *
  2989. *
  2990. *
  2991. * @param v_high_g_sign_u8 :The status of high g sign
  2992. * value | sign
  2993. * -----------|-------------
  2994. * 0 | positive
  2995. * 1 | negative
  2996. *
  2997. *
  2998. *
  2999. * @return results of bus communication function
  3000. * @retval 0 -> Success
  3001. * @retval -1 -> Error
  3002. *
  3003. *
  3004. */
  3005. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat3_high_g_sign(u8
  3006. *v_high_g_sign_u8)
  3007. {
  3008. /* variable used to return the status of communication result*/
  3009. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3010. u8 v_data_u8 = BMI160_INIT_VALUE;
  3011. /* check the p_bmi160 structure for NULL pointer assignment*/
  3012. if (p_bmi160 == BMI160_NULL) {
  3013. return E_BMI160_NULL_PTR;
  3014. } else {
  3015. /* read highg_sign interrupt status */
  3016. com_rslt =
  3017. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3018. BMI160_USER_INTR_STAT_3_HIGH_G_SIGN__REG,
  3019. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  3020. *v_high_g_sign_u8 =
  3021. BMI160_GET_BITSLICE(v_data_u8,
  3022. BMI160_USER_INTR_STAT_3_HIGH_G_SIGN);
  3023. }
  3024. return com_rslt;
  3025. }
  3026. /*!
  3027. * @brief This API reads the status of orient_xy plane
  3028. * from the register 0x1F bit 4 and 5
  3029. *
  3030. *
  3031. * @param v_orient_xy_u8 :The status of orient_xy plane
  3032. * value | status
  3033. * -----------|-------------
  3034. * 0x00 | portrait upright
  3035. * 0x01 | portrait upside down
  3036. * 0x02 | landscape left
  3037. * 0x03 | landscape right
  3038. *
  3039. *
  3040. * @return results of bus communication function
  3041. * @retval 0 -> Success
  3042. * @retval -1 -> Error
  3043. *
  3044. *
  3045. */
  3046. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat3_orient_xy(u8
  3047. *v_orient_xy_u8)
  3048. {
  3049. /* variable used to return the status of communication result*/
  3050. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3051. u8 v_data_u8 = BMI160_INIT_VALUE;
  3052. /* check the p_bmi160 structure for NULL pointer assignment*/
  3053. if (p_bmi160 == BMI160_NULL) {
  3054. return E_BMI160_NULL_PTR;
  3055. } else {
  3056. /* read orient plane xy interrupt status */
  3057. com_rslt =
  3058. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3059. BMI160_USER_INTR_STAT_3_ORIENT_XY__REG,
  3060. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  3061. *v_orient_xy_u8 =
  3062. BMI160_GET_BITSLICE(v_data_u8,
  3063. BMI160_USER_INTR_STAT_3_ORIENT_XY);
  3064. }
  3065. return com_rslt;
  3066. }
  3067. /*!
  3068. * @brief This API reads the status of orient z plane
  3069. * from the register 0x1F bit 6
  3070. *
  3071. *
  3072. * @param v_orient_z_u8 :The status of orient z
  3073. * value | status
  3074. * -----------|-------------
  3075. * 0x00 | upward looking
  3076. * 0x01 | downward looking
  3077. *
  3078. * @return results of bus communication function
  3079. * @retval 0 -> Success
  3080. * @retval -1 -> Error
  3081. *
  3082. *
  3083. */
  3084. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat3_orient_z(u8
  3085. *v_orient_z_u8)
  3086. {
  3087. /* variable used to return the status of communication result*/
  3088. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3089. u8 v_data_u8 = BMI160_INIT_VALUE;
  3090. /* check the p_bmi160 structure for NULL pointer assignment*/
  3091. if (p_bmi160 == BMI160_NULL) {
  3092. return E_BMI160_NULL_PTR;
  3093. } else {
  3094. /* read orient z plane interrupt status */
  3095. com_rslt =
  3096. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3097. BMI160_USER_INTR_STAT_3_ORIENT_Z__REG, &v_data_u8,
  3098. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  3099. *v_orient_z_u8 =
  3100. BMI160_GET_BITSLICE(v_data_u8,
  3101. BMI160_USER_INTR_STAT_3_ORIENT_Z);
  3102. }
  3103. return com_rslt;
  3104. }
  3105. /*!
  3106. * @brief This API reads the flat status from the register
  3107. * 0x1F bit 7
  3108. *
  3109. *
  3110. * @param v_flat_u8 : The status of flat interrupt
  3111. * value | status
  3112. * -----------|-------------
  3113. * 0x00 | non flat
  3114. * 0x01 | flat position
  3115. *
  3116. *
  3117. * @return results of bus communication function
  3118. * @retval 0 -> Success
  3119. * @retval -1 -> Error
  3120. *
  3121. *
  3122. */
  3123. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat3_flat(u8
  3124. *v_flat_u8)
  3125. {
  3126. /* variable used to return the status of communication result*/
  3127. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3128. u8 v_data_u8 = BMI160_INIT_VALUE;
  3129. /* check the p_bmi160 structure for NULL pointer assignment*/
  3130. if (p_bmi160 == BMI160_NULL) {
  3131. return E_BMI160_NULL_PTR;
  3132. } else {
  3133. /* read flat interrupt status */
  3134. com_rslt =
  3135. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3136. BMI160_USER_INTR_STAT_3_FLAT__REG, &v_data_u8,
  3137. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  3138. *v_flat_u8 = BMI160_GET_BITSLICE(v_data_u8,
  3139. BMI160_USER_INTR_STAT_3_FLAT);
  3140. }
  3141. return com_rslt;
  3142. }
  3143. /*!
  3144. * @brief This API reads the temperature of the sensor
  3145. * from the register 0x21 bit 0 to 7
  3146. *
  3147. *
  3148. *
  3149. * @param v_temp_s16 : The value of temperature
  3150. *
  3151. *
  3152. *
  3153. * @return results of bus communication function
  3154. * @retval 0 -> Success
  3155. * @retval -1 -> Error
  3156. *
  3157. *
  3158. */
  3159. BMI160_RETURN_FUNCTION_TYPE bmi160_get_temp(s16
  3160. *v_temp_s16)
  3161. {
  3162. /* variable used to return the status of communication result*/
  3163. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3164. /* Array contains the temperature LSB and MSB data
  3165. v_data_u8[0] - LSB
  3166. v_data_u8[1] - MSB*/
  3167. u8 v_data_u8[BMI160_TEMP_DATA_SIZE] = {BMI160_INIT_VALUE,
  3168. BMI160_INIT_VALUE};
  3169. /* check the p_bmi160 structure for NULL pointer assignment*/
  3170. if (p_bmi160 == BMI160_NULL) {
  3171. return E_BMI160_NULL_PTR;
  3172. } else {
  3173. /* read temperature data */
  3174. com_rslt =
  3175. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3176. BMI160_USER_TEMP_LSB_VALUE__REG, v_data_u8,
  3177. BMI160_TEMP_DATA_LENGTH);
  3178. *v_temp_s16 =
  3179. (s16)(((s32)((s8) (v_data_u8[BMI160_TEMP_MSB_BYTE]) <<
  3180. BMI160_SHIFT_BIT_POSITION_BY_08_BITS))
  3181. | v_data_u8[BMI160_TEMP_LSB_BYTE]);
  3182. }
  3183. return com_rslt;
  3184. }
  3185. #ifdef FIFO_ENABLE
  3186. /*!
  3187. * @brief This API reads the FIFO length of the sensor
  3188. * from the register 0x23 and 0x24 bit 0 to 7 and 0 to 2
  3189. * @brief this byte counter is updated each time a complete frame
  3190. * is read or written
  3191. *
  3192. *
  3193. * @param v_fifo_length_u32 : The value of FIFO byte counter
  3194. *
  3195. *
  3196. * @return results of bus communication function
  3197. * @retval 0 -> Success
  3198. * @retval -1 -> Error
  3199. *
  3200. *
  3201. */
  3202. BMI160_RETURN_FUNCTION_TYPE bmi160_fifo_length(u32 *v_fifo_length_u32)
  3203. {
  3204. /* variable used to return the status of communication result*/
  3205. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3206. /* Array contains the FIFO length data
  3207. v_data_u8[0] - FIFO length
  3208. v_data_u8[1] - FIFO length*/
  3209. u8 a_data_u8r[BMI160_FIFO_DATA_SIZE] = {BMI160_INIT_VALUE,
  3210. BMI160_INIT_VALUE};
  3211. /* check the p_bmi160 structure for NULL pointer assignment*/
  3212. if (p_bmi160 == BMI160_NULL) {
  3213. return E_BMI160_NULL_PTR;
  3214. } else {
  3215. /* read FIFO length*/
  3216. com_rslt =
  3217. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3218. BMI160_USER_FIFO_BYTE_COUNTER_LSB__REG, a_data_u8r,
  3219. BMI160_FIFO_DATA_LENGTH);
  3220. a_data_u8r[BMI160_FIFO_LENGTH_MSB_BYTE] =
  3221. BMI160_GET_BITSLICE(
  3222. a_data_u8r[BMI160_FIFO_LENGTH_MSB_BYTE],
  3223. BMI160_USER_FIFO_BYTE_COUNTER_MSB);
  3224. *v_fifo_length_u32 =
  3225. (u32)(((u32)((u8) (
  3226. a_data_u8r[BMI160_FIFO_LENGTH_MSB_BYTE]) <<
  3227. BMI160_SHIFT_BIT_POSITION_BY_08_BITS))
  3228. | a_data_u8r[BMI160_FIFO_LENGTH_LSB_BYTE]);
  3229. }
  3230. return com_rslt;
  3231. }
  3232. /*!
  3233. * @brief This API reads the FIFO data of the sensor
  3234. * from the register 0x24
  3235. * @brief Data format depends on the setting of register FIFO_CONFIG
  3236. *
  3237. *
  3238. *
  3239. * @param v_fifodata_u8 : Pointer holding the FIFO data
  3240. * @param v_fifo_length_u16 : The value of FIFO length maximum 1024
  3241. *
  3242. * @note For reading FIFO data use the following functions
  3243. *
  3244. * @return results of bus communication function
  3245. * @retval 0 -> Success
  3246. * @retval -1 -> Error
  3247. *
  3248. *
  3249. */
  3250. BMI160_RETURN_FUNCTION_TYPE bmi160_fifo_data(
  3251. u8 *v_fifodata_u8, u16 v_fifo_length_u16)
  3252. {
  3253. /* variable used to return the status of communication result*/
  3254. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3255. /* check the p_bmi160 structure for NULL pointer assignment*/
  3256. if (p_bmi160 == BMI160_NULL) {
  3257. return E_BMI160_NULL_PTR;
  3258. } else {
  3259. /* read FIFO data*/
  3260. com_rslt =
  3261. p_bmi160->BMI160_BURST_READ_FUNC(p_bmi160->dev_addr,
  3262. BMI160_USER_FIFO_DATA__REG,
  3263. v_fifodata_u8, v_fifo_length_u16);
  3264. }
  3265. return com_rslt;
  3266. }
  3267. #endif
  3268. /*!
  3269. * @brief This API is used to get the
  3270. * Accel output data rate from the register 0x40 bit 0 to 3
  3271. *
  3272. *
  3273. * @param v_output_data_rate_u8 :The value of Accel output date rate
  3274. * value | output data rate
  3275. * -------|--------------------------
  3276. * 0 | BMI160_ACCEL_OUTPUT_DATA_RATE_RESERVED
  3277. * 1 | BMI160_ACCEL_OUTPUT_DATA_RATE_0_78HZ
  3278. * 2 | BMI160_ACCEL_OUTPUT_DATA_RATE_1_56HZ
  3279. * 3 | BMI160_ACCEL_OUTPUT_DATA_RATE_3_12HZ
  3280. * 4 | BMI160_ACCEL_OUTPUT_DATA_RATE_6_25HZ
  3281. * 5 | BMI160_ACCEL_OUTPUT_DATA_RATE_12_5HZ
  3282. * 6 | BMI160_ACCEL_OUTPUT_DATA_RATE_25HZ
  3283. * 7 | BMI160_ACCEL_OUTPUT_DATA_RATE_50HZ
  3284. * 8 | BMI160_ACCEL_OUTPUT_DATA_RATE_100HZ
  3285. * 9 | BMI160_ACCEL_OUTPUT_DATA_RATE_200HZ
  3286. * 10 | BMI160_ACCEL_OUTPUT_DATA_RATE_400HZ
  3287. * 11 | BMI160_ACCEL_OUTPUT_DATA_RATE_800HZ
  3288. * 12 | BMI160_ACCEL_OUTPUT_DATA_RATE_1600HZ
  3289. *
  3290. *
  3291. * @return results of bus communication function
  3292. * @retval 0 -> Success
  3293. * @retval -1 -> Error
  3294. *
  3295. *
  3296. */
  3297. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_output_data_rate(
  3298. u8 *v_output_data_rate_u8)
  3299. {
  3300. /* variable used to return the status of communication result*/
  3301. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3302. u8 v_data_u8 = BMI160_INIT_VALUE;
  3303. /* check the p_bmi160 structure for NULL pointer assignment*/
  3304. if (p_bmi160 == BMI160_NULL) {
  3305. return E_BMI160_NULL_PTR;
  3306. } else {
  3307. /* read the Accel output data rate*/
  3308. com_rslt =
  3309. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3310. BMI160_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE__REG,
  3311. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  3312. *v_output_data_rate_u8 = BMI160_GET_BITSLICE(v_data_u8,
  3313. BMI160_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE);
  3314. }
  3315. return com_rslt;
  3316. }
  3317. /*!
  3318. * @brief This API is used to set the
  3319. * Accel output date rate from the register 0x40 bit 0 to 3
  3320. *
  3321. *
  3322. * @param v_output_data_rate_u8 :The value of Accel output date rate
  3323. * value | output data rate
  3324. * -------|--------------------------
  3325. * 0 | BMI160_ACCEL_OUTPUT_DATA_RATE_RESERVED
  3326. * 1 | BMI160_ACCEL_OUTPUT_DATA_RATE_0_78HZ
  3327. * 2 | BMI160_ACCEL_OUTPUT_DATA_RATE_1_56HZ
  3328. * 3 | BMI160_ACCEL_OUTPUT_DATA_RATE_3_12HZ
  3329. * 4 | BMI160_ACCEL_OUTPUT_DATA_RATE_6_25HZ
  3330. * 5 | BMI160_ACCEL_OUTPUT_DATA_RATE_12_5HZ
  3331. * 6 | BMI160_ACCEL_OUTPUT_DATA_RATE_25HZ
  3332. * 7 | BMI160_ACCEL_OUTPUT_DATA_RATE_50HZ
  3333. * 8 | BMI160_ACCEL_OUTPUT_DATA_RATE_100HZ
  3334. * 9 | BMI160_ACCEL_OUTPUT_DATA_RATE_200HZ
  3335. * 10 | BMI160_ACCEL_OUTPUT_DATA_RATE_400HZ
  3336. * 11 | BMI160_ACCEL_OUTPUT_DATA_RATE_800HZ
  3337. * 12 | BMI160_ACCEL_OUTPUT_DATA_RATE_1600HZ
  3338. *
  3339. * @param v_accel_bw_u8 :The value of Accel selected Accel bandwidth
  3340. * value | output data rate
  3341. * -------|--------------------------
  3342. * 0 | BMI160_ACCEL_OSR4_AVG1
  3343. * 1 | BMI160_ACCEL_OSR2_AVG2
  3344. * 2 | BMI160_ACCEL_NORMAL_AVG4
  3345. * 3 | BMI160_ACCEL_CIC_AVG8
  3346. * 4 | BMI160_ACCEL_RES_AVG2
  3347. * 5 | BMI160_ACCEL_RES_AVG4
  3348. * 6 | BMI160_ACCEL_RES_AVG8
  3349. * 7 | BMI160_ACCEL_RES_AVG16
  3350. * 8 | BMI160_ACCEL_RES_AVG32
  3351. * 9 | BMI160_ACCEL_RES_AVG64
  3352. * 10 | BMI160_ACCEL_RES_AVG128
  3353. *
  3354. *
  3355. *
  3356. *
  3357. *
  3358. * @note Verify the Accel bandwidth before setting the
  3359. * output data rate
  3360. * bandwidth | output data rate | under sampling
  3361. *-------------|------------------|----------------
  3362. * OSR4 | 12.5 TO 1600 | 0
  3363. * OSR2 | 12.5 TO 1600 | 0
  3364. * NORMAL | 12.5 TO 1600 | 0
  3365. * CIC | 12.5 TO 1600 | 0
  3366. * AVG2 | 0.78 TO 400 | 1
  3367. * AVG4 | 0.78 TO 200 | 1
  3368. * AVG8 | 0.78 TO 100 | 1
  3369. * AVG16 | 0.78 TO 50 | 1
  3370. * AVG32 | 0.78 TO 25 | 1
  3371. * AVG64 | 0.78 TO 12.5 | 1
  3372. * AVG128 | 0.78 TO 6.25 | 1
  3373. *
  3374. * @return results of bus communication function
  3375. * @retval 0 -> Success
  3376. * @retval -1 -> Error
  3377. *
  3378. *
  3379. */
  3380. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_output_data_rate(
  3381. u8 v_output_data_rate_u8, u8 v_accel_bw_u8)
  3382. {
  3383. /* variable used to return the status of communication result*/
  3384. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3385. u8 v_data_u8 = BMI160_INIT_VALUE;
  3386. u8 v_odr_u8 = BMI160_INIT_VALUE;
  3387. u8 v_assign_bw = BMI160_ASSIGN_DATA;
  3388. /* check the p_bmi160 structure for NULL pointer assignment*/
  3389. if (p_bmi160 == BMI160_NULL) {
  3390. return E_BMI160_NULL_PTR;
  3391. } else {
  3392. if ((v_accel_bw_u8 >= BMI160_ACCEL_RES_AVG2) &&
  3393. (v_accel_bw_u8 <= BMI160_ACCEL_RES_AVG128)) {
  3394. /* enable the under sampling*/
  3395. com_rslt = bmi160_set_accel_under_sampling_parameter(
  3396. BMI160_US_ENABLE);
  3397. } else if (((v_accel_bw_u8 > BMI160_ACCEL_OSR4_AVG1) &&
  3398. (v_accel_bw_u8 <= BMI160_ACCEL_CIC_AVG8))
  3399. || (v_accel_bw_u8 == BMI160_ACCEL_OSR4_AVG1)) {
  3400. /* disable the under sampling*/
  3401. com_rslt = bmi160_set_accel_under_sampling_parameter(
  3402. BMI160_US_DISABLE);
  3403. }
  3404. /* assign the output data rate*/
  3405. switch (v_accel_bw_u8) {
  3406. case BMI160_ACCEL_RES_AVG2:
  3407. if (v_output_data_rate_u8
  3408. >= BMI160_ACCEL_OUTPUT_DATA_RATE_0_78HZ
  3409. && v_output_data_rate_u8
  3410. <= BMI160_ACCEL_OUTPUT_DATA_RATE_400HZ) {
  3411. v_odr_u8 = v_output_data_rate_u8;
  3412. v_assign_bw = SUCCESS;
  3413. } else {
  3414. com_rslt = E_BMI160_OUT_OF_RANGE;
  3415. }
  3416. break;
  3417. case BMI160_ACCEL_RES_AVG4:
  3418. if (v_output_data_rate_u8
  3419. >= BMI160_ACCEL_OUTPUT_DATA_RATE_0_78HZ
  3420. && v_output_data_rate_u8
  3421. <= BMI160_ACCEL_OUTPUT_DATA_RATE_200HZ) {
  3422. v_odr_u8 = v_output_data_rate_u8;
  3423. v_assign_bw = SUCCESS;
  3424. } else {
  3425. com_rslt = E_BMI160_OUT_OF_RANGE;
  3426. }
  3427. break;
  3428. case BMI160_ACCEL_RES_AVG8:
  3429. if (v_output_data_rate_u8
  3430. >= BMI160_ACCEL_OUTPUT_DATA_RATE_0_78HZ
  3431. && v_output_data_rate_u8
  3432. <= BMI160_ACCEL_OUTPUT_DATA_RATE_100HZ) {
  3433. v_odr_u8 = v_output_data_rate_u8;
  3434. v_assign_bw = SUCCESS;
  3435. } else {
  3436. com_rslt = E_BMI160_OUT_OF_RANGE;
  3437. }
  3438. break;
  3439. case BMI160_ACCEL_RES_AVG16:
  3440. if (v_output_data_rate_u8
  3441. >= BMI160_ACCEL_OUTPUT_DATA_RATE_0_78HZ
  3442. && v_output_data_rate_u8
  3443. <= BMI160_ACCEL_OUTPUT_DATA_RATE_50HZ) {
  3444. v_odr_u8 = v_output_data_rate_u8;
  3445. v_assign_bw = SUCCESS;
  3446. } else {
  3447. com_rslt = E_BMI160_OUT_OF_RANGE;
  3448. }
  3449. break;
  3450. case BMI160_ACCEL_RES_AVG32:
  3451. if (v_output_data_rate_u8
  3452. >= BMI160_ACCEL_OUTPUT_DATA_RATE_0_78HZ
  3453. && v_output_data_rate_u8
  3454. <= BMI160_ACCEL_OUTPUT_DATA_RATE_25HZ) {
  3455. v_odr_u8 = v_output_data_rate_u8;
  3456. v_assign_bw = SUCCESS;
  3457. } else {
  3458. com_rslt = E_BMI160_OUT_OF_RANGE;
  3459. }
  3460. break;
  3461. case BMI160_ACCEL_RES_AVG64:
  3462. if (v_output_data_rate_u8
  3463. >= BMI160_ACCEL_OUTPUT_DATA_RATE_0_78HZ
  3464. && v_output_data_rate_u8
  3465. <= BMI160_ACCEL_OUTPUT_DATA_RATE_12_5HZ) {
  3466. v_odr_u8 = v_output_data_rate_u8;
  3467. v_assign_bw = SUCCESS;
  3468. } else {
  3469. com_rslt = E_BMI160_OUT_OF_RANGE;
  3470. }
  3471. break;
  3472. case BMI160_ACCEL_RES_AVG128:
  3473. if (v_output_data_rate_u8
  3474. >= BMI160_ACCEL_OUTPUT_DATA_RATE_0_78HZ
  3475. && v_output_data_rate_u8
  3476. <= BMI160_ACCEL_OUTPUT_DATA_RATE_6_25HZ) {
  3477. v_odr_u8 = v_output_data_rate_u8;
  3478. v_assign_bw = SUCCESS;
  3479. } else {
  3480. com_rslt = E_BMI160_OUT_OF_RANGE;
  3481. }
  3482. break;
  3483. case BMI160_ACCEL_OSR4_AVG1:
  3484. if ((v_output_data_rate_u8
  3485. >= BMI160_ACCEL_OUTPUT_DATA_RATE_12_5HZ)
  3486. && (v_output_data_rate_u8
  3487. <= BMI160_ACCEL_OUTPUT_DATA_RATE_1600HZ)) {
  3488. v_odr_u8 = v_output_data_rate_u8;
  3489. v_assign_bw = SUCCESS;
  3490. } else {
  3491. com_rslt = E_BMI160_OUT_OF_RANGE;
  3492. }
  3493. break;
  3494. case BMI160_ACCEL_OSR2_AVG2:
  3495. if ((v_output_data_rate_u8
  3496. >= BMI160_ACCEL_OUTPUT_DATA_RATE_12_5HZ)
  3497. && (v_output_data_rate_u8
  3498. <= BMI160_ACCEL_OUTPUT_DATA_RATE_1600HZ)) {
  3499. v_odr_u8 = v_output_data_rate_u8;
  3500. v_assign_bw = SUCCESS;
  3501. } else {
  3502. com_rslt = E_BMI160_OUT_OF_RANGE;
  3503. }
  3504. break;
  3505. case BMI160_ACCEL_NORMAL_AVG4:
  3506. if ((v_output_data_rate_u8
  3507. >= BMI160_ACCEL_OUTPUT_DATA_RATE_12_5HZ)
  3508. && (v_output_data_rate_u8
  3509. <= BMI160_ACCEL_OUTPUT_DATA_RATE_1600HZ)) {
  3510. v_odr_u8 = v_output_data_rate_u8;
  3511. v_assign_bw = SUCCESS;
  3512. } else {
  3513. com_rslt = E_BMI160_OUT_OF_RANGE;
  3514. }
  3515. break;
  3516. case BMI160_ACCEL_CIC_AVG8:
  3517. if ((v_output_data_rate_u8
  3518. >= BMI160_ACCEL_OUTPUT_DATA_RATE_12_5HZ)
  3519. && (v_output_data_rate_u8
  3520. <= BMI160_ACCEL_OUTPUT_DATA_RATE_1600HZ)) {
  3521. v_odr_u8 = v_output_data_rate_u8;
  3522. v_assign_bw = SUCCESS;
  3523. } else {
  3524. com_rslt = E_BMI160_OUT_OF_RANGE;
  3525. }
  3526. break;
  3527. default:
  3528. com_rslt = E_BMI160_OUT_OF_RANGE;
  3529. break;
  3530. }
  3531. if (v_assign_bw == SUCCESS) {
  3532. /* write Accel output data rate */
  3533. com_rslt +=
  3534. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3535. BMI160_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE__REG,
  3536. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  3537. if (com_rslt == SUCCESS) {
  3538. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  3539. BMI160_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE,
  3540. v_odr_u8);
  3541. com_rslt +=
  3542. p_bmi160->BMI160_BUS_WRITE_FUNC(
  3543. p_bmi160->dev_addr,
  3544. BMI160_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE__REG,
  3545. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  3546. /*Accel and Gyro power mode check*/
  3547. if (bmi160_power_mode_status_u8_g !=
  3548. BMI160_NORMAL_MODE)
  3549. /*interface idle time delay */
  3550. p_bmi160->delay_msec(
  3551. BMI160_GEN_READ_WRITE_DELAY);
  3552. }
  3553. } else {
  3554. com_rslt = E_BMI160_OUT_OF_RANGE;
  3555. }
  3556. }
  3557. return com_rslt;
  3558. }
  3559. /*!
  3560. * @brief This API is used to get the
  3561. * Accel bandwidth from the register 0x40 bit 4 to 6
  3562. * @brief bandwidth parameter determines filter configuration(acc_us=0)
  3563. * and averaging for under sampling mode(acc_us=1)
  3564. *
  3565. *
  3566. * @param v_bw_u8 : The value of Accel bandwidth
  3567. *
  3568. * @note Accel bandwidth depends on under sampling parameter
  3569. * @note under sampling parameter cab be set by the function
  3570. * "BMI160_SET_ACCEL_UNDER_SAMPLING_PARAMETER"
  3571. *
  3572. * @note Filter configuration
  3573. * accel_us | Filter configuration
  3574. * -----------|---------------------
  3575. * 0x00 | OSR4 mode
  3576. * 0x01 | OSR2 mode
  3577. * 0x02 | normal mode
  3578. * 0x03 | CIC mode
  3579. * 0x04 | Reserved
  3580. * 0x05 | Reserved
  3581. * 0x06 | Reserved
  3582. * 0x07 | Reserved
  3583. *
  3584. * @note Accel under sampling mode
  3585. * accel_us | Under sampling mode
  3586. * -----------|---------------------
  3587. * 0x00 | no averaging
  3588. * 0x01 | average 2 samples
  3589. * 0x02 | average 4 samples
  3590. * 0x03 | average 8 samples
  3591. * 0x04 | average 16 samples
  3592. * 0x05 | average 32 samples
  3593. * 0x06 | average 64 samples
  3594. * 0x07 | average 128 samples
  3595. *
  3596. *
  3597. *
  3598. * @return results of bus communication function
  3599. * @retval 0 -> Success
  3600. * @retval -1 -> Error
  3601. *
  3602. *
  3603. */
  3604. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_bw(u8 *v_bw_u8)
  3605. {
  3606. /* variable used to return the status of communication result*/
  3607. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3608. u8 v_data_u8 = BMI160_INIT_VALUE;
  3609. /* check the p_bmi160 structure for NULL pointer assignment*/
  3610. if (p_bmi160 == BMI160_NULL) {
  3611. return E_BMI160_NULL_PTR;
  3612. } else {
  3613. /* read the Accel bandwidth */
  3614. com_rslt =
  3615. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3616. BMI160_USER_ACCEL_CONFIG_ACCEL_BW__REG, &v_data_u8,
  3617. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  3618. *v_bw_u8 = BMI160_GET_BITSLICE(v_data_u8,
  3619. BMI160_USER_ACCEL_CONFIG_ACCEL_BW);
  3620. }
  3621. return com_rslt;
  3622. }
  3623. /*!
  3624. * @brief This API is used to set the
  3625. * Accel bandwidth from the register 0x40 bit 4 to 6
  3626. * @brief bandwidth parameter determines filter configuration(acc_us=0)
  3627. * and averaging for under sampling mode(acc_us=1)
  3628. *
  3629. *
  3630. * @param v_bw_u8 : The value of Accel bandwidth
  3631. *
  3632. * @note Accel bandwidth depends on under sampling parameter
  3633. * @note under sampling parameter cab be set by the function
  3634. * "BMI160_SET_ACCEL_UNDER_SAMPLING_PARAMETER"
  3635. *
  3636. * @note Filter configuration
  3637. * accel_us | Filter configuration
  3638. * -----------|---------------------
  3639. * 0x00 | OSR4 mode
  3640. * 0x01 | OSR2 mode
  3641. * 0x02 | normal mode
  3642. * 0x03 | CIC mode
  3643. * 0x04 | Reserved
  3644. * 0x05 | Reserved
  3645. * 0x06 | Reserved
  3646. * 0x07 | Reserved
  3647. *
  3648. * @note Accel under sampling mode
  3649. * accel_us | Under sampling mode
  3650. * -----------|---------------------
  3651. * 0x00 | no averaging
  3652. * 0x01 | average 2 samples
  3653. * 0x02 | average 4 samples
  3654. * 0x03 | average 8 samples
  3655. * 0x04 | average 16 samples
  3656. * 0x05 | average 32 samples
  3657. * 0x06 | average 64 samples
  3658. * 0x07 | average 128 samples
  3659. *
  3660. *
  3661. *
  3662. * @return results of bus communication function
  3663. * @retval 0 -> Success
  3664. * @retval -1 -> Error
  3665. *
  3666. *
  3667. */
  3668. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_bw(u8 v_bw_u8)
  3669. {
  3670. /* variable used to return the status of communication result*/
  3671. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3672. u8 v_data_u8 = BMI160_INIT_VALUE;
  3673. /* check the p_bmi160 structure for NULL pointer assignment*/
  3674. if (p_bmi160 == BMI160_NULL) {
  3675. return E_BMI160_NULL_PTR;
  3676. } else {
  3677. /* select Accel bandwidth*/
  3678. if (v_bw_u8 <= BMI160_MAX_ACCEL_BW) {
  3679. /* write Accel bandwidth*/
  3680. com_rslt =
  3681. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3682. BMI160_USER_ACCEL_CONFIG_ACCEL_BW__REG, &v_data_u8,
  3683. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  3684. if (com_rslt == SUCCESS) {
  3685. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  3686. BMI160_USER_ACCEL_CONFIG_ACCEL_BW,
  3687. v_bw_u8);
  3688. com_rslt +=
  3689. p_bmi160->BMI160_BUS_WRITE_FUNC(
  3690. p_bmi160->dev_addr,
  3691. BMI160_USER_ACCEL_CONFIG_ACCEL_BW__REG,
  3692. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  3693. /*Accel and Gyro power mode check*/
  3694. if (bmi160_power_mode_status_u8_g !=
  3695. BMI160_NORMAL_MODE)
  3696. /*interface idle time delay */
  3697. p_bmi160->delay_msec(
  3698. BMI160_GEN_READ_WRITE_DELAY);
  3699. }
  3700. } else {
  3701. com_rslt = E_BMI160_OUT_OF_RANGE;
  3702. }
  3703. }
  3704. return com_rslt;
  3705. }
  3706. /*!
  3707. * @brief This API is used to get the Accel
  3708. * under sampling parameter from the register 0x40 bit 7
  3709. *
  3710. *
  3711. *
  3712. *
  3713. * @param v_accel_under_sampling_u8 : The value of Accel under sampling
  3714. * value | under_sampling
  3715. * ----------|---------------
  3716. * 0x01 | BMI160_ENABLE
  3717. * 0x00 | BMI160_DISABLE
  3718. *
  3719. *
  3720. *
  3721. * @return results of bus communication function
  3722. * @retval 0 -> Success
  3723. * @retval -1 -> Error
  3724. *
  3725. *
  3726. */
  3727. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_under_sampling_parameter(
  3728. u8 *v_accel_under_sampling_u8)
  3729. {
  3730. /* variable used to return the status of communication result*/
  3731. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3732. u8 v_data_u8 = BMI160_INIT_VALUE;
  3733. /* check the p_bmi160 structure for NULL pointer assignment*/
  3734. if (p_bmi160 == BMI160_NULL) {
  3735. return E_BMI160_NULL_PTR;
  3736. } else {
  3737. /* read the Accel under sampling parameter */
  3738. com_rslt =
  3739. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3740. BMI160_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING__REG,
  3741. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  3742. *v_accel_under_sampling_u8 =
  3743. BMI160_GET_BITSLICE(v_data_u8,
  3744. BMI160_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING);
  3745. }
  3746. return com_rslt;
  3747. }
  3748. /*!
  3749. * @brief This API is used to set the Accel
  3750. * under sampling parameter from the register 0x40 bit 7
  3751. *
  3752. *
  3753. *
  3754. *
  3755. * @param v_accel_under_sampling_u8 : The value of Accel under sampling
  3756. * value | under_sampling
  3757. * ----------|---------------
  3758. * 0x01 | BMI160_ENABLE
  3759. * 0x00 | BMI160_DISABLE
  3760. *
  3761. *
  3762. *
  3763. * @return results of bus communication function
  3764. * @retval 0 -> Success
  3765. * @retval -1 -> Error
  3766. *
  3767. *
  3768. */
  3769. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_under_sampling_parameter(
  3770. u8 v_accel_under_sampling_u8)
  3771. {
  3772. /* variable used to return the status of communication result*/
  3773. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3774. u8 v_data_u8 = BMI160_INIT_VALUE;
  3775. /* check the p_bmi160 structure for NULL pointer assignment*/
  3776. if (p_bmi160 == BMI160_NULL) {
  3777. return E_BMI160_NULL_PTR;
  3778. } else {
  3779. if (v_accel_under_sampling_u8 <= BMI160_MAX_UNDER_SAMPLING) {
  3780. com_rslt =
  3781. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3782. BMI160_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING__REG,
  3783. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  3784. if (com_rslt == SUCCESS) {
  3785. /* write the Accel under sampling parameter */
  3786. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  3787. BMI160_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING,
  3788. v_accel_under_sampling_u8);
  3789. com_rslt +=
  3790. p_bmi160->BMI160_BUS_WRITE_FUNC(
  3791. p_bmi160->dev_addr,
  3792. BMI160_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING__REG,
  3793. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  3794. /*Accel and Gyro power mode check*/
  3795. if (bmi160_power_mode_status_u8_g !=
  3796. BMI160_NORMAL_MODE)
  3797. /*interface idle time delay */
  3798. p_bmi160->delay_msec(
  3799. BMI160_GEN_READ_WRITE_DELAY);
  3800. }
  3801. } else {
  3802. com_rslt = E_BMI160_OUT_OF_RANGE;
  3803. }
  3804. }
  3805. return com_rslt;
  3806. }
  3807. /*!
  3808. * @brief This API is used to get the range
  3809. * (g values) of the Accel from the register 0x41 bit 0 to 3
  3810. *
  3811. *
  3812. *
  3813. *
  3814. * @param v_range_u8 : The value of Accel g range
  3815. * value | g_range
  3816. * ----------|-----------
  3817. * 0x03 | BMI160_ACCEL_RANGE_2G
  3818. * 0x05 | BMI160_ACCEL_RANGE_4G
  3819. * 0x08 | BMI160_ACCEL_RANGE_8G
  3820. * 0x0C | BMI160_ACCEL_RANGE_16G
  3821. *
  3822. *
  3823. *
  3824. * @return results of bus communication function
  3825. * @retval 0 -> Success
  3826. * @retval -1 -> Error
  3827. *
  3828. *
  3829. */
  3830. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_range(
  3831. u8 *v_range_u8)
  3832. {
  3833. /* variable used to return the status of communication result*/
  3834. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3835. u8 v_data_u8 = BMI160_INIT_VALUE;
  3836. /* check the p_bmi160 structure for NULL pointer assignment*/
  3837. if (p_bmi160 == BMI160_NULL) {
  3838. return E_BMI160_NULL_PTR;
  3839. } else {
  3840. /* read the Accel range*/
  3841. com_rslt =
  3842. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3843. BMI160_USER_ACCEL_RANGE__REG, &v_data_u8,
  3844. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  3845. *v_range_u8 = BMI160_GET_BITSLICE(v_data_u8,
  3846. BMI160_USER_ACCEL_RANGE);
  3847. }
  3848. return com_rslt;
  3849. }
  3850. /*!
  3851. * @brief This API is used to set the range
  3852. * (g values) of the Accel from the register 0x41 bit 0 to 3
  3853. *
  3854. *
  3855. *
  3856. *
  3857. * @param v_range_u8 : The value of Accel g range
  3858. * value | g_range
  3859. * ----------|-----------
  3860. * 0x03 | BMI160_ACCEL_RANGE_2G
  3861. * 0x05 | BMI160_ACCEL_RANGE_4G
  3862. * 0x08 | BMI160_ACCEL_RANGE_8G
  3863. * 0x0C | BMI160_ACCEL_RANGE_16G
  3864. *
  3865. *
  3866. *
  3867. * @return results of bus communication function
  3868. * @retval 0 -> Success
  3869. * @retval -1 -> Error
  3870. *
  3871. *
  3872. */
  3873. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_range(u8 v_range_u8)
  3874. {
  3875. /* variable used to return the status of communication result*/
  3876. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3877. u8 v_data_u8 = BMI160_INIT_VALUE;
  3878. /* check the p_bmi160 structure for NULL pointer assignment*/
  3879. if (p_bmi160 == BMI160_NULL) {
  3880. return E_BMI160_NULL_PTR;
  3881. } else {
  3882. if ((v_range_u8 == BMI160_ACCEL_RANGE0) ||
  3883. (v_range_u8 == BMI160_ACCEL_RANGE1) ||
  3884. (v_range_u8 == BMI160_ACCEL_RANGE3) ||
  3885. (v_range_u8 == BMI160_ACCEL_RANGE4)) {
  3886. com_rslt =
  3887. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3888. BMI160_USER_ACCEL_RANGE__REG,
  3889. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  3890. if (com_rslt == SUCCESS) {
  3891. v_data_u8 = BMI160_SET_BITSLICE(
  3892. v_data_u8, BMI160_USER_ACCEL_RANGE,
  3893. v_range_u8);
  3894. /* write the Accel range*/
  3895. com_rslt +=
  3896. p_bmi160->BMI160_BUS_WRITE_FUNC(
  3897. p_bmi160->dev_addr,
  3898. BMI160_USER_ACCEL_RANGE__REG,
  3899. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  3900. /*Accel and Gyro power mode check*/
  3901. if (bmi160_power_mode_status_u8_g !=
  3902. BMI160_NORMAL_MODE)
  3903. /*interface idle time delay */
  3904. p_bmi160->delay_msec(
  3905. BMI160_GEN_READ_WRITE_DELAY);
  3906. }
  3907. } else {
  3908. com_rslt = E_BMI160_OUT_OF_RANGE;
  3909. }
  3910. }
  3911. return com_rslt;
  3912. }
  3913. /*!
  3914. * @brief This API is used to get the
  3915. * Gyro output data rate from the register 0x42 bit 0 to 3
  3916. *
  3917. *
  3918. *
  3919. *
  3920. * @param v_output_data_rate_u8 :The value of gyro output data rate
  3921. * value | gyro output data rate
  3922. * -----------|-----------------------------
  3923. * 0x00 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3924. * 0x01 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3925. * 0x02 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3926. * 0x03 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3927. * 0x04 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3928. * 0x05 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3929. * 0x06 | BMI160_GYRO_OUTPUT_DATA_RATE_25HZ
  3930. * 0x07 | BMI160_GYRO_OUTPUT_DATA_RATE_50HZ
  3931. * 0x08 | BMI160_GYRO_OUTPUT_DATA_RATE_100HZ
  3932. * 0x09 | BMI160_GYRO_OUTPUT_DATA_RATE_200HZ
  3933. * 0x0A | BMI160_GYRO_OUTPUT_DATA_RATE_400HZ
  3934. * 0x0B | BMI160_GYRO_OUTPUT_DATA_RATE_800HZ
  3935. * 0x0C | BMI160_GYRO_OUTPUT_DATA_RATE_1600HZ
  3936. * 0x0D | BMI160_GYRO_OUTPUT_DATA_RATE_3200HZ
  3937. * 0x0E | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3938. * 0x0F | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3939. *
  3940. * @return results of bus communication function
  3941. * @retval 0 -> Success
  3942. * @retval -1 -> Error
  3943. *
  3944. *
  3945. */
  3946. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_output_data_rate(
  3947. u8 *v_output_data_rate_u8)
  3948. {
  3949. /* variable used to return the status of communication result*/
  3950. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3951. u8 v_data_u8 = BMI160_INIT_VALUE;
  3952. /* check the p_bmi160 structure for NULL pointer assignment*/
  3953. if (p_bmi160 == BMI160_NULL) {
  3954. return E_BMI160_NULL_PTR;
  3955. } else {
  3956. /* read the gyro output data rate*/
  3957. com_rslt =
  3958. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3959. BMI160_USER_GYRO_CONFIG_OUTPUT_DATA_RATE__REG,
  3960. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  3961. *v_output_data_rate_u8 = BMI160_GET_BITSLICE(v_data_u8,
  3962. BMI160_USER_GYRO_CONFIG_OUTPUT_DATA_RATE);
  3963. }
  3964. return com_rslt;
  3965. }
  3966. /*!
  3967. * @brief This API is used to set the
  3968. * Gyro output data rate from the register 0x42 bit 0 to 3
  3969. *
  3970. *
  3971. *
  3972. *
  3973. * @param v_output_data_rate_u8 :The value of gyro output data rate
  3974. * value | gyro output data rate
  3975. * -----------|-----------------------------
  3976. * 0x00 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3977. * 0x01 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3978. * 0x02 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3979. * 0x03 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3980. * 0x04 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3981. * 0x05 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3982. * 0x06 | BMI160_GYRO_OUTPUT_DATA_RATE_25HZ
  3983. * 0x07 | BMI160_GYRO_OUTPUT_DATA_RATE_50HZ
  3984. * 0x08 | BMI160_GYRO_OUTPUT_DATA_RATE_100HZ
  3985. * 0x09 | BMI160_GYRO_OUTPUT_DATA_RATE_200HZ
  3986. * 0x0A | BMI160_GYRO_OUTPUT_DATA_RATE_400HZ
  3987. * 0x0B | BMI160_GYRO_OUTPUT_DATA_RATE_800HZ
  3988. * 0x0C | BMI160_GYRO_OUTPUT_DATA_RATE_1600HZ
  3989. * 0x0D | BMI160_GYRO_OUTPUT_DATA_RATE_3200HZ
  3990. * 0x0E | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3991. * 0x0F | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3992. *
  3993. * @return results of bus communication function
  3994. * @retval 0 -> Success
  3995. * @retval -1 -> Error
  3996. *
  3997. *
  3998. */
  3999. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_output_data_rate(
  4000. u8 v_output_data_rate_u8)
  4001. {
  4002. /* variable used to return the status of communication result*/
  4003. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4004. u8 v_data_u8 = BMI160_INIT_VALUE;
  4005. /* check the p_bmi160 structure for NULL pointer assignment*/
  4006. if (p_bmi160 == BMI160_NULL) {
  4007. return E_BMI160_NULL_PTR;
  4008. } else {
  4009. /* select the gyro output data rate*/
  4010. if ((v_output_data_rate_u8 < BMI160_OUTPUT_DATA_RATE6) &&
  4011. (v_output_data_rate_u8 != BMI160_INIT_VALUE)
  4012. && (v_output_data_rate_u8 != BMI160_OUTPUT_DATA_RATE1)
  4013. && (v_output_data_rate_u8 != BMI160_OUTPUT_DATA_RATE2)
  4014. && (v_output_data_rate_u8 != BMI160_OUTPUT_DATA_RATE3)
  4015. && (v_output_data_rate_u8 != BMI160_OUTPUT_DATA_RATE4)
  4016. && (v_output_data_rate_u8 != BMI160_OUTPUT_DATA_RATE5)
  4017. && (v_output_data_rate_u8 != BMI160_OUTPUT_DATA_RATE6)
  4018. && (v_output_data_rate_u8 != BMI160_OUTPUT_DATA_RATE7)) {
  4019. /* write the gyro output data rate */
  4020. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  4021. (p_bmi160->dev_addr,
  4022. BMI160_USER_GYRO_CONFIG_OUTPUT_DATA_RATE__REG,
  4023. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4024. if (com_rslt == SUCCESS) {
  4025. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  4026. BMI160_USER_GYRO_CONFIG_OUTPUT_DATA_RATE,
  4027. v_output_data_rate_u8);
  4028. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  4029. (p_bmi160->dev_addr,
  4030. BMI160_USER_GYRO_CONFIG_OUTPUT_DATA_RATE__REG,
  4031. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4032. /*Accel and Gyro power mode check*/
  4033. if (bmi160_power_mode_status_u8_g !=
  4034. BMI160_NORMAL_MODE)
  4035. /*interface idle time delay */
  4036. p_bmi160->delay_msec(
  4037. BMI160_GEN_READ_WRITE_DELAY);
  4038. }
  4039. } else {
  4040. com_rslt = E_BMI160_OUT_OF_RANGE;
  4041. }
  4042. }
  4043. return com_rslt;
  4044. }
  4045. /*!
  4046. * @brief This API is used to get the
  4047. * bandwidth of gyro from the register 0x42 bit 4 to 5
  4048. *
  4049. *
  4050. *
  4051. *
  4052. * @param v_bw_u8 : The value of gyro bandwidth
  4053. * value | gyro bandwidth
  4054. * ----------|----------------
  4055. * 0x00 | BMI160_GYRO_OSR4_MODE
  4056. * 0x01 | BMI160_GYRO_OSR2_MODE
  4057. * 0x02 | BMI160_GYRO_NORMAL_MODE
  4058. * 0x03 | BMI160_GYRO_CIC_MODE
  4059. *
  4060. *
  4061. * @return results of bus communication function
  4062. * @retval 0 -> Success
  4063. * @retval -1 -> Error
  4064. *
  4065. *
  4066. */
  4067. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_bw(u8 *v_bw_u8)
  4068. {
  4069. /* variable used to return the status of communication result*/
  4070. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4071. u8 v_data_u8 = BMI160_INIT_VALUE;
  4072. /* check the p_bmi160 structure for NULL pointer assignment*/
  4073. if (p_bmi160 == BMI160_NULL) {
  4074. return E_BMI160_NULL_PTR;
  4075. } else {
  4076. /* read gyro bandwidth*/
  4077. com_rslt =
  4078. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4079. BMI160_USER_GYRO_CONFIG_BW__REG, &v_data_u8,
  4080. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4081. *v_bw_u8 = BMI160_GET_BITSLICE(v_data_u8,
  4082. BMI160_USER_GYRO_CONFIG_BW);
  4083. }
  4084. return com_rslt;
  4085. }
  4086. /*!
  4087. * @brief This API is used to set the
  4088. * bandwidth of gyro from the register 0x42 bit 4 to 5
  4089. *
  4090. *
  4091. *
  4092. *
  4093. * @param v_bw_u8 : The value of gyro bandwidth
  4094. * value | gyro bandwidth
  4095. * ----------|----------------
  4096. * 0x00 | BMI160_GYRO_OSR4_MODE
  4097. * 0x01 | BMI160_GYRO_OSR2_MODE
  4098. * 0x02 | BMI160_GYRO_NORMAL_MODE
  4099. * 0x03 | BMI160_GYRO_CIC_MODE
  4100. *
  4101. *
  4102. * @return results of bus communication function
  4103. * @retval 0 -> Success
  4104. * @retval -1 -> Error
  4105. *
  4106. *
  4107. */
  4108. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_bw(u8 v_bw_u8)
  4109. {
  4110. /* variable used to return the status of communication result*/
  4111. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4112. u8 v_data_u8 = BMI160_INIT_VALUE;
  4113. /* check the p_bmi160 structure for NULL pointer assignment*/
  4114. if (p_bmi160 == BMI160_NULL) {
  4115. return E_BMI160_NULL_PTR;
  4116. } else {
  4117. if (v_bw_u8 <= BMI160_MAX_GYRO_BW) {
  4118. /* write the gyro bandwidth*/
  4119. com_rslt =
  4120. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4121. BMI160_USER_GYRO_CONFIG_BW__REG,
  4122. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4123. if (com_rslt == SUCCESS) {
  4124. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  4125. BMI160_USER_GYRO_CONFIG_BW, v_bw_u8);
  4126. com_rslt +=
  4127. p_bmi160->BMI160_BUS_WRITE_FUNC(
  4128. p_bmi160->dev_addr,
  4129. BMI160_USER_GYRO_CONFIG_BW__REG,
  4130. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4131. /*Accel and Gyro power mode check*/
  4132. if (bmi160_power_mode_status_u8_g !=
  4133. BMI160_NORMAL_MODE)
  4134. /*interface idle time delay */
  4135. p_bmi160->delay_msec(
  4136. BMI160_GEN_READ_WRITE_DELAY);
  4137. }
  4138. } else {
  4139. com_rslt = E_BMI160_OUT_OF_RANGE;
  4140. }
  4141. }
  4142. return com_rslt;
  4143. }
  4144. /*!
  4145. * @brief This API reads the range
  4146. * of gyro from the register 0x43 bit 0 to 2
  4147. *
  4148. * @param v_range_u8 : The value of gyro range
  4149. * value | range
  4150. * ----------|-------------------------------
  4151. * 0x00 | BMI160_GYRO_RANGE_2000_DEG_SEC
  4152. * 0x01 | BMI160_GYRO_RANGE_1000_DEG_SEC
  4153. * 0x02 | BMI160_GYRO_RANGE_500_DEG_SEC
  4154. * 0x03 | BMI160_GYRO_RANGE_250_DEG_SEC
  4155. * 0x04 | BMI160_GYRO_RANGE_125_DEG_SEC
  4156. *
  4157. * @return results of bus communication function
  4158. * @retval 0 -> Success
  4159. * @retval -1 -> Error
  4160. *
  4161. *
  4162. */
  4163. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_range(u8 *v_range_u8)
  4164. {
  4165. /* variable used to return the status of communication result*/
  4166. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4167. u8 v_data_u8 = BMI160_INIT_VALUE;
  4168. /* check the p_bmi160 structure for NULL pointer assignment*/
  4169. if (p_bmi160 == BMI160_NULL) {
  4170. return E_BMI160_NULL_PTR;
  4171. } else {
  4172. /* read the gyro range */
  4173. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  4174. (p_bmi160->dev_addr,
  4175. BMI160_USER_GYRO_RANGE__REG,
  4176. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4177. *v_range_u8 =
  4178. BMI160_GET_BITSLICE(v_data_u8,
  4179. BMI160_USER_GYRO_RANGE);
  4180. }
  4181. return com_rslt;
  4182. }
  4183. /*!
  4184. * @brief This API sets the range
  4185. * of gyro from the register 0x43 bit 0 to 2
  4186. *
  4187. * @param v_range_u8 : The value of gyro range
  4188. * value | range
  4189. * ----------|-------------------------------
  4190. * 0x00 | BMI160_GYRO_RANGE_2000_DEG_SEC
  4191. * 0x01 | BMI160_GYRO_RANGE_1000_DEG_SEC
  4192. * 0x02 | BMI160_GYRO_RANGE_500_DEG_SEC
  4193. * 0x03 | BMI160_GYRO_RANGE_250_DEG_SEC
  4194. * 0x04 | BMI160_GYRO_RANGE_125_DEG_SEC
  4195. *
  4196. * @return results of bus communication function
  4197. * @retval 0 -> Success
  4198. * @retval -1 -> Error
  4199. *
  4200. *
  4201. */
  4202. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_range(u8 v_range_u8)
  4203. {
  4204. /* variable used to return the status of communication result*/
  4205. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4206. u8 v_data_u8 = BMI160_INIT_VALUE;
  4207. /* check the p_bmi160 structure for NULL pointer assignment*/
  4208. if (p_bmi160 == BMI160_NULL) {
  4209. return E_BMI160_NULL_PTR;
  4210. } else {
  4211. if (v_range_u8 <= BMI160_MAX_GYRO_RANGE) {
  4212. /* write the gyro range value */
  4213. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  4214. (p_bmi160->dev_addr,
  4215. BMI160_USER_GYRO_RANGE__REG,
  4216. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4217. if (com_rslt == SUCCESS) {
  4218. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  4219. BMI160_USER_GYRO_RANGE,
  4220. v_range_u8);
  4221. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  4222. (p_bmi160->dev_addr,
  4223. BMI160_USER_GYRO_RANGE__REG,
  4224. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4225. /*Accel and Gyro power mode check*/
  4226. if (bmi160_power_mode_status_u8_g !=
  4227. BMI160_NORMAL_MODE)
  4228. /*interface idle time delay */
  4229. p_bmi160->delay_msec(
  4230. BMI160_GEN_READ_WRITE_DELAY);
  4231. }
  4232. } else {
  4233. com_rslt = E_BMI160_OUT_OF_RANGE;
  4234. }
  4235. }
  4236. return com_rslt;
  4237. }
  4238. /*!
  4239. * @brief This API is used to get the
  4240. * output data rate of Mag from the register 0x44 bit 0 to 3
  4241. *
  4242. *
  4243. *
  4244. *
  4245. * @param v_output_data_rate_u8 : The value of Mag output data rate
  4246. * value | Mag output data rate
  4247. * ---------|---------------------------
  4248. * 0x00 |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED
  4249. * 0x01 |BMI160_MAG_OUTPUT_DATA_RATE_0_78HZ
  4250. * 0x02 |BMI160_MAG_OUTPUT_DATA_RATE_1_56HZ
  4251. * 0x03 |BMI160_MAG_OUTPUT_DATA_RATE_3_12HZ
  4252. * 0x04 |BMI160_MAG_OUTPUT_DATA_RATE_6_25HZ
  4253. * 0x05 |BMI160_MAG_OUTPUT_DATA_RATE_12_5HZ
  4254. * 0x06 |BMI160_MAG_OUTPUT_DATA_RATE_25HZ
  4255. * 0x07 |BMI160_MAG_OUTPUT_DATA_RATE_50HZ
  4256. * 0x08 |BMI160_MAG_OUTPUT_DATA_RATE_100HZ
  4257. * 0x09 |BMI160_MAG_OUTPUT_DATA_RATE_200HZ
  4258. * 0x0A |BMI160_MAG_OUTPUT_DATA_RATE_400HZ
  4259. * 0x0B |BMI160_MAG_OUTPUT_DATA_RATE_800HZ
  4260. * 0x0C |BMI160_MAG_OUTPUT_DATA_RATE_1600HZ
  4261. * 0x0D |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED0
  4262. * 0x0E |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED1
  4263. * 0x0F |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED2
  4264. *
  4265. *
  4266. *
  4267. * @return results of bus communication function
  4268. * @retval 0 -> Success
  4269. * @retval -1 -> Error
  4270. *
  4271. *
  4272. */
  4273. BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_output_data_rate(
  4274. u8 *v_output_data_rate_u8)
  4275. {
  4276. /* variable used to return the status of communication result*/
  4277. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4278. u8 v_data_u8 = BMI160_INIT_VALUE;
  4279. /* check the p_bmi160 structure for NULL pointer assignment*/
  4280. if (p_bmi160 == BMI160_NULL) {
  4281. return E_BMI160_NULL_PTR;
  4282. } else {
  4283. /* read the Mag data output rate*/
  4284. com_rslt =
  4285. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4286. BMI160_USER_MAG_CONFIG_OUTPUT_DATA_RATE__REG,
  4287. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4288. *v_output_data_rate_u8 = BMI160_GET_BITSLICE(v_data_u8,
  4289. BMI160_USER_MAG_CONFIG_OUTPUT_DATA_RATE);
  4290. }
  4291. return com_rslt;
  4292. }
  4293. /*!
  4294. * @brief This API is used to set the
  4295. * output data rate of Mag from the register 0x44 bit 0 to 3
  4296. *
  4297. *
  4298. *
  4299. *
  4300. * @param v_output_data_rate_u8 : The value of Mag output data rate
  4301. * value | Mag output data rate
  4302. * ---------|---------------------------
  4303. * 0x00 |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED
  4304. * 0x01 |BMI160_MAG_OUTPUT_DATA_RATE_0_78HZ
  4305. * 0x02 |BMI160_MAG_OUTPUT_DATA_RATE_1_56HZ
  4306. * 0x03 |BMI160_MAG_OUTPUT_DATA_RATE_3_12HZ
  4307. * 0x04 |BMI160_MAG_OUTPUT_DATA_RATE_6_25HZ
  4308. * 0x05 |BMI160_MAG_OUTPUT_DATA_RATE_12_5HZ
  4309. * 0x06 |BMI160_MAG_OUTPUT_DATA_RATE_25HZ
  4310. * 0x07 |BMI160_MAG_OUTPUT_DATA_RATE_50HZ
  4311. * 0x08 |BMI160_MAG_OUTPUT_DATA_RATE_100HZ
  4312. * 0x09 |BMI160_MAG_OUTPUT_DATA_RATE_200HZ
  4313. * 0x0A |BMI160_MAG_OUTPUT_DATA_RATE_400HZ
  4314. * 0x0B |BMI160_MAG_OUTPUT_DATA_RATE_800HZ
  4315. * 0x0C |BMI160_MAG_OUTPUT_DATA_RATE_1600HZ
  4316. * 0x0D |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED0
  4317. * 0x0E |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED1
  4318. * 0x0F |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED2
  4319. *
  4320. *
  4321. *
  4322. * @return results of bus communication function
  4323. * @retval 0 -> Success
  4324. * @retval -1 -> Error
  4325. *
  4326. *
  4327. */
  4328. BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_output_data_rate(
  4329. u8 v_output_data_rate_u8)
  4330. {
  4331. /* variable used to return the status of communication result*/
  4332. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4333. u8 v_data_u8 = BMI160_INIT_VALUE;
  4334. /* check the p_bmi160 structure for NULL pointer assignment*/
  4335. if (p_bmi160 == BMI160_NULL) {
  4336. return E_BMI160_NULL_PTR;
  4337. } else {
  4338. /* select the Mag data output rate*/
  4339. if ((v_output_data_rate_u8
  4340. <= BMI160_MAX_ACCEL_OUTPUT_DATA_RATE)
  4341. && (v_output_data_rate_u8
  4342. != BMI160_OUTPUT_DATA_RATE0)
  4343. && (v_output_data_rate_u8
  4344. != BMI160_OUTPUT_DATA_RATE6)
  4345. && (v_output_data_rate_u8
  4346. != BMI160_OUTPUT_DATA_RATE7)) {
  4347. /* write the Mag data output rate*/
  4348. com_rslt =
  4349. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4350. BMI160_USER_MAG_CONFIG_OUTPUT_DATA_RATE__REG,
  4351. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4352. if (com_rslt == SUCCESS) {
  4353. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  4354. BMI160_USER_MAG_CONFIG_OUTPUT_DATA_RATE,
  4355. v_output_data_rate_u8);
  4356. com_rslt +=
  4357. p_bmi160->BMI160_BUS_WRITE_FUNC(
  4358. p_bmi160->dev_addr,
  4359. BMI160_USER_MAG_CONFIG_OUTPUT_DATA_RATE__REG,
  4360. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4361. /*Accel and Gyro power mode check*/
  4362. if (bmi160_power_mode_status_u8_g !=
  4363. BMI160_NORMAL_MODE)
  4364. /*interface idle time delay */
  4365. p_bmi160->delay_msec(
  4366. BMI160_GEN_READ_WRITE_DELAY);
  4367. }
  4368. } else {
  4369. com_rslt = E_BMI160_OUT_OF_RANGE;
  4370. }
  4371. }
  4372. return com_rslt;
  4373. }
  4374. #ifdef FIFO_ENABLE
  4375. /*!
  4376. * @brief This API is used to read Down sampling
  4377. * for gyro (2**downs_gyro) in the register 0x45 bit 0 to 2
  4378. *
  4379. *
  4380. *
  4381. *
  4382. * @param v_fifo_down_gyro_u8 :The value of gyro FIFO down
  4383. *
  4384. *
  4385. * @return results of bus communication function
  4386. * @retval 0 -> Success
  4387. * @retval -1 -> Error
  4388. *
  4389. *
  4390. */
  4391. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_down_gyro(
  4392. u8 *v_fifo_down_gyro_u8)
  4393. {
  4394. /* variable used to return the status of communication result*/
  4395. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4396. u8 v_data_u8 = BMI160_INIT_VALUE;
  4397. /* check the p_bmi160 structure for NULL pointer assignment*/
  4398. if (p_bmi160 == BMI160_NULL) {
  4399. return E_BMI160_NULL_PTR;
  4400. } else {
  4401. /* read the gyro FIFO down*/
  4402. com_rslt =
  4403. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4404. BMI160_USER_FIFO_DOWN_GYRO__REG,
  4405. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4406. *v_fifo_down_gyro_u8 = BMI160_GET_BITSLICE(v_data_u8,
  4407. BMI160_USER_FIFO_DOWN_GYRO);
  4408. }
  4409. return com_rslt;
  4410. }
  4411. /*!
  4412. * @brief This API is used to set Down sampling
  4413. * for gyro (2**downs_gyro) in the register 0x45 bit 0 to 2
  4414. *
  4415. *
  4416. *
  4417. *
  4418. * @param v_fifo_down_gyro_u8 :The value of gyro FIFO down
  4419. *
  4420. *
  4421. * @return results of bus communication function
  4422. * @retval 0 -> Success
  4423. * @retval -1 -> Error
  4424. *
  4425. *
  4426. */
  4427. BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_down_gyro(
  4428. u8 v_fifo_down_gyro_u8)
  4429. {
  4430. /* variable used to return the status of communication result*/
  4431. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4432. u8 v_data_u8 = BMI160_INIT_VALUE;
  4433. /* check the p_bmi160 structure for NULL pointer assignment*/
  4434. if (p_bmi160 == BMI160_NULL) {
  4435. return E_BMI160_NULL_PTR;
  4436. } else {
  4437. /* write the gyro FIFO down*/
  4438. com_rslt =
  4439. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4440. BMI160_USER_FIFO_DOWN_GYRO__REG,
  4441. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4442. if (com_rslt == SUCCESS) {
  4443. v_data_u8 = BMI160_SET_BITSLICE(
  4444. v_data_u8,
  4445. BMI160_USER_FIFO_DOWN_GYRO,
  4446. v_fifo_down_gyro_u8);
  4447. com_rslt +=
  4448. p_bmi160->BMI160_BUS_WRITE_FUNC(
  4449. p_bmi160->dev_addr,
  4450. BMI160_USER_FIFO_DOWN_GYRO__REG,
  4451. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4452. }
  4453. }
  4454. return com_rslt;
  4455. }
  4456. /*!
  4457. * @brief This API is used to read gyro FIFO filter data
  4458. * from the register 0x45 bit 3
  4459. *
  4460. *
  4461. *
  4462. * @param v_gyro_fifo_filter_data_u8 :The value of gyro filter data
  4463. * value | gyro_fifo_filter_data
  4464. * ------------|-------------------------
  4465. * 0x00 | Unfiltered data
  4466. * 0x01 | Filtered data
  4467. *
  4468. * @return results of bus communication function
  4469. * @retval 0 -> Success
  4470. * @retval -1 -> Error
  4471. *
  4472. *
  4473. */
  4474. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_fifo_filter_data(
  4475. u8 *v_gyro_fifo_filter_data_u8)
  4476. {
  4477. /* variable used to return the status of communication result*/
  4478. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4479. u8 v_data_u8 = BMI160_INIT_VALUE;
  4480. /* check the p_bmi160 structure for NULL pointer assignment*/
  4481. if (p_bmi160 == BMI160_NULL) {
  4482. return E_BMI160_NULL_PTR;
  4483. } else {
  4484. /* read the gyro FIFO filter data */
  4485. com_rslt =
  4486. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4487. BMI160_USER_FIFO_FILTER_GYRO__REG, &v_data_u8,
  4488. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4489. *v_gyro_fifo_filter_data_u8 =
  4490. BMI160_GET_BITSLICE(v_data_u8,
  4491. BMI160_USER_FIFO_FILTER_GYRO);
  4492. }
  4493. return com_rslt;
  4494. }
  4495. /*!
  4496. * @brief This API is used to set gyro FIFO filter data
  4497. * from the register 0x45 bit 3
  4498. *
  4499. *
  4500. *
  4501. * @param v_gyro_fifo_filter_data_u8 :The value of gyro filter data
  4502. * value | gyro_fifo_filter_data
  4503. * ------------|-------------------------
  4504. * 0x00 | Unfiltered data
  4505. * 0x01 | Filtered data
  4506. *
  4507. * @return results of bus communication function
  4508. * @retval 0 -> Success
  4509. * @retval -1 -> Error
  4510. *
  4511. *
  4512. */
  4513. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_fifo_filter_data(
  4514. u8 v_gyro_fifo_filter_data_u8)
  4515. {
  4516. /* variable used to return the status of communication result*/
  4517. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4518. u8 v_data_u8 = BMI160_INIT_VALUE;
  4519. /* check the p_bmi160 structure for NULL pointer assignment*/
  4520. if (p_bmi160 == BMI160_NULL) {
  4521. return E_BMI160_NULL_PTR;
  4522. } else {
  4523. if (v_gyro_fifo_filter_data_u8
  4524. <= BMI160_MAX_VALUE_FIFO_FILTER) {
  4525. /* write the gyro FIFO filter data */
  4526. com_rslt =
  4527. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4528. BMI160_USER_FIFO_FILTER_GYRO__REG,
  4529. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4530. if (com_rslt == SUCCESS) {
  4531. v_data_u8 = BMI160_SET_BITSLICE(
  4532. v_data_u8,
  4533. BMI160_USER_FIFO_FILTER_GYRO,
  4534. v_gyro_fifo_filter_data_u8);
  4535. com_rslt +=
  4536. p_bmi160->BMI160_BUS_WRITE_FUNC(
  4537. p_bmi160->dev_addr,
  4538. BMI160_USER_FIFO_FILTER_GYRO__REG,
  4539. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4540. }
  4541. } else {
  4542. com_rslt = E_BMI160_OUT_OF_RANGE;
  4543. }
  4544. }
  4545. return com_rslt;
  4546. }
  4547. /*!
  4548. * @brief This API is used to read Down sampling
  4549. * for Accel (2*downs_accel) from the register 0x45 bit 4 to 6
  4550. *
  4551. *
  4552. *
  4553. *
  4554. * @param v_fifo_down_u8 :The value of Accel FIFO down
  4555. *
  4556. *
  4557. *
  4558. * @return results of bus communication function
  4559. * @retval 0 -> Success
  4560. * @retval -1 -> Error
  4561. *
  4562. *
  4563. */
  4564. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_down_accel(
  4565. u8 *v_fifo_down_u8)
  4566. {
  4567. /* variable used to return the status of communication result*/
  4568. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4569. u8 v_data_u8 = BMI160_INIT_VALUE;
  4570. /* check the p_bmi160 structure for NULL pointer assignment*/
  4571. if (p_bmi160 == BMI160_NULL) {
  4572. return E_BMI160_NULL_PTR;
  4573. } else {
  4574. /* read the Accel FIFO down data */
  4575. com_rslt =
  4576. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4577. BMI160_USER_FIFO_DOWN_ACCEL__REG, &v_data_u8,
  4578. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4579. *v_fifo_down_u8 = BMI160_GET_BITSLICE(v_data_u8,
  4580. BMI160_USER_FIFO_DOWN_ACCEL);
  4581. }
  4582. return com_rslt;
  4583. }
  4584. /*!
  4585. * @brief This API is used to set Down sampling
  4586. * for Accel (2*downs_accel) from the register 0x45 bit 4 to 6
  4587. *
  4588. *
  4589. *
  4590. *
  4591. * @param v_fifo_down_u8 :The value of Accel FIFO down
  4592. *
  4593. *
  4594. *
  4595. * @return results of bus communication function
  4596. * @retval 0 -> Success
  4597. * @retval -1 -> Error
  4598. *
  4599. *
  4600. */
  4601. BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_down_accel(
  4602. u8 v_fifo_down_u8)
  4603. {
  4604. /* variable used to return the status of communication result*/
  4605. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4606. u8 v_data_u8 = BMI160_INIT_VALUE;
  4607. /* check the p_bmi160 structure for NULL pointer assignment*/
  4608. if (p_bmi160 == BMI160_NULL) {
  4609. return E_BMI160_NULL_PTR;
  4610. } else {
  4611. /* write the Accel FIFO down data */
  4612. com_rslt =
  4613. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4614. BMI160_USER_FIFO_DOWN_ACCEL__REG, &v_data_u8,
  4615. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4616. if (com_rslt == SUCCESS) {
  4617. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  4618. BMI160_USER_FIFO_DOWN_ACCEL, v_fifo_down_u8);
  4619. com_rslt +=
  4620. p_bmi160->BMI160_BUS_WRITE_FUNC(
  4621. p_bmi160->dev_addr,
  4622. BMI160_USER_FIFO_DOWN_ACCEL__REG,
  4623. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4624. }
  4625. }
  4626. return com_rslt;
  4627. }
  4628. /*!
  4629. * @brief This API is used to read Accel FIFO filter data
  4630. * from the register 0x45 bit 7
  4631. *
  4632. *
  4633. *
  4634. * @param accel_fifo_filter_u8 :The value of Accel filter data
  4635. * value | accel_fifo_filter_u8
  4636. * ------------|-------------------------
  4637. * 0x00 | Unfiltered data
  4638. * 0x01 | Filtered data
  4639. *
  4640. *
  4641. * @return results of bus communication function
  4642. * @retval 0 -> Success
  4643. * @retval -1 -> Error
  4644. *
  4645. *
  4646. */
  4647. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_fifo_filter_data(
  4648. u8 *accel_fifo_filter_u8)
  4649. {
  4650. /* variable used to return the status of communication result*/
  4651. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4652. u8 v_data_u8 = BMI160_INIT_VALUE;
  4653. /* check the p_bmi160 structure for NULL pointer assignment*/
  4654. if (p_bmi160 == BMI160_NULL) {
  4655. return E_BMI160_NULL_PTR;
  4656. } else {
  4657. /* read the Accel FIFO filter data */
  4658. com_rslt =
  4659. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4660. BMI160_USER_FIFO_FILTER_ACCEL__REG, &v_data_u8,
  4661. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4662. *accel_fifo_filter_u8 = BMI160_GET_BITSLICE(v_data_u8,
  4663. BMI160_USER_FIFO_FILTER_ACCEL);
  4664. }
  4665. return com_rslt;
  4666. }
  4667. /*!
  4668. * @brief This API is used to set Accel FIFO filter data
  4669. * from the register 0x45 bit 7
  4670. *
  4671. *
  4672. *
  4673. * @param v_accel_fifo_filter_u8 :The value of Accel filter data
  4674. * value | accel_fifo_filter_data
  4675. * ------------|-------------------------
  4676. * 0x00 | Unfiltered data
  4677. * 0x01 | Filtered data
  4678. *
  4679. *
  4680. * @return results of bus communication function
  4681. * @retval 0 -> Success
  4682. * @retval -1 -> Error
  4683. *
  4684. *
  4685. */
  4686. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_fifo_filter_data(
  4687. u8 v_accel_fifo_filter_u8)
  4688. {
  4689. /* variable used to return the status of communication result*/
  4690. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4691. u8 v_data_u8 = BMI160_INIT_VALUE;
  4692. /* check the p_bmi160 structure for NULL pointer assignment*/
  4693. if (p_bmi160 == BMI160_NULL) {
  4694. return E_BMI160_NULL_PTR;
  4695. } else {
  4696. if (v_accel_fifo_filter_u8 <= BMI160_MAX_VALUE_FIFO_FILTER) {
  4697. com_rslt =
  4698. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4699. BMI160_USER_FIFO_FILTER_ACCEL__REG,
  4700. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4701. if (com_rslt == SUCCESS) {
  4702. /* write Accel FIFO filter data */
  4703. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  4704. BMI160_USER_FIFO_FILTER_ACCEL,
  4705. v_accel_fifo_filter_u8);
  4706. com_rslt +=
  4707. p_bmi160->BMI160_BUS_WRITE_FUNC(
  4708. p_bmi160->dev_addr,
  4709. BMI160_USER_FIFO_FILTER_ACCEL__REG,
  4710. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4711. }
  4712. } else {
  4713. com_rslt = E_BMI160_OUT_OF_RANGE;
  4714. }
  4715. }
  4716. return com_rslt;
  4717. }
  4718. /*!
  4719. * @brief This API is used to Trigger an interrupt
  4720. * when FIFO contains water mark level from the register 0x46 bit 0 to 7
  4721. *
  4722. *
  4723. *
  4724. * @param v_fifo_wm_u8 : The value of FIFO water mark level
  4725. *
  4726. *
  4727. *
  4728. * @return results of bus communication function
  4729. * @retval 0 -> Success
  4730. * @retval -1 -> Error
  4731. *
  4732. *
  4733. */
  4734. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_wm(
  4735. u8 *v_fifo_wm_u8)
  4736. {
  4737. /* variable used to return the status of communication result*/
  4738. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4739. u8 v_data_u8 = BMI160_INIT_VALUE;
  4740. /* check the p_bmi160 structure for NULL pointer assignment*/
  4741. if (p_bmi160 == BMI160_NULL) {
  4742. return E_BMI160_NULL_PTR;
  4743. } else {
  4744. /* read the FIFO water mark level*/
  4745. com_rslt =
  4746. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4747. BMI160_USER_FIFO_WM__REG,
  4748. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4749. *v_fifo_wm_u8 = BMI160_GET_BITSLICE(v_data_u8,
  4750. BMI160_USER_FIFO_WM);
  4751. }
  4752. return com_rslt;
  4753. }
  4754. /*!
  4755. * @brief This API is used to Trigger an interrupt
  4756. * when FIFO contains water mark level from the register 0x46 bit 0 to 7
  4757. *
  4758. *
  4759. *
  4760. * @param v_fifo_wm_u8 : The value of FIFO water mark level
  4761. *
  4762. *
  4763. *
  4764. * @return results of bus communication function
  4765. * @retval 0 -> Success
  4766. * @retval -1 -> Error
  4767. *
  4768. *
  4769. */
  4770. BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_wm(
  4771. u8 v_fifo_wm_u8)
  4772. {
  4773. /* variable used to return the status of communication result*/
  4774. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4775. /* check the p_bmi160 structure for NULL pointer assignment*/
  4776. if (p_bmi160 == BMI160_NULL) {
  4777. return E_BMI160_NULL_PTR;
  4778. } else {
  4779. /* write the FIFO water mark level*/
  4780. com_rslt =
  4781. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->dev_addr,
  4782. BMI160_USER_FIFO_WM__REG,
  4783. &v_fifo_wm_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4784. }
  4785. return com_rslt;
  4786. }
  4787. /*!
  4788. * @brief This API reads FIFO sensor time
  4789. * frame after the last valid data frame from the register 0x47 bit 1
  4790. *
  4791. *
  4792. *
  4793. *
  4794. * @param v_fifo_time_enable_u8 : The value of sensor time
  4795. * value | FIFO sensor time
  4796. * ------------|-------------------------
  4797. * 0x00 | do not return sensortime frame
  4798. * 0x01 | return sensortime frame
  4799. *
  4800. * @return results of bus communication function
  4801. * @retval 0 -> Success
  4802. * @retval -1 -> Error
  4803. *
  4804. *
  4805. */
  4806. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_time_enable(
  4807. u8 *v_fifo_time_enable_u8)
  4808. {
  4809. /* variable used to return the status of communication result*/
  4810. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4811. u8 v_data_u8 = BMI160_INIT_VALUE;
  4812. /* check the p_bmi160 structure for NULL pointer assignment*/
  4813. if (p_bmi160 == BMI160_NULL) {
  4814. return E_BMI160_NULL_PTR;
  4815. } else {
  4816. /* read the FIFO sensor time*/
  4817. com_rslt =
  4818. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4819. BMI160_USER_FIFO_TIME_ENABLE__REG, &v_data_u8,
  4820. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4821. *v_fifo_time_enable_u8 = BMI160_GET_BITSLICE(v_data_u8,
  4822. BMI160_USER_FIFO_TIME_ENABLE);
  4823. }
  4824. return com_rslt;
  4825. }
  4826. /*!
  4827. * @brief This API sets FIFO sensor time
  4828. * frame after the last valid data frame from the register 0x47 bit 1
  4829. *
  4830. *
  4831. *
  4832. *
  4833. * @param v_fifo_time_enable_u8 : The value of sensor time
  4834. * value | FIFO sensor time
  4835. * ------------|-------------------------
  4836. * 0x00 | do not return sensortime frame
  4837. * 0x01 | return sensortime frame
  4838. *
  4839. * @return results of bus communication function
  4840. * @retval 0 -> Success
  4841. * @retval -1 -> Error
  4842. *
  4843. *
  4844. */
  4845. BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_time_enable(
  4846. u8 v_fifo_time_enable_u8)
  4847. {
  4848. /* variable used to return the status of communication result*/
  4849. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4850. u8 v_data_u8 = BMI160_INIT_VALUE;
  4851. /* check the p_bmi160 structure for NULL pointer assignment*/
  4852. if (p_bmi160 == BMI160_NULL) {
  4853. return E_BMI160_NULL_PTR;
  4854. } else {
  4855. if (v_fifo_time_enable_u8 <= BMI160_MAX_VALUE_FIFO_TIME) {
  4856. /* write the FIFO sensor time*/
  4857. com_rslt =
  4858. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4859. BMI160_USER_FIFO_TIME_ENABLE__REG, &v_data_u8,
  4860. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4861. if (com_rslt == SUCCESS) {
  4862. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  4863. BMI160_USER_FIFO_TIME_ENABLE,
  4864. v_fifo_time_enable_u8);
  4865. com_rslt +=
  4866. p_bmi160->BMI160_BUS_WRITE_FUNC(
  4867. p_bmi160->dev_addr,
  4868. BMI160_USER_FIFO_TIME_ENABLE__REG,
  4869. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4870. }
  4871. } else {
  4872. com_rslt = E_BMI160_OUT_OF_RANGE;
  4873. }
  4874. }
  4875. return com_rslt;
  4876. }
  4877. /*!
  4878. * @brief This API reads FIFO tag interrupt2 enable status
  4879. * from the register 0x47 bit 2
  4880. *
  4881. * @param v_fifo_tag_intr2_u8 : The value of FIFO tag interrupt
  4882. * value | FIFO tag interrupt
  4883. * ----------|-------------------
  4884. * 0x01 | BMI160_ENABLE
  4885. * 0x00 | BMI160_DISABLE
  4886. *
  4887. *
  4888. *
  4889. *
  4890. * @return results of bus communication function
  4891. * @retval 0 -> Success
  4892. * @retval -1 -> Error
  4893. *
  4894. *
  4895. */
  4896. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_tag_intr2_enable(
  4897. u8 *v_fifo_tag_intr2_u8)
  4898. {
  4899. /* variable used to return the status of communication result*/
  4900. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4901. u8 v_data_u8 = BMI160_INIT_VALUE;
  4902. /* check the p_bmi160 structure for NULL pointer assignment*/
  4903. if (p_bmi160 == BMI160_NULL) {
  4904. return E_BMI160_NULL_PTR;
  4905. } else {
  4906. /* read the FIFO tag interrupt2*/
  4907. com_rslt =
  4908. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4909. BMI160_USER_FIFO_TAG_INTR2_ENABLE__REG, &v_data_u8,
  4910. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4911. *v_fifo_tag_intr2_u8 = BMI160_GET_BITSLICE(v_data_u8,
  4912. BMI160_USER_FIFO_TAG_INTR2_ENABLE);
  4913. }
  4914. return com_rslt;
  4915. }
  4916. /*!
  4917. * @brief This API sets FIFO tag interrupt2 enable status
  4918. * from the register 0x47 bit 2
  4919. *
  4920. * @param v_fifo_tag_intr2_u8 : The value of FIFO tag interrupt
  4921. * value | FIFO tag interrupt
  4922. * ----------|-------------------
  4923. * 0x01 | BMI160_ENABLE
  4924. * 0x00 | BMI160_DISABLE
  4925. *
  4926. *
  4927. *
  4928. *
  4929. * @return results of bus communication function
  4930. * @retval 0 -> Success
  4931. * @retval -1 -> Error
  4932. *
  4933. *
  4934. */
  4935. BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_tag_intr2_enable(
  4936. u8 v_fifo_tag_intr2_u8)
  4937. {
  4938. /* variable used to return the status of communication result*/
  4939. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4940. u8 v_data_u8 = BMI160_INIT_VALUE;
  4941. /* check the p_bmi160 structure for NULL pointer assignment*/
  4942. if (p_bmi160 == BMI160_NULL) {
  4943. return E_BMI160_NULL_PTR;
  4944. } else {
  4945. if (v_fifo_tag_intr2_u8 <= BMI160_MAX_VALUE_FIFO_INTR) {
  4946. /* write the FIFO tag interrupt2*/
  4947. com_rslt = bmi160_set_input_enable(1,
  4948. v_fifo_tag_intr2_u8);
  4949. com_rslt +=
  4950. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4951. BMI160_USER_FIFO_TAG_INTR2_ENABLE__REG, &v_data_u8,
  4952. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4953. if (com_rslt == SUCCESS) {
  4954. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  4955. BMI160_USER_FIFO_TAG_INTR2_ENABLE,
  4956. v_fifo_tag_intr2_u8);
  4957. com_rslt +=
  4958. p_bmi160->BMI160_BUS_WRITE_FUNC(
  4959. p_bmi160->dev_addr,
  4960. BMI160_USER_FIFO_TAG_INTR2_ENABLE__REG,
  4961. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  4962. /*Accel and Gyro power mode check*/
  4963. if (bmi160_power_mode_status_u8_g !=
  4964. BMI160_NORMAL_MODE)
  4965. /*interface idle time delay */
  4966. p_bmi160->delay_msec(
  4967. BMI160_GEN_READ_WRITE_DELAY);
  4968. }
  4969. } else {
  4970. com_rslt = E_BMI160_OUT_OF_RANGE;
  4971. }
  4972. }
  4973. return com_rslt;
  4974. }
  4975. /*!
  4976. * @brief This API reads FIFO tag interrupt1 enable status
  4977. * from the register 0x47 bit 3
  4978. *
  4979. * @param v_fifo_tag_intr1_u8 :The value of FIFO tag interrupt1
  4980. * value | FIFO tag interrupt
  4981. * ----------|-------------------
  4982. * 0x01 | BMI160_ENABLE
  4983. * 0x00 | BMI160_DISABLE
  4984. *
  4985. * @return results of bus communication function
  4986. * @retval 0 -> Success
  4987. * @retval -1 -> Error
  4988. *
  4989. *
  4990. */
  4991. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_tag_intr1_enable(
  4992. u8 *v_fifo_tag_intr1_u8)
  4993. {
  4994. /* variable used to return the status of communication result*/
  4995. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4996. u8 v_data_u8 = BMI160_INIT_VALUE;
  4997. /* check the p_bmi160 structure for NULL pointer assignment*/
  4998. if (p_bmi160 == BMI160_NULL) {
  4999. return E_BMI160_NULL_PTR;
  5000. } else {
  5001. /* read FIFO tag interrupt*/
  5002. com_rslt =
  5003. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5004. BMI160_USER_FIFO_TAG_INTR1_ENABLE__REG, &v_data_u8,
  5005. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5006. *v_fifo_tag_intr1_u8 = BMI160_GET_BITSLICE(v_data_u8,
  5007. BMI160_USER_FIFO_TAG_INTR1_ENABLE);
  5008. }
  5009. return com_rslt;
  5010. }
  5011. /*!
  5012. * @brief This API sets FIFO tag interrupt1 enable status
  5013. * from the register 0x47 bit 3
  5014. *
  5015. * @param v_fifo_tag_intr1_u8 :The value of FIFO tag interrupt1
  5016. * value | FIFO tag interrupt
  5017. * ----------|-------------------
  5018. * 0x01 | BMI160_ENABLE
  5019. * 0x00 | BMI160_DISABLE
  5020. *
  5021. * @return results of bus communication function
  5022. * @retval 0 -> Success
  5023. * @retval -1 -> Error
  5024. *
  5025. *
  5026. */
  5027. BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_tag_intr1_enable(
  5028. u8 v_fifo_tag_intr1_u8)
  5029. {
  5030. /* variable used to return the status of communication result*/
  5031. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5032. u8 v_data_u8 = BMI160_INIT_VALUE;
  5033. /* check the p_bmi160 structure for NULL pointer assignment*/
  5034. if (p_bmi160 == BMI160_NULL) {
  5035. return E_BMI160_NULL_PTR;
  5036. } else {
  5037. if (v_fifo_tag_intr1_u8 <= BMI160_MAX_VALUE_FIFO_INTR) {
  5038. /* write the FIFO tag interrupt*/
  5039. com_rslt = bmi160_set_input_enable(BMI160_INIT_VALUE,
  5040. v_fifo_tag_intr1_u8);
  5041. com_rslt +=
  5042. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5043. BMI160_USER_FIFO_TAG_INTR1_ENABLE__REG, &v_data_u8,
  5044. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5045. if (com_rslt == SUCCESS) {
  5046. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  5047. BMI160_USER_FIFO_TAG_INTR1_ENABLE,
  5048. v_fifo_tag_intr1_u8);
  5049. com_rslt +=
  5050. p_bmi160->BMI160_BUS_WRITE_FUNC(
  5051. p_bmi160->dev_addr,
  5052. BMI160_USER_FIFO_TAG_INTR1_ENABLE__REG,
  5053. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5054. /*Accel and Gyro power mode check*/
  5055. if (bmi160_power_mode_status_u8_g !=
  5056. BMI160_NORMAL_MODE)
  5057. /*interface idle time delay */
  5058. p_bmi160->delay_msec(
  5059. BMI160_GEN_READ_WRITE_DELAY);
  5060. }
  5061. } else {
  5062. com_rslt = E_BMI160_OUT_OF_RANGE;
  5063. }
  5064. }
  5065. return com_rslt;
  5066. }
  5067. /*!
  5068. * @brief This API reads FIFO frame
  5069. * header enable from the register 0x47 bit 4
  5070. *
  5071. * @param v_fifo_header_u8 :The value of FIFO header
  5072. * value | FIFO header
  5073. * ----------|-------------------
  5074. * 0x01 | BMI160_ENABLE
  5075. * 0x00 | BMI160_DISABLE
  5076. *
  5077. * @return results of bus communication function
  5078. * @retval 0 -> Success
  5079. * @retval -1 -> Error
  5080. *
  5081. *
  5082. */
  5083. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_header_enable(
  5084. u8 *v_fifo_header_u8)
  5085. {
  5086. /* variable used to return the status of communication result*/
  5087. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5088. u8 v_data_u8 = BMI160_INIT_VALUE;
  5089. /* check the p_bmi160 structure for NULL pointer assignment*/
  5090. if (p_bmi160 == BMI160_NULL) {
  5091. return E_BMI160_NULL_PTR;
  5092. } else {
  5093. /* read FIFO header */
  5094. com_rslt =
  5095. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5096. BMI160_USER_FIFO_HEADER_ENABLE__REG, &v_data_u8,
  5097. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5098. *v_fifo_header_u8 = BMI160_GET_BITSLICE(v_data_u8,
  5099. BMI160_USER_FIFO_HEADER_ENABLE);
  5100. }
  5101. return com_rslt;
  5102. }
  5103. /*!
  5104. * @brief This API sets FIFO frame
  5105. * header enable from the register 0x47 bit 4
  5106. *
  5107. * @param v_fifo_header_u8 :The value of FIFO header
  5108. * value | FIFO header
  5109. * ----------|-------------------
  5110. * 0x01 | BMI160_ENABLE
  5111. * 0x00 | BMI160_DISABLE
  5112. *
  5113. * @return results of bus communication function
  5114. * @retval 0 -> Success
  5115. * @retval -1 -> Error
  5116. *
  5117. *
  5118. */
  5119. BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_header_enable(
  5120. u8 v_fifo_header_u8)
  5121. {
  5122. /* variable used to return the status of communication result*/
  5123. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5124. u8 v_data_u8 = BMI160_INIT_VALUE;
  5125. /* check the p_bmi160 structure for NULL pointer assignment*/
  5126. if (p_bmi160 == BMI160_NULL) {
  5127. return E_BMI160_NULL_PTR;
  5128. } else {
  5129. if (v_fifo_header_u8 <= BMI160_MAX_VALUE_FIFO_HEADER) {
  5130. /* write the FIFO header */
  5131. com_rslt =
  5132. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5133. BMI160_USER_FIFO_HEADER_ENABLE__REG, &v_data_u8,
  5134. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5135. if (com_rslt == SUCCESS) {
  5136. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  5137. BMI160_USER_FIFO_HEADER_ENABLE,
  5138. v_fifo_header_u8);
  5139. com_rslt +=
  5140. p_bmi160->BMI160_BUS_WRITE_FUNC(
  5141. p_bmi160->dev_addr,
  5142. BMI160_USER_FIFO_HEADER_ENABLE__REG,
  5143. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5144. }
  5145. } else {
  5146. com_rslt = E_BMI160_OUT_OF_RANGE;
  5147. }
  5148. }
  5149. return com_rslt;
  5150. }
  5151. /*!
  5152. * @brief This API is used to check whether
  5153. * Mag data in FIFO (all 3 axes) or not from the
  5154. * register 0x47 bit 5
  5155. *
  5156. * @param v_fifo_mag_u8 : The value of FIFO Mag enable
  5157. * value | FIFO mag
  5158. * ----------|-------------------
  5159. * 0x00 | no Mag data is stored
  5160. * 0x01 | Mag data is stored
  5161. *
  5162. * @return results of bus communication function
  5163. * @retval 0 -> Success
  5164. * @retval -1 -> Error
  5165. *
  5166. *
  5167. */
  5168. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_mag_enable(
  5169. u8 *v_fifo_mag_u8)
  5170. {
  5171. /* variable used to return the status of communication result*/
  5172. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5173. u8 v_data_u8 = BMI160_INIT_VALUE;
  5174. /* check the p_bmi160 structure for NULL pointer assignment*/
  5175. if (p_bmi160 == BMI160_NULL) {
  5176. return E_BMI160_NULL_PTR;
  5177. } else {
  5178. /* read the FIFO Mag enable*/
  5179. com_rslt =
  5180. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5181. BMI160_USER_FIFO_MAG_ENABLE__REG, &v_data_u8,
  5182. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5183. *v_fifo_mag_u8 = BMI160_GET_BITSLICE(v_data_u8,
  5184. BMI160_USER_FIFO_MAG_ENABLE);
  5185. }
  5186. return com_rslt;
  5187. }
  5188. /*!
  5189. * @brief This API is used to enable
  5190. * Mag data in FIFO (all 3 axes) from the register 0x47 bit 5
  5191. *
  5192. * @param v_fifo_mag_u8 : The value of FIFO Mag enable
  5193. * value | FIFO mag
  5194. * ----------|-------------------
  5195. * 0x00 | no Mag data is stored
  5196. * 0x01 | Mag data is stored
  5197. *
  5198. * @return results of bus communication function
  5199. * @retval 0 -> Success
  5200. * @retval -1 -> Error
  5201. *
  5202. *
  5203. */
  5204. BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_mag_enable(
  5205. u8 v_fifo_mag_u8)
  5206. {
  5207. /* variable used to return the status of communication result*/
  5208. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5209. u8 v_data_u8 = BMI160_INIT_VALUE;
  5210. /* check the p_bmi160 structure for NULL pointer assignment*/
  5211. if (p_bmi160 == BMI160_NULL) {
  5212. return E_BMI160_NULL_PTR;
  5213. } else {
  5214. if (v_fifo_mag_u8 <= BMI160_MAX_VALUE_FIFO_MAG) {
  5215. /* write the FIFO Mag enable*/
  5216. com_rslt =
  5217. p_bmi160->BMI160_BUS_READ_FUNC
  5218. (p_bmi160->dev_addr,
  5219. BMI160_USER_FIFO_MAG_ENABLE__REG,
  5220. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5221. if (com_rslt == SUCCESS) {
  5222. v_data_u8 =
  5223. BMI160_SET_BITSLICE(v_data_u8,
  5224. BMI160_USER_FIFO_MAG_ENABLE,
  5225. v_fifo_mag_u8);
  5226. com_rslt +=
  5227. p_bmi160->BMI160_BUS_WRITE_FUNC
  5228. (p_bmi160->dev_addr,
  5229. BMI160_USER_FIFO_MAG_ENABLE__REG,
  5230. &v_data_u8,
  5231. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5232. }
  5233. } else {
  5234. com_rslt = E_BMI160_OUT_OF_RANGE;
  5235. }
  5236. }
  5237. return com_rslt;
  5238. }
  5239. /*!
  5240. * @brief This API is used to check whether
  5241. * Accel data is stored in FIFO (all 3 axes) or not from the
  5242. * register 0x47 bit 6
  5243. *
  5244. * @param v_fifo_accel_u8 : The value of FIFO Accel enable
  5245. * value | FIFO Accel
  5246. * ----------|-------------------
  5247. * 0x00 | no Accel data is stored
  5248. * 0x01 | Accel data is stored
  5249. *
  5250. *
  5251. *
  5252. * @return results of bus communication function
  5253. * @retval 0 -> Success
  5254. * @retval -1 -> Error
  5255. *
  5256. *
  5257. */
  5258. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_accel_enable(
  5259. u8 *v_fifo_accel_u8)
  5260. {
  5261. /* variable used to return the status of communication result*/
  5262. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5263. u8 v_data_u8 = BMI160_INIT_VALUE;
  5264. /* check the p_bmi160 structure for NULL pointer assignment*/
  5265. if (p_bmi160 == BMI160_NULL) {
  5266. return E_BMI160_NULL_PTR;
  5267. } else {
  5268. /* read the Accel FIFO enable*/
  5269. com_rslt =
  5270. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5271. BMI160_USER_FIFO_ACCEL_ENABLE__REG, &v_data_u8,
  5272. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5273. *v_fifo_accel_u8 =
  5274. BMI160_GET_BITSLICE(v_data_u8,
  5275. BMI160_USER_FIFO_ACCEL_ENABLE);
  5276. }
  5277. return com_rslt;
  5278. }
  5279. /*!
  5280. * @brief This API is used to enable
  5281. * Accel data in FIFO (all 3 axes) from the register 0x47 bit 6
  5282. *
  5283. * @param v_fifo_accel_u8 : The value of FIFO Accel enable
  5284. * value | FIFO Accel
  5285. * ----------|-------------------
  5286. * 0x00 | no Accel data is stored
  5287. * 0x01 | Accel data is stored
  5288. *
  5289. *
  5290. *
  5291. * @return results of bus communication function
  5292. * @retval 0 -> Success
  5293. * @retval -1 -> Error
  5294. *
  5295. *
  5296. */
  5297. BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_accel_enable(
  5298. u8 v_fifo_accel_u8)
  5299. {
  5300. /* variable used to return the status of communication result*/
  5301. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5302. u8 v_data_u8 = BMI160_INIT_VALUE;
  5303. /* check the p_bmi160 structure for NULL pointer assignment*/
  5304. if (p_bmi160 == BMI160_NULL) {
  5305. return E_BMI160_NULL_PTR;
  5306. } else {
  5307. if (v_fifo_accel_u8 <= BMI160_MAX_VALUE_FIFO_ACCEL) {
  5308. /* write the FIFO Mag enables*/
  5309. com_rslt =
  5310. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5311. BMI160_USER_FIFO_ACCEL_ENABLE__REG, &v_data_u8,
  5312. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5313. if (com_rslt == SUCCESS) {
  5314. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  5315. BMI160_USER_FIFO_ACCEL_ENABLE, v_fifo_accel_u8);
  5316. com_rslt +=
  5317. p_bmi160->BMI160_BUS_WRITE_FUNC(
  5318. p_bmi160->dev_addr,
  5319. BMI160_USER_FIFO_ACCEL_ENABLE__REG,
  5320. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5321. }
  5322. } else {
  5323. com_rslt = E_BMI160_OUT_OF_RANGE;
  5324. }
  5325. }
  5326. return com_rslt;
  5327. }
  5328. /*!
  5329. * @brief This API is used to check whether
  5330. * gyro data is stored in FIFO (all 3 axes) or not from the
  5331. * register 0x47 bit 7
  5332. *
  5333. *
  5334. * @param v_fifo_gyro_u8 : The value of FIFO gyro enable
  5335. * value | FIFO gyro
  5336. * ----------|-------------------
  5337. * 0x00 | no gyro data is stored
  5338. * 0x01 | gyro data is stored
  5339. *
  5340. *
  5341. * @return results of bus communication function
  5342. * @retval 0 -> Success
  5343. * @retval -1 -> Error
  5344. *
  5345. *
  5346. */
  5347. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_gyro_enable(
  5348. u8 *v_fifo_gyro_u8)
  5349. {
  5350. /* variable used to return the status of communication result*/
  5351. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5352. u8 v_data_u8 = BMI160_INIT_VALUE;
  5353. /* check the p_bmi160 structure for NULL pointer assignment*/
  5354. if (p_bmi160 == BMI160_NULL) {
  5355. return E_BMI160_NULL_PTR;
  5356. } else {
  5357. /* read FIFO gyro enable */
  5358. com_rslt =
  5359. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5360. BMI160_USER_FIFO_GYRO_ENABLE__REG, &v_data_u8,
  5361. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5362. *v_fifo_gyro_u8 = BMI160_GET_BITSLICE(v_data_u8,
  5363. BMI160_USER_FIFO_GYRO_ENABLE);
  5364. }
  5365. return com_rslt;
  5366. }
  5367. /*!
  5368. * @brief This API is used to enable
  5369. * gyro data in FIFO (all 3 axes) from the register 0x47 bit 7
  5370. *
  5371. *
  5372. * @param v_fifo_gyro_u8 : The value of FIFO gyro enable
  5373. * value | FIFO gyro
  5374. * ----------|-------------------
  5375. * 0x00 | no gyro data is stored
  5376. * 0x01 | gyro data is stored
  5377. *
  5378. *
  5379. * @return results of bus communication function
  5380. * @retval 0 -> Success
  5381. * @retval -1 -> Error
  5382. *
  5383. *
  5384. */
  5385. BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_gyro_enable(
  5386. u8 v_fifo_gyro_u8)
  5387. {
  5388. /* variable used to return the status of communication result*/
  5389. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5390. u8 v_data_u8 = BMI160_INIT_VALUE;
  5391. /* check the p_bmi160 structure for NULL pointer assignment*/
  5392. if (p_bmi160 == BMI160_NULL) {
  5393. return E_BMI160_NULL_PTR;
  5394. } else {
  5395. if (v_fifo_gyro_u8 <= BMI160_MAX_VALUE_FIFO_GYRO) {
  5396. /* write FIFO gyro enable*/
  5397. com_rslt =
  5398. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5399. BMI160_USER_FIFO_GYRO_ENABLE__REG, &v_data_u8,
  5400. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5401. if (com_rslt == SUCCESS) {
  5402. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  5403. BMI160_USER_FIFO_GYRO_ENABLE, v_fifo_gyro_u8);
  5404. com_rslt +=
  5405. p_bmi160->BMI160_BUS_WRITE_FUNC(
  5406. p_bmi160->dev_addr,
  5407. BMI160_USER_FIFO_GYRO_ENABLE__REG,
  5408. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5409. }
  5410. } else {
  5411. com_rslt = E_BMI160_OUT_OF_RANGE;
  5412. }
  5413. }
  5414. return com_rslt;
  5415. }
  5416. #endif
  5417. /*!
  5418. * @brief This API is used to read
  5419. * I2C device address of auxiliary Mag from the register 0x4B bit 1 to 7
  5420. *
  5421. *
  5422. *
  5423. *
  5424. * @param v_i2c_device_addr_u8 : The value of Mag I2C device address
  5425. *
  5426. *
  5427. * @return results of bus communication function
  5428. * @retval 0 -> Success
  5429. * @retval -1 -> Error
  5430. *
  5431. *
  5432. */
  5433. BMI160_RETURN_FUNCTION_TYPE bmi160_get_i2c_device_addr(
  5434. u8 *v_i2c_device_addr_u8)
  5435. {
  5436. /* variable used to return the status of communication result*/
  5437. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5438. u8 v_data_u8 = BMI160_INIT_VALUE;
  5439. /* check the p_bmi160 structure for NULL pointer assignment*/
  5440. if (p_bmi160 == BMI160_NULL) {
  5441. return E_BMI160_NULL_PTR;
  5442. } else {
  5443. /* read the Mag I2C device address*/
  5444. com_rslt =
  5445. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5446. BMI160_USER_I2C_DEVICE_ADDR__REG, &v_data_u8,
  5447. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5448. *v_i2c_device_addr_u8 = BMI160_GET_BITSLICE(v_data_u8,
  5449. BMI160_USER_I2C_DEVICE_ADDR);
  5450. }
  5451. return com_rslt;
  5452. }
  5453. /*!
  5454. * @brief This API is used to set
  5455. * I2C device address of auxiliary Mag from the register 0x4B bit 1 to 7
  5456. *
  5457. *
  5458. *
  5459. *
  5460. * @param v_i2c_device_addr_u8 : The value of Mag I2C device address
  5461. *
  5462. *
  5463. * @return results of bus communication function
  5464. * @retval 0 -> Success
  5465. * @retval -1 -> Error
  5466. *
  5467. *
  5468. */
  5469. BMI160_RETURN_FUNCTION_TYPE bmi160_set_i2c_device_addr(
  5470. u8 v_i2c_device_addr_u8)
  5471. {
  5472. /* variable used to return the status of communication result*/
  5473. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5474. u8 v_data_u8 = BMI160_INIT_VALUE;
  5475. /* check the p_bmi160 structure for NULL pointer assignment*/
  5476. if (p_bmi160 == BMI160_NULL) {
  5477. return E_BMI160_NULL_PTR;
  5478. } else {
  5479. /* write the Mag I2C device address*/
  5480. com_rslt =
  5481. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5482. BMI160_USER_I2C_DEVICE_ADDR__REG, &v_data_u8,
  5483. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5484. if (com_rslt == SUCCESS) {
  5485. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  5486. BMI160_USER_I2C_DEVICE_ADDR,
  5487. v_i2c_device_addr_u8);
  5488. com_rslt +=
  5489. p_bmi160->BMI160_BUS_WRITE_FUNC(
  5490. p_bmi160->dev_addr,
  5491. BMI160_USER_I2C_DEVICE_ADDR__REG,
  5492. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5493. /*Accel and Gyro power mode check*/
  5494. if (bmi160_power_mode_status_u8_g !=
  5495. BMI160_NORMAL_MODE)
  5496. /*interface idle time delay */
  5497. p_bmi160->delay_msec(
  5498. BMI160_GEN_READ_WRITE_DELAY);
  5499. }
  5500. }
  5501. return com_rslt;
  5502. }
  5503. /*!
  5504. * @brief This API is used to read the
  5505. * Burst data length (1,2,6,8 byte) from the register 0x4C bit 0 to 1
  5506. *
  5507. *
  5508. *
  5509. *
  5510. * @param v_mag_burst_u8 : The data of Mag burst read length
  5511. *
  5512. *
  5513. *
  5514. * @return results of bus communication function
  5515. * @retval 0 -> Success
  5516. * @retval -1 -> Error
  5517. *
  5518. *
  5519. */
  5520. BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_burst(
  5521. u8 *v_mag_burst_u8)
  5522. {
  5523. /* variable used to return the status of communication result*/
  5524. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5525. u8 v_data_u8 = BMI160_INIT_VALUE;
  5526. /* check the p_bmi160 structure for NULL pointer assignment*/
  5527. if (p_bmi160 == BMI160_NULL) {
  5528. return E_BMI160_NULL_PTR;
  5529. } else {
  5530. /* read Mag burst mode length*/
  5531. com_rslt =
  5532. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5533. BMI160_USER_MAG_BURST__REG,
  5534. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5535. *v_mag_burst_u8 = BMI160_GET_BITSLICE(v_data_u8,
  5536. BMI160_USER_MAG_BURST);
  5537. }
  5538. return com_rslt;
  5539. }
  5540. /*!
  5541. * @brief This API is used to set
  5542. * Burst data length (1,2,6,8 byte) from the register 0x4C bit 0 to 1
  5543. *
  5544. *
  5545. *
  5546. *
  5547. * @param v_mag_burst_u8 : The data of Mag burst read length
  5548. *
  5549. *
  5550. *
  5551. * @return results of bus communication function
  5552. * @retval 0 -> Success
  5553. * @retval -1 -> Error
  5554. *
  5555. *
  5556. */
  5557. BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_burst(
  5558. u8 v_mag_burst_u8)
  5559. {
  5560. /* variable used to return the status of communication result*/
  5561. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5562. u8 v_data_u8 = BMI160_INIT_VALUE;
  5563. /* check the p_bmi160 structure for NULL pointer assignment*/
  5564. if (p_bmi160 == BMI160_NULL) {
  5565. return E_BMI160_NULL_PTR;
  5566. } else {
  5567. /* write Mag burst mode length*/
  5568. com_rslt =
  5569. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5570. BMI160_USER_MAG_BURST__REG,
  5571. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5572. if (com_rslt == SUCCESS) {
  5573. v_data_u8 =
  5574. BMI160_SET_BITSLICE(v_data_u8,
  5575. BMI160_USER_MAG_BURST, v_mag_burst_u8);
  5576. com_rslt +=
  5577. p_bmi160->BMI160_BUS_WRITE_FUNC(
  5578. p_bmi160->dev_addr,
  5579. BMI160_USER_MAG_BURST__REG, &v_data_u8,
  5580. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5581. /*Accel and Gyro power mode check*/
  5582. if (bmi160_power_mode_status_u8_g !=
  5583. BMI160_NORMAL_MODE)
  5584. /*interface idle time delay */
  5585. p_bmi160->delay_msec(
  5586. BMI160_GEN_READ_WRITE_DELAY);
  5587. }
  5588. }
  5589. return com_rslt;
  5590. }
  5591. /*!
  5592. * @brief This API is used to read
  5593. * trigger-readout offset in units of 2.5 ms. If set to zero,
  5594. * the offset is maximum, i.e. after readout a trigger
  5595. * is issued immediately. from the register 0x4C bit 2 to 5
  5596. *
  5597. *
  5598. *
  5599. *
  5600. * @param v_mag_offset_u8 : The value of Mag offset
  5601. *
  5602. *
  5603. *
  5604. * @return results of bus communication function
  5605. * @retval 0 -> Success
  5606. * @retval -1 -> Error
  5607. *
  5608. *
  5609. */
  5610. BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_offset(
  5611. u8 *v_mag_offset_u8)
  5612. {
  5613. /* variable used to return the status of communication result*/
  5614. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5615. u8 v_data_u8 = BMI160_INIT_VALUE;
  5616. /* check the p_bmi160 structure for NULL pointer assignment*/
  5617. if (p_bmi160 == BMI160_NULL) {
  5618. return E_BMI160_NULL_PTR;
  5619. } else {
  5620. com_rslt =
  5621. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5622. BMI160_USER_MAG_OFFSET__REG,
  5623. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5624. *v_mag_offset_u8 =
  5625. BMI160_GET_BITSLICE(v_data_u8,
  5626. BMI160_USER_MAG_OFFSET);
  5627. }
  5628. return com_rslt;
  5629. }
  5630. /*!
  5631. * @brief This API is used to set the
  5632. * trigger-readout offset in units of 2.5 ms. If set to zero,
  5633. * the offset is maximum, i.e. after readout a trigger
  5634. * is issued immediately. from the register 0x4C bit 2 to 5
  5635. *
  5636. *
  5637. *
  5638. *
  5639. * @param v_mag_offset_u8 : The value of Mag offset
  5640. *
  5641. *
  5642. *
  5643. * @return results of bus communication function
  5644. * @retval 0 -> Success
  5645. * @retval -1 -> Error
  5646. *
  5647. *
  5648. */
  5649. BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_offset(
  5650. u8 v_mag_offset_u8)
  5651. {
  5652. /* variable used to return the status of communication result*/
  5653. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5654. u8 v_data_u8 = BMI160_INIT_VALUE;
  5655. /* check the p_bmi160 structure for NULL pointer assignment*/
  5656. if (p_bmi160 == BMI160_NULL) {
  5657. return E_BMI160_NULL_PTR;
  5658. } else {
  5659. com_rslt =
  5660. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5661. BMI160_USER_MAG_OFFSET__REG,
  5662. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5663. if (com_rslt == SUCCESS) {
  5664. v_data_u8 =
  5665. BMI160_SET_BITSLICE(v_data_u8,
  5666. BMI160_USER_MAG_OFFSET, v_mag_offset_u8);
  5667. com_rslt +=
  5668. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->dev_addr,
  5669. BMI160_USER_MAG_OFFSET__REG,
  5670. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5671. /*Accel and Gyro power mode check*/
  5672. if (bmi160_power_mode_status_u8_g !=
  5673. BMI160_NORMAL_MODE)
  5674. /*interface idle time delay */
  5675. p_bmi160->delay_msec(
  5676. BMI160_GEN_READ_WRITE_DELAY);
  5677. }
  5678. }
  5679. return com_rslt;
  5680. }
  5681. /*!
  5682. * @brief This API is used to read the
  5683. * Enable register access on MAG_IF[2] or MAG_IF[3].
  5684. * This implies that the DATA registers are not updated with
  5685. * Mag values. Accessing Mag requires
  5686. * the Mag in normal mode in PMU_STATUS.
  5687. * from the register 0x4C bit 7
  5688. *
  5689. *
  5690. *
  5691. * @param v_mag_manual_u8 : The value of Mag manual enable
  5692. * value | Mag manual
  5693. * ----------|-------------------
  5694. * 0x01 | BMI160_ENABLE
  5695. * 0x00 | BMI160_DISABLE
  5696. *
  5697. *
  5698. *
  5699. * @return results of bus communication function
  5700. * @retval 0 -> Success
  5701. * @retval -1 -> Error
  5702. *
  5703. *
  5704. */
  5705. BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_manual_enable(
  5706. u8 *v_mag_manual_u8)
  5707. {
  5708. /* variable used to return the status of communication result*/
  5709. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5710. u8 v_data_u8 = BMI160_INIT_VALUE;
  5711. /* check the p_bmi160 structure for NULL pointer assignment*/
  5712. if (p_bmi160 == BMI160_NULL) {
  5713. return E_BMI160_NULL_PTR;
  5714. } else {
  5715. /* read Mag manual */
  5716. com_rslt =
  5717. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5718. BMI160_USER_MAG_MANUAL_ENABLE__REG, &v_data_u8,
  5719. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5720. *v_mag_manual_u8 =
  5721. BMI160_GET_BITSLICE(v_data_u8,
  5722. BMI160_USER_MAG_MANUAL_ENABLE);
  5723. }
  5724. return com_rslt;
  5725. }
  5726. /*!
  5727. * @brief This API is used to set the
  5728. * Enable register access of MAG_IF[2] or MAG_IF[3].
  5729. * This implies that the DATA registers are not updated with
  5730. * Mag values. Accessing Mag requires
  5731. * the Mag in normal mode in PMU_STATUS.
  5732. * from the register 0x4C bit 7
  5733. *
  5734. *
  5735. *
  5736. * @param v_mag_manual_u8 : The value of Mag manual enable
  5737. * value | Mag manual
  5738. * ----------|-------------------
  5739. * 0x01 | BMI160_ENABLE
  5740. * 0x00 | BMI160_DISABLE
  5741. *
  5742. *
  5743. *
  5744. * @return results of bus communication function
  5745. * @retval 0 -> Success
  5746. * @retval -1 -> Error
  5747. *
  5748. *
  5749. */
  5750. BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_manual_enable(
  5751. u8 v_mag_manual_u8)
  5752. {
  5753. /* variable used to return the status of communication result*/
  5754. BMI160_RETURN_FUNCTION_TYPE com_rslt = BMI160_INIT_VALUE;
  5755. u8 v_data_u8 = BMI160_INIT_VALUE;
  5756. /* check the p_bmi160 structure for NULL pointer assignment*/
  5757. if (p_bmi160 == BMI160_NULL) {
  5758. return E_BMI160_NULL_PTR;
  5759. } else {
  5760. /* write the Mag manual*/
  5761. com_rslt =
  5762. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5763. BMI160_USER_MAG_MANUAL_ENABLE__REG, &v_data_u8,
  5764. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5765. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  5766. if (com_rslt == SUCCESS) {
  5767. /* set the bit of Mag manual enable*/
  5768. v_data_u8 =
  5769. BMI160_SET_BITSLICE(v_data_u8,
  5770. BMI160_USER_MAG_MANUAL_ENABLE, v_mag_manual_u8);
  5771. com_rslt +=
  5772. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->dev_addr,
  5773. BMI160_USER_MAG_MANUAL_ENABLE__REG, &v_data_u8,
  5774. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5775. /*Accel and Gyro power mode check*/
  5776. if (bmi160_power_mode_status_u8_g !=
  5777. BMI160_NORMAL_MODE)
  5778. /*interface idle time delay */
  5779. p_bmi160->delay_msec(
  5780. BMI160_GEN_READ_WRITE_DELAY);
  5781. }
  5782. if (com_rslt == SUCCESS)
  5783. p_bmi160->mag_manual_enable = v_mag_manual_u8;
  5784. else
  5785. p_bmi160->mag_manual_enable = E_BMI160_COMM_RES;
  5786. }
  5787. return com_rslt;
  5788. }
  5789. /*!
  5790. * @brief This API is used to get the
  5791. * Mag read address from the register 0x4D bit 0 to 7
  5792. * @brief Mag read address of auxiliary mag
  5793. *
  5794. *
  5795. *
  5796. *
  5797. * @param v_mag_read_addr_u8 : The value of address need to be read
  5798. *
  5799. *
  5800. *
  5801. * @return results of bus communication function
  5802. * @retval 0 -> Success
  5803. * @retval -1 -> Error
  5804. *
  5805. *
  5806. */
  5807. BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_read_addr(
  5808. u8 *v_mag_read_addr_u8)
  5809. {
  5810. /* variable used to return the status of communication result*/
  5811. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5812. u8 v_data_u8 = BMI160_INIT_VALUE;
  5813. /* check the p_bmi160 structure for NULL pointer assignment*/
  5814. if (p_bmi160 == BMI160_NULL) {
  5815. return E_BMI160_NULL_PTR;
  5816. } else {
  5817. /* read the written address*/
  5818. com_rslt =
  5819. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5820. BMI160_USER_READ_ADDR__REG,
  5821. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5822. *v_mag_read_addr_u8 =
  5823. BMI160_GET_BITSLICE(v_data_u8,
  5824. BMI160_USER_READ_ADDR);
  5825. }
  5826. return com_rslt;
  5827. }
  5828. /*!
  5829. * @brief This API is used to set
  5830. * Mag read address from the register 0x4D bit 0 to 7
  5831. * @brief address where data will be read from auxiliary mag
  5832. *
  5833. *
  5834. *
  5835. * @param v_mag_read_addr_u8:
  5836. * The data of auxiliary Mag address to write data
  5837. *
  5838. *
  5839. * @return results of bus communication function
  5840. * @retval 0 -> Success
  5841. * @retval -1 -> Error
  5842. *
  5843. *
  5844. */
  5845. BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_read_addr(
  5846. u8 v_mag_read_addr_u8)
  5847. {
  5848. /* variable used to return the status of communication result*/
  5849. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5850. /* check the p_bmi160 structure for NULL pointer assignment*/
  5851. if (p_bmi160 == BMI160_NULL) {
  5852. return E_BMI160_NULL_PTR;
  5853. } else {
  5854. /* write the Mag read address*/
  5855. com_rslt =
  5856. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->dev_addr,
  5857. BMI160_USER_READ_ADDR__REG, &v_mag_read_addr_u8,
  5858. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5859. /*Accel and Gyro power mode check*/
  5860. if (bmi160_power_mode_status_u8_g !=
  5861. BMI160_NORMAL_MODE)
  5862. /*interface idle time delay */
  5863. p_bmi160->delay_msec(
  5864. BMI160_GEN_READ_WRITE_DELAY);
  5865. }
  5866. return com_rslt;
  5867. }
  5868. /*!
  5869. * @brief This API is used to read
  5870. * Mag write address from the register 0x4E bit 0 to 7
  5871. * @brief write address where data will be written in Mag
  5872. *
  5873. *
  5874. *
  5875. * @param v_mag_write_addr_u8:
  5876. * The data of auxiliary Mag address to write data
  5877. *
  5878. *
  5879. * @return results of bus communication function
  5880. * @retval 0 -> Success
  5881. * @retval -1 -> Error
  5882. *
  5883. *
  5884. */
  5885. BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_write_addr(
  5886. u8 *v_mag_write_addr_u8)
  5887. {
  5888. /* variable used to return the status of communication result*/
  5889. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5890. u8 v_data_u8 = BMI160_INIT_VALUE;
  5891. /* check the p_bmi160 structure for NULL pointer assignment*/
  5892. if (p_bmi160 == BMI160_NULL) {
  5893. return E_BMI160_NULL_PTR;
  5894. } else {
  5895. /* read the address of last written */
  5896. com_rslt =
  5897. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5898. BMI160_USER_WRITE_ADDR__REG,
  5899. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5900. *v_mag_write_addr_u8 =
  5901. BMI160_GET_BITSLICE(v_data_u8,
  5902. BMI160_USER_WRITE_ADDR);
  5903. }
  5904. return com_rslt;
  5905. }
  5906. /*!
  5907. * @brief This API is used to set
  5908. * Mag write address from the register 0x4E bit 0 to 7
  5909. * @brief this is the address in Mag where the data will be written
  5910. *
  5911. *
  5912. *
  5913. * @param v_mag_write_addr_u8:
  5914. * The address which the data will be written to
  5915. *
  5916. *
  5917. * @return results of bus communication function
  5918. * @retval 0 -> Success
  5919. * @retval -1 -> Error
  5920. *
  5921. *
  5922. */
  5923. BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_write_addr(
  5924. u8 v_mag_write_addr_u8)
  5925. {
  5926. /* variable used to return the status of communication result*/
  5927. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5928. /* check the p_bmi160 structure for NULL pointer assignment*/
  5929. if (p_bmi160 == BMI160_NULL) {
  5930. return E_BMI160_NULL_PTR;
  5931. } else {
  5932. /* write the data of Mag address to write data */
  5933. com_rslt =
  5934. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->dev_addr,
  5935. BMI160_USER_WRITE_ADDR__REG, &v_mag_write_addr_u8,
  5936. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5937. /*Accel and Gyro power mode check*/
  5938. if (bmi160_power_mode_status_u8_g !=
  5939. BMI160_NORMAL_MODE)
  5940. /*interface idle time delay */
  5941. p_bmi160->delay_msec(
  5942. BMI160_GEN_READ_WRITE_DELAY);
  5943. }
  5944. return com_rslt;
  5945. }
  5946. /*!
  5947. * @brief This API is used to read Mag write data
  5948. * from the register 0x4F bit 0 to 7
  5949. * @brief The data will be written to mag
  5950. *
  5951. *
  5952. *
  5953. * @param v_mag_write_data_u8: The value of Mag data
  5954. *
  5955. *
  5956. *
  5957. * @return results of bus communication function
  5958. * @retval 0 -> Success
  5959. * @retval -1 -> Error
  5960. *
  5961. *
  5962. */
  5963. BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_write_data(
  5964. u8 *v_mag_write_data_u8)
  5965. {
  5966. /* variable used to return the status of communication result*/
  5967. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5968. u8 v_data_u8 = BMI160_INIT_VALUE;
  5969. /* check the p_bmi160 structure for NULL pointer assignment*/
  5970. if (p_bmi160 == BMI160_NULL) {
  5971. return E_BMI160_NULL_PTR;
  5972. } else {
  5973. com_rslt =
  5974. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5975. BMI160_USER_WRITE_DATA__REG, &v_data_u8,
  5976. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  5977. *v_mag_write_data_u8 =
  5978. BMI160_GET_BITSLICE(v_data_u8,
  5979. BMI160_USER_WRITE_DATA);
  5980. }
  5981. return com_rslt;
  5982. }
  5983. /*!
  5984. * @brief This API is used to set Mag write data
  5985. * from the register 0x4F bit 0 to 7
  5986. * @brief The data will be written to mag
  5987. *
  5988. *
  5989. *
  5990. * @param v_mag_write_data_u8: The value of Mag data
  5991. *
  5992. *
  5993. *
  5994. * @return results of bus communication function
  5995. * @retval 0 -> Success
  5996. * @retval -1 -> Error
  5997. *
  5998. *
  5999. */
  6000. BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_write_data(
  6001. u8 v_mag_write_data_u8)
  6002. {
  6003. /* variable used to return the status of communication result*/
  6004. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6005. /* check the p_bmi160 structure for NULL pointer assignment*/
  6006. if (p_bmi160 == BMI160_NULL) {
  6007. return E_BMI160_NULL_PTR;
  6008. } else {
  6009. com_rslt =
  6010. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->dev_addr,
  6011. BMI160_USER_WRITE_DATA__REG, &v_mag_write_data_u8,
  6012. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6013. /*Accel and Gyro power mode check*/
  6014. if (bmi160_power_mode_status_u8_g !=
  6015. BMI160_NORMAL_MODE)
  6016. /*interface idle time delay */
  6017. p_bmi160->delay_msec(
  6018. BMI160_GEN_READ_WRITE_DELAY);
  6019. }
  6020. return com_rslt;
  6021. }
  6022. /*!
  6023. * @brief This API is used to read
  6024. * interrupt enable from the register 0x50 bit 0 to 7
  6025. *
  6026. *
  6027. *
  6028. *
  6029. * @param v_enable_u8 : Value which selects the interrupt
  6030. * v_enable_u8 | interrupt
  6031. * ---------------|---------------
  6032. * 0 | BMI160_ANY_MOTION_X_ENABLE
  6033. * 1 | BMI160_ANY_MOTION_Y_ENABLE
  6034. * 2 | BMI160_ANY_MOTION_Z_ENABLE
  6035. * 3 | BMI160_DOUBLE_TAP_ENABLE
  6036. * 4 | BMI160_SINGLE_TAP_ENABLE
  6037. * 5 | BMI160_ORIENT_ENABLE
  6038. * 6 | BMI160_FLAT_ENABLE
  6039. *
  6040. * @param v_intr_enable_zero_u8 : The interrupt enable value
  6041. * value | interrupt enable
  6042. * ----------|-------------------
  6043. * 0x01 | BMI160_ENABLE
  6044. * 0x00 | BMI160_DISABLE
  6045. *
  6046. *
  6047. *
  6048. * @return results of bus communication function
  6049. * @retval 0 -> Success
  6050. * @retval -1 -> Error
  6051. *
  6052. *
  6053. */
  6054. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_enable_0(
  6055. u8 v_enable_u8, u8 *v_intr_enable_zero_u8)
  6056. {
  6057. /* variable used to return the status of communication result*/
  6058. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6059. u8 v_data_u8 = BMI160_INIT_VALUE;
  6060. /* check the p_bmi160 structure for NULL pointer assignment*/
  6061. if (p_bmi160 == BMI160_NULL) {
  6062. return E_BMI160_NULL_PTR;
  6063. } else {
  6064. /* select interrupt to read*/
  6065. switch (v_enable_u8) {
  6066. case BMI160_ANY_MOTION_X_ENABLE:
  6067. /* read the any motion interrupt x data */
  6068. com_rslt =
  6069. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6070. dev_addr,
  6071. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE__REG,
  6072. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6073. *v_intr_enable_zero_u8 =
  6074. BMI160_GET_BITSLICE(v_data_u8,
  6075. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE);
  6076. break;
  6077. case BMI160_ANY_MOTION_Y_ENABLE:
  6078. /* read the any motion interrupt y data */
  6079. com_rslt =
  6080. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6081. dev_addr,
  6082. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE__REG,
  6083. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6084. *v_intr_enable_zero_u8 =
  6085. BMI160_GET_BITSLICE(v_data_u8,
  6086. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE);
  6087. break;
  6088. case BMI160_ANY_MOTION_Z_ENABLE:
  6089. /* read the any motion interrupt z data */
  6090. com_rslt =
  6091. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6092. dev_addr,
  6093. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE__REG,
  6094. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6095. *v_intr_enable_zero_u8 =
  6096. BMI160_GET_BITSLICE(v_data_u8,
  6097. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE);
  6098. break;
  6099. case BMI160_DOUBLE_TAP_ENABLE:
  6100. /* read the double tap interrupt data */
  6101. com_rslt =
  6102. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6103. dev_addr,
  6104. BMI160_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE__REG,
  6105. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6106. *v_intr_enable_zero_u8 =
  6107. BMI160_GET_BITSLICE(v_data_u8,
  6108. BMI160_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE);
  6109. break;
  6110. case BMI160_SINGLE_TAP_ENABLE:
  6111. /* read the single tap interrupt data */
  6112. com_rslt =
  6113. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6114. dev_addr,
  6115. BMI160_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE__REG,
  6116. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6117. *v_intr_enable_zero_u8 =
  6118. BMI160_GET_BITSLICE(v_data_u8,
  6119. BMI160_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE);
  6120. break;
  6121. case BMI160_ORIENT_ENABLE:
  6122. /* read the orient interrupt data */
  6123. com_rslt =
  6124. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6125. dev_addr, BMI160_USER_INTR_ENABLE_0_ORIENT_ENABLE__REG,
  6126. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6127. *v_intr_enable_zero_u8 =
  6128. BMI160_GET_BITSLICE(v_data_u8,
  6129. BMI160_USER_INTR_ENABLE_0_ORIENT_ENABLE);
  6130. break;
  6131. case BMI160_FLAT_ENABLE:
  6132. /* read the flat interrupt data */
  6133. com_rslt =
  6134. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6135. dev_addr, BMI160_USER_INTR_ENABLE_0_FLAT_ENABLE__REG,
  6136. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6137. *v_intr_enable_zero_u8 =
  6138. BMI160_GET_BITSLICE(v_data_u8,
  6139. BMI160_USER_INTR_ENABLE_0_FLAT_ENABLE);
  6140. break;
  6141. default:
  6142. com_rslt = E_BMI160_OUT_OF_RANGE;
  6143. break;
  6144. }
  6145. }
  6146. return com_rslt;
  6147. }
  6148. /*!
  6149. * @brief This API is used to set
  6150. * interrupt enable from the register 0x50 bit 0 to 7
  6151. *
  6152. *
  6153. *
  6154. *
  6155. * @param v_enable_u8 : Value which selects the interrupt
  6156. * v_enable_u8 | interrupt
  6157. * ---------------|---------------
  6158. * 0 | BMI160_ANY_MOTION_X_ENABLE
  6159. * 1 | BMI160_ANY_MOTION_Y_ENABLE
  6160. * 2 | BMI160_ANY_MOTION_Z_ENABLE
  6161. * 3 | BMI160_DOUBLE_TAP_ENABLE
  6162. * 4 | BMI160_SINGLE_TAP_ENABLE
  6163. * 5 | BMI160_ORIENT_ENABLE
  6164. * 6 | BMI160_FLAT_ENABLE
  6165. *
  6166. * @param v_intr_enable_zero_u8 : The interrupt enable value
  6167. * value | interrupt enable
  6168. * ----------|-------------------
  6169. * 0x01 | BMI160_ENABLE
  6170. * 0x00 | BMI160_DISABLE
  6171. *
  6172. *
  6173. *
  6174. * @return results of bus communication function
  6175. * @retval 0 -> Success
  6176. * @retval -1 -> Error
  6177. *
  6178. *
  6179. */
  6180. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_enable_0(
  6181. u8 v_enable_u8, u8 v_intr_enable_zero_u8)
  6182. {
  6183. /* variable used to return the status of communication result*/
  6184. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6185. u8 v_data_u8 = BMI160_INIT_VALUE;
  6186. /* check the p_bmi160 structure for NULL pointer assignment*/
  6187. if (p_bmi160 == BMI160_NULL) {
  6188. return E_BMI160_NULL_PTR;
  6189. } else {
  6190. switch (v_enable_u8) {
  6191. case BMI160_ANY_MOTION_X_ENABLE:
  6192. /* write any motion x*/
  6193. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6194. dev_addr, BMI160_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE__REG,
  6195. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6196. if (com_rslt == SUCCESS) {
  6197. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6198. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE,
  6199. v_intr_enable_zero_u8);
  6200. com_rslt +=
  6201. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6202. dev_addr,
  6203. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE__REG,
  6204. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6205. }
  6206. break;
  6207. case BMI160_ANY_MOTION_Y_ENABLE:
  6208. /* write any motion y*/
  6209. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6210. dev_addr, BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE__REG,
  6211. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6212. if (com_rslt == SUCCESS) {
  6213. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6214. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE,
  6215. v_intr_enable_zero_u8);
  6216. com_rslt +=
  6217. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6218. dev_addr,
  6219. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE__REG,
  6220. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6221. }
  6222. break;
  6223. case BMI160_ANY_MOTION_Z_ENABLE:
  6224. /* write any motion z*/
  6225. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6226. dev_addr, BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE__REG,
  6227. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6228. if (com_rslt == SUCCESS) {
  6229. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6230. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE,
  6231. v_intr_enable_zero_u8);
  6232. com_rslt +=
  6233. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6234. dev_addr,
  6235. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE__REG,
  6236. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6237. }
  6238. break;
  6239. case BMI160_DOUBLE_TAP_ENABLE:
  6240. /* write double tap*/
  6241. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6242. dev_addr, BMI160_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE__REG,
  6243. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6244. if (com_rslt == SUCCESS) {
  6245. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6246. BMI160_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE,
  6247. v_intr_enable_zero_u8);
  6248. com_rslt +=
  6249. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6250. dev_addr,
  6251. BMI160_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE__REG,
  6252. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6253. }
  6254. break;
  6255. case BMI160_SINGLE_TAP_ENABLE:
  6256. /* write single tap */
  6257. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6258. dev_addr, BMI160_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE__REG,
  6259. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6260. if (com_rslt == SUCCESS) {
  6261. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6262. BMI160_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE,
  6263. v_intr_enable_zero_u8);
  6264. com_rslt +=
  6265. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6266. dev_addr,
  6267. BMI160_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE__REG,
  6268. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6269. }
  6270. break;
  6271. case BMI160_ORIENT_ENABLE:
  6272. /* write orient interrupt*/
  6273. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6274. dev_addr, BMI160_USER_INTR_ENABLE_0_ORIENT_ENABLE__REG,
  6275. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6276. if (com_rslt == SUCCESS) {
  6277. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6278. BMI160_USER_INTR_ENABLE_0_ORIENT_ENABLE,
  6279. v_intr_enable_zero_u8);
  6280. com_rslt +=
  6281. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6282. dev_addr,
  6283. BMI160_USER_INTR_ENABLE_0_ORIENT_ENABLE__REG,
  6284. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6285. }
  6286. break;
  6287. case BMI160_FLAT_ENABLE:
  6288. /* write flat interrupt*/
  6289. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6290. dev_addr, BMI160_USER_INTR_ENABLE_0_FLAT_ENABLE__REG,
  6291. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6292. if (com_rslt == SUCCESS) {
  6293. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6294. BMI160_USER_INTR_ENABLE_0_FLAT_ENABLE,
  6295. v_intr_enable_zero_u8);
  6296. com_rslt +=
  6297. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6298. dev_addr,
  6299. BMI160_USER_INTR_ENABLE_0_FLAT_ENABLE__REG,
  6300. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6301. }
  6302. break;
  6303. default:
  6304. com_rslt = E_BMI160_OUT_OF_RANGE;
  6305. break;
  6306. }
  6307. /*Accel and Gyro power mode check */
  6308. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  6309. /*interface idle time delay */
  6310. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  6311. }
  6312. return com_rslt;
  6313. }
  6314. /*!
  6315. * @brief This API is used to read
  6316. * interrupt enable byte1 from the register 0x51 bit 0 to 6
  6317. * @brief It read the high_g_x,high_g_y,high_g_z,low_g_enable
  6318. * data ready, FIFO full and FIFO water mark.
  6319. *
  6320. *
  6321. *
  6322. * @param v_enable_u8 : The value of interrupt enable
  6323. * @param v_enable_u8 : Value which selects interrupt
  6324. * v_enable_u8 | interrupt
  6325. * ---------------|---------------
  6326. * 0 | BMI160_HIGH_G_X_ENABLE
  6327. * 1 | BMI160_HIGH_G_Y_ENABLE
  6328. * 2 | BMI160_HIGH_G_Z_ENABLE
  6329. * 3 | BMI160_LOW_G_ENABLE
  6330. * 4 | BMI160_DATA_RDY_ENABLE
  6331. * 5 | BMI160_FIFO_FULL_ENABLE
  6332. * 6 | BMI160_FIFO_WM_ENABLE
  6333. *
  6334. * @param v_intr_enable_1_u8 : The interrupt enable value
  6335. * value | interrupt enable
  6336. * ----------|-------------------
  6337. * 0x01 | BMI160_ENABLE
  6338. * 0x00 | BMI160_DISABLE
  6339. *
  6340. *
  6341. *
  6342. * @return results of bus communication function
  6343. * @retval 0 -> Success
  6344. * @retval -1 -> Error
  6345. *
  6346. *
  6347. */
  6348. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_enable_1(
  6349. u8 v_enable_u8, u8 *v_intr_enable_1_u8)
  6350. {
  6351. /* variable used to return the status of communication result*/
  6352. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6353. u8 v_data_u8 = BMI160_INIT_VALUE;
  6354. /* check the p_bmi160 structure for NULL pointer assignment*/
  6355. if (p_bmi160 == BMI160_NULL) {
  6356. return E_BMI160_NULL_PTR;
  6357. } else {
  6358. switch (v_enable_u8) {
  6359. case BMI160_HIGH_G_X_ENABLE:
  6360. /* read high_g_x interrupt*/
  6361. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6362. dev_addr,
  6363. BMI160_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE__REG,
  6364. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6365. *v_intr_enable_1_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6366. BMI160_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE);
  6367. break;
  6368. case BMI160_HIGH_G_Y_ENABLE:
  6369. /* read high_g_y interrupt*/
  6370. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6371. dev_addr,
  6372. BMI160_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE__REG,
  6373. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6374. *v_intr_enable_1_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6375. BMI160_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE);
  6376. break;
  6377. case BMI160_HIGH_G_Z_ENABLE:
  6378. /* read high_g_z interrupt*/
  6379. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6380. dev_addr,
  6381. BMI160_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE__REG,
  6382. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6383. *v_intr_enable_1_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6384. BMI160_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE);
  6385. break;
  6386. case BMI160_LOW_G_ENABLE:
  6387. /* read low_g interrupt */
  6388. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6389. dev_addr, BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG,
  6390. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6391. *v_intr_enable_1_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6392. BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE);
  6393. break;
  6394. case BMI160_DATA_RDY_ENABLE:
  6395. /* read data ready interrupt */
  6396. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6397. dev_addr,
  6398. BMI160_USER_INTR_ENABLE_1_DATA_RDY_ENABLE__REG,
  6399. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6400. *v_intr_enable_1_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6401. BMI160_USER_INTR_ENABLE_1_DATA_RDY_ENABLE);
  6402. break;
  6403. case BMI160_FIFO_FULL_ENABLE:
  6404. /* read FIFO full interrupt */
  6405. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6406. dev_addr,
  6407. BMI160_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE__REG,
  6408. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6409. *v_intr_enable_1_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6410. BMI160_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE);
  6411. break;
  6412. case BMI160_FIFO_WM_ENABLE:
  6413. /* read FIFO water mark interrupt */
  6414. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6415. dev_addr,
  6416. BMI160_USER_INTR_ENABLE_1_FIFO_WM_ENABLE__REG,
  6417. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6418. *v_intr_enable_1_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6419. BMI160_USER_INTR_ENABLE_1_FIFO_WM_ENABLE);
  6420. break;
  6421. default:
  6422. com_rslt = E_BMI160_OUT_OF_RANGE;
  6423. break;
  6424. }
  6425. }
  6426. return com_rslt;
  6427. }
  6428. /*!
  6429. * @brief This API is used to set
  6430. * interrupt enable byte1 from the register 0x51 bit 0 to 6
  6431. * @brief It read the high_g_x,high_g_y,high_g_z,low_g_enable
  6432. * data ready, FIFO full and FIFO water mark.
  6433. *
  6434. *
  6435. *
  6436. * @param v_enable_u8 : The value of interrupt enable
  6437. * @param v_enable_u8 : Value to select the interrupt
  6438. * v_enable_u8 | interrupt
  6439. * ---------------|---------------
  6440. * 0 | BMI160_HIGH_G_X_ENABLE
  6441. * 1 | BMI160_HIGH_G_Y_ENABLE
  6442. * 2 | BMI160_HIGH_G_Z_ENABLE
  6443. * 3 | BMI160_LOW_G_ENABLE
  6444. * 4 | BMI160_DATA_RDY_ENABLE
  6445. * 5 | BMI160_FIFO_FULL_ENABLE
  6446. * 6 | BMI160_FIFO_WM_ENABLE
  6447. *
  6448. * @param v_intr_enable_1_u8 : The interrupt enable value
  6449. * value | interrupt enable
  6450. * ----------|-------------------
  6451. * 0x01 | BMI160_ENABLE
  6452. * 0x00 | BMI160_DISABLE
  6453. *
  6454. *
  6455. *
  6456. * @return results of bus communication function
  6457. * @retval 0 -> Success
  6458. * @retval -1 -> Error
  6459. *
  6460. *
  6461. */
  6462. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_enable_1(
  6463. u8 v_enable_u8, u8 v_intr_enable_1_u8)
  6464. {
  6465. /* variable used to return the status of communication result*/
  6466. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6467. u8 v_data_u8 = BMI160_INIT_VALUE;
  6468. /* check the p_bmi160 structure for NULL pointer assignment*/
  6469. if (p_bmi160 == BMI160_NULL) {
  6470. return E_BMI160_NULL_PTR;
  6471. } else {
  6472. switch (v_enable_u8) {
  6473. case BMI160_HIGH_G_X_ENABLE:
  6474. /* write high_g_x interrupt*/
  6475. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6476. dev_addr,
  6477. BMI160_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE__REG,
  6478. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6479. if (com_rslt == SUCCESS) {
  6480. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6481. BMI160_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE,
  6482. v_intr_enable_1_u8);
  6483. com_rslt +=
  6484. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6485. dev_addr,
  6486. BMI160_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE__REG,
  6487. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6488. }
  6489. break;
  6490. case BMI160_HIGH_G_Y_ENABLE:
  6491. /* write high_g_y interrupt*/
  6492. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6493. dev_addr,
  6494. BMI160_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE__REG,
  6495. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6496. if (com_rslt == SUCCESS) {
  6497. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6498. BMI160_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE,
  6499. v_intr_enable_1_u8);
  6500. com_rslt +=
  6501. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6502. dev_addr,
  6503. BMI160_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE__REG,
  6504. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6505. }
  6506. break;
  6507. case BMI160_HIGH_G_Z_ENABLE:
  6508. /* write high_g_z interrupt*/
  6509. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6510. dev_addr,
  6511. BMI160_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE__REG,
  6512. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6513. if (com_rslt == SUCCESS) {
  6514. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6515. BMI160_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE,
  6516. v_intr_enable_1_u8);
  6517. com_rslt +=
  6518. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6519. dev_addr,
  6520. BMI160_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE__REG,
  6521. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6522. }
  6523. break;
  6524. case BMI160_LOW_G_ENABLE:
  6525. /* write low_g interrupt*/
  6526. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6527. dev_addr,
  6528. BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG,
  6529. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6530. if (com_rslt == SUCCESS) {
  6531. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6532. BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE,
  6533. v_intr_enable_1_u8);
  6534. com_rslt +=
  6535. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6536. dev_addr,
  6537. BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG,
  6538. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6539. }
  6540. break;
  6541. case BMI160_DATA_RDY_ENABLE:
  6542. /* write data ready interrupt*/
  6543. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6544. dev_addr,
  6545. BMI160_USER_INTR_ENABLE_1_DATA_RDY_ENABLE__REG,
  6546. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6547. if (com_rslt == SUCCESS) {
  6548. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6549. BMI160_USER_INTR_ENABLE_1_DATA_RDY_ENABLE,
  6550. v_intr_enable_1_u8);
  6551. com_rslt +=
  6552. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6553. dev_addr,
  6554. BMI160_USER_INTR_ENABLE_1_DATA_RDY_ENABLE__REG,
  6555. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6556. }
  6557. break;
  6558. case BMI160_FIFO_FULL_ENABLE:
  6559. /* write FIFO full interrupt*/
  6560. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6561. dev_addr,
  6562. BMI160_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE__REG,
  6563. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6564. if (com_rslt == SUCCESS) {
  6565. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6566. BMI160_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE,
  6567. v_intr_enable_1_u8);
  6568. com_rslt +=
  6569. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6570. dev_addr,
  6571. BMI160_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE__REG,
  6572. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6573. }
  6574. break;
  6575. case BMI160_FIFO_WM_ENABLE:
  6576. /* write FIFO water mark interrupt*/
  6577. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6578. dev_addr, BMI160_USER_INTR_ENABLE_1_FIFO_WM_ENABLE__REG,
  6579. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6580. if (com_rslt == SUCCESS) {
  6581. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6582. BMI160_USER_INTR_ENABLE_1_FIFO_WM_ENABLE,
  6583. v_intr_enable_1_u8);
  6584. com_rslt +=
  6585. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6586. dev_addr,
  6587. BMI160_USER_INTR_ENABLE_1_FIFO_WM_ENABLE__REG,
  6588. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6589. }
  6590. break;
  6591. default:
  6592. com_rslt = E_BMI160_OUT_OF_RANGE;
  6593. break;
  6594. }
  6595. /*Accel and Gyro power mode check*/
  6596. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  6597. /*interface idle time delay */
  6598. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  6599. }
  6600. return com_rslt;
  6601. }
  6602. /*!
  6603. * @brief This API is used to read
  6604. * interrupt enable byte2 from the register bit 0x52 bit 0 to 3
  6605. * @brief It reads no motion x,y and z
  6606. *
  6607. *
  6608. *
  6609. * @param v_enable_u8: The value of interrupt enable
  6610. * v_enable_u8 | interrupt
  6611. * ---------------|---------------
  6612. * 0 | BMI160_NOMOTION_X_ENABLE
  6613. * 1 | BMI160_NOMOTION_Y_ENABLE
  6614. * 2 | BMI160_NOMOTION_Z_ENABLE
  6615. *
  6616. * @param v_intr_enable_2_u8 : The interrupt enable value
  6617. * value | interrupt enable
  6618. * ----------|-------------------
  6619. * 0x01 | BMI160_ENABLE
  6620. * 0x00 | BMI160_DISABLE
  6621. *
  6622. *
  6623. *
  6624. * @return results of bus communication function
  6625. * @retval 0 -> Success
  6626. * @retval -1 -> Error
  6627. *
  6628. *
  6629. */
  6630. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_enable_2(
  6631. u8 v_enable_u8, u8 *v_intr_enable_2_u8)
  6632. {
  6633. /* variable used to return the status of communication result*/
  6634. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6635. u8 v_data_u8 = BMI160_INIT_VALUE;
  6636. /* check the p_bmi160 structure for NULL pointer assignment*/
  6637. if (p_bmi160 == BMI160_NULL) {
  6638. return E_BMI160_NULL_PTR;
  6639. } else {
  6640. switch (v_enable_u8) {
  6641. case BMI160_NOMOTION_X_ENABLE:
  6642. /* read no motion x */
  6643. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6644. dev_addr,
  6645. BMI160_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE__REG,
  6646. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6647. *v_intr_enable_2_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6648. BMI160_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE);
  6649. break;
  6650. case BMI160_NOMOTION_Y_ENABLE:
  6651. /* read no motion y */
  6652. com_rslt =
  6653. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6654. dev_addr,
  6655. BMI160_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE__REG,
  6656. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6657. *v_intr_enable_2_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6658. BMI160_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE);
  6659. break;
  6660. case BMI160_NOMOTION_Z_ENABLE:
  6661. /* read no motion z */
  6662. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6663. dev_addr,
  6664. BMI160_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE__REG,
  6665. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6666. *v_intr_enable_2_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6667. BMI160_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE);
  6668. break;
  6669. default:
  6670. com_rslt = E_BMI160_OUT_OF_RANGE;
  6671. break;
  6672. }
  6673. }
  6674. return com_rslt;
  6675. }
  6676. /*!
  6677. * @brief This API is used to set
  6678. * interrupt enable byte2 from the register bit 0x52 bit 0 to 3
  6679. * @brief It reads no motion x,y and z
  6680. *
  6681. *
  6682. *
  6683. * @param v_enable_u8: The value of interrupt enable
  6684. * v_enable_u8 | interrupt
  6685. * ---------------|---------------
  6686. * 0 | BMI160_NOMOTION_X_ENABLE
  6687. * 1 | BMI160_NOMOTION_Y_ENABLE
  6688. * 2 | BMI160_NOMOTION_Z_ENABLE
  6689. *
  6690. * @param v_intr_enable_2_u8 : The interrupt enable value
  6691. * value | interrupt enable
  6692. * ----------|-------------------
  6693. * 0x01 | BMI160_ENABLE
  6694. * 0x00 | BMI160_DISABLE
  6695. *
  6696. *
  6697. *
  6698. * @return results of bus communication function
  6699. * @retval 0 -> Success
  6700. * @retval -1 -> Error
  6701. *
  6702. *
  6703. */
  6704. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_enable_2(
  6705. u8 v_enable_u8, u8 v_intr_enable_2_u8)
  6706. {
  6707. /* variable used to return the status of communication result*/
  6708. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6709. u8 v_data_u8 = BMI160_INIT_VALUE;
  6710. /* check the p_bmi160 structure for NULL pointer assignment*/
  6711. if (p_bmi160 == BMI160_NULL) {
  6712. return E_BMI160_NULL_PTR;
  6713. } else {
  6714. switch (v_enable_u8) {
  6715. case BMI160_NOMOTION_X_ENABLE:
  6716. /* write no motion x */
  6717. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6718. dev_addr,
  6719. BMI160_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE__REG,
  6720. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6721. if (com_rslt == SUCCESS) {
  6722. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6723. BMI160_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE,
  6724. v_intr_enable_2_u8);
  6725. com_rslt +=
  6726. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6727. dev_addr,
  6728. BMI160_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE__REG,
  6729. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6730. }
  6731. break;
  6732. case BMI160_NOMOTION_Y_ENABLE:
  6733. /* write no motion y */
  6734. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6735. dev_addr,
  6736. BMI160_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE__REG,
  6737. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6738. if (com_rslt == SUCCESS) {
  6739. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6740. BMI160_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE,
  6741. v_intr_enable_2_u8);
  6742. com_rslt +=
  6743. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6744. dev_addr,
  6745. BMI160_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE__REG,
  6746. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6747. }
  6748. break;
  6749. case BMI160_NOMOTION_Z_ENABLE:
  6750. /* write no motion z */
  6751. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6752. dev_addr,
  6753. BMI160_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE__REG,
  6754. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6755. if (com_rslt == SUCCESS) {
  6756. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6757. BMI160_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE,
  6758. v_intr_enable_2_u8);
  6759. com_rslt +=
  6760. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6761. dev_addr,
  6762. BMI160_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE__REG,
  6763. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6764. }
  6765. break;
  6766. default:
  6767. com_rslt = E_BMI160_OUT_OF_RANGE;
  6768. break;
  6769. }
  6770. /*Accel and Gyro power mode check*/
  6771. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  6772. /*interface idle time delay */
  6773. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  6774. }
  6775. return com_rslt;
  6776. }
  6777. /*!
  6778. * @brief This API is used to read
  6779. * interrupt enable step detector interrupt from
  6780. * the register bit 0x52 bit 3
  6781. *
  6782. *
  6783. *
  6784. *
  6785. * @param v_step_intr_u8 : The value of step detector interrupt enable
  6786. *
  6787. *
  6788. *
  6789. * @return results of bus communication function
  6790. * @retval 0 -> Success
  6791. * @retval -1 -> Error
  6792. *
  6793. *
  6794. */
  6795. BMI160_RETURN_FUNCTION_TYPE bmi160_get_step_detector_enable(
  6796. u8 *v_step_intr_u8)
  6797. {
  6798. /* variable used to return the status of communication result*/
  6799. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6800. u8 v_data_u8 = BMI160_INIT_VALUE;
  6801. /* check the p_bmi160 structure for NULL pointer assignment*/
  6802. if (p_bmi160 == BMI160_NULL) {
  6803. return E_BMI160_NULL_PTR;
  6804. } else {
  6805. /* read the step detector interrupt*/
  6806. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6807. dev_addr,
  6808. BMI160_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE__REG,
  6809. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6810. *v_step_intr_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6811. BMI160_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE);
  6812. }
  6813. return com_rslt;
  6814. }
  6815. /*!
  6816. * @brief This API is used to set
  6817. * interrupt enable step detector interrupt from
  6818. * the register bit 0x52 bit 3
  6819. *
  6820. *
  6821. *
  6822. *
  6823. * @param v_step_intr_u8 : The value of step detector interrupt enable
  6824. *
  6825. *
  6826. *
  6827. * @return results of bus communication function
  6828. * @retval 0 -> Success
  6829. * @retval -1 -> Error
  6830. *
  6831. *
  6832. */
  6833. BMI160_RETURN_FUNCTION_TYPE bmi160_set_step_detector_enable(
  6834. u8 v_step_intr_u8)
  6835. {
  6836. /* variable used to return the status of communication result*/
  6837. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6838. u8 v_data_u8 = BMI160_INIT_VALUE;
  6839. /* check the p_bmi160 structure for NULL pointer assignment*/
  6840. if (p_bmi160 == BMI160_NULL) {
  6841. return E_BMI160_NULL_PTR;
  6842. } else {
  6843. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6844. dev_addr,
  6845. BMI160_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE__REG,
  6846. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6847. if (com_rslt == SUCCESS) {
  6848. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6849. BMI160_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE,
  6850. v_step_intr_u8);
  6851. com_rslt +=
  6852. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6853. dev_addr,
  6854. BMI160_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE__REG,
  6855. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6856. /*Accel and Gyro power mode check*/
  6857. if (bmi160_power_mode_status_u8_g !=
  6858. BMI160_NORMAL_MODE)
  6859. /*interface idle time delay */
  6860. p_bmi160->delay_msec(
  6861. BMI160_GEN_READ_WRITE_DELAY);
  6862. }
  6863. }
  6864. return com_rslt;
  6865. }
  6866. /*!
  6867. * @brief This API reads trigger condition of interrupt1
  6868. * and interrupt2 pin from the register 0x53
  6869. * @brief interrupt1 - bit 0
  6870. * @brief interrupt2 - bit 4
  6871. *
  6872. * @param v_channel_u8: The value of edge trigger selection
  6873. * v_channel_u8 | Edge trigger
  6874. * ---------------|---------------
  6875. * 0 | BMI160_INTR1_EDGE_CTRL
  6876. * 1 | BMI160_INTR2_EDGE_CTRL
  6877. *
  6878. * @param v_intr_edge_ctrl_u8 : The value of edge trigger enable
  6879. * value | interrupt enable
  6880. * ----------|-------------------
  6881. * 0x01 | BMI160_EDGE
  6882. * 0x00 | BMI160_LEVEL
  6883. *
  6884. * @return results of bus communication function
  6885. * @retval 0 -> Success
  6886. * @retval -1 -> Error
  6887. *
  6888. *
  6889. */
  6890. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_edge_ctrl(
  6891. u8 v_channel_u8, u8 *v_intr_edge_ctrl_u8)
  6892. {
  6893. /* variable used to return the status of communication result*/
  6894. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6895. u8 v_data_u8 = BMI160_INIT_VALUE;
  6896. /* check the p_bmi160 structure for NULL pointer assignment*/
  6897. if (p_bmi160 == BMI160_NULL) {
  6898. return E_BMI160_NULL_PTR;
  6899. } else {
  6900. switch (v_channel_u8) {
  6901. case BMI160_INTR1_EDGE_CTRL:
  6902. /* read the edge trigger interrupt1*/
  6903. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6904. dev_addr, BMI160_USER_INTR1_EDGE_CTRL__REG,
  6905. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6906. *v_intr_edge_ctrl_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6907. BMI160_USER_INTR1_EDGE_CTRL);
  6908. break;
  6909. case BMI160_INTR2_EDGE_CTRL:
  6910. /* read the edge trigger interrupt2*/
  6911. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6912. dev_addr, BMI160_USER_INTR2_EDGE_CTRL__REG,
  6913. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6914. *v_intr_edge_ctrl_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6915. BMI160_USER_INTR2_EDGE_CTRL);
  6916. break;
  6917. default:
  6918. com_rslt = E_BMI160_OUT_OF_RANGE;
  6919. break;
  6920. }
  6921. }
  6922. return com_rslt;
  6923. }
  6924. /*!
  6925. * @brief This API configures trigger condition of interrupt1
  6926. * and interrupt2 pin from the register 0x53
  6927. * @brief interrupt1 - bit 0
  6928. * @brief interrupt2 - bit 4
  6929. *
  6930. * @param v_channel_u8: The value of edge trigger selection
  6931. * v_channel_u8 | Edge trigger
  6932. * ---------------|---------------
  6933. * 0 | BMI160_INTR1_EDGE_CTRL
  6934. * 1 | BMI160_INTR2_EDGE_CTRL
  6935. *
  6936. * @param v_intr_edge_ctrl_u8 : The value of edge trigger enable
  6937. * value | interrupt enable
  6938. * ----------|-------------------
  6939. * 0x01 | BMI160_EDGE
  6940. * 0x00 | BMI160_LEVEL
  6941. *
  6942. * @return results of bus communication function
  6943. * @retval 0 -> Success
  6944. * @retval -1 -> Error
  6945. *
  6946. *
  6947. */
  6948. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_edge_ctrl(
  6949. u8 v_channel_u8, u8 v_intr_edge_ctrl_u8)
  6950. {
  6951. /* variable used to return the status of communication result*/
  6952. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6953. u8 v_data_u8 = BMI160_INIT_VALUE;
  6954. /* check the p_bmi160 structure for NULL pointer assignment*/
  6955. if (p_bmi160 == BMI160_NULL) {
  6956. return E_BMI160_NULL_PTR;
  6957. } else {
  6958. switch (v_channel_u8) {
  6959. case BMI160_INTR1_EDGE_CTRL:
  6960. /* write the edge trigger interrupt1*/
  6961. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6962. dev_addr, BMI160_USER_INTR1_EDGE_CTRL__REG,
  6963. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6964. if (com_rslt == SUCCESS) {
  6965. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6966. BMI160_USER_INTR1_EDGE_CTRL,
  6967. v_intr_edge_ctrl_u8);
  6968. com_rslt +=
  6969. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6970. dev_addr, BMI160_USER_INTR1_EDGE_CTRL__REG,
  6971. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6972. }
  6973. break;
  6974. case BMI160_INTR2_EDGE_CTRL:
  6975. /* write the edge trigger interrupt2*/
  6976. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6977. dev_addr, BMI160_USER_INTR2_EDGE_CTRL__REG,
  6978. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6979. if (com_rslt == SUCCESS) {
  6980. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6981. BMI160_USER_INTR2_EDGE_CTRL,
  6982. v_intr_edge_ctrl_u8);
  6983. com_rslt +=
  6984. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6985. dev_addr, BMI160_USER_INTR2_EDGE_CTRL__REG,
  6986. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  6987. }
  6988. break;
  6989. default:
  6990. com_rslt = E_BMI160_OUT_OF_RANGE;
  6991. break;
  6992. }
  6993. /*Accel and Gyro power mode check*/
  6994. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  6995. /*interface idle time delay */
  6996. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  6997. }
  6998. return com_rslt;
  6999. }
  7000. /*!
  7001. * @brief This API is used to get the configure level condition of
  7002. * interrupt1 and interrupt2 pin from the register 0x53
  7003. * @brief interrupt1 - bit 1
  7004. * @brief interrupt2 - bit 5
  7005. *
  7006. * @param v_channel_u8: The value of level condition selection
  7007. * v_channel_u8 | level selection
  7008. * ---------------|---------------
  7009. * 0 | BMI160_INTR1_LEVEL
  7010. * 1 | BMI160_INTR2_LEVEL
  7011. *
  7012. * @param v_intr_level_u8 : The value of level of interrupt enable
  7013. * value | Behaviour
  7014. * ----------|-------------------
  7015. * 0x01 | BMI160_LEVEL_HIGH
  7016. * 0x00 | BMI160_LEVEL_LOW
  7017. *
  7018. * @return results of bus communication function
  7019. * @retval 0 -> Success
  7020. * @retval -1 -> Error
  7021. *
  7022. *
  7023. */
  7024. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_level(
  7025. u8 v_channel_u8, u8 *v_intr_level_u8)
  7026. {
  7027. /* variable used to return the status of communication result*/
  7028. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7029. u8 v_data_u8 = BMI160_INIT_VALUE;
  7030. /* check the p_bmi160 structure for NULL pointer assignment*/
  7031. if (p_bmi160 == BMI160_NULL) {
  7032. return E_BMI160_NULL_PTR;
  7033. } else {
  7034. switch (v_channel_u8) {
  7035. case BMI160_INTR1_LEVEL:
  7036. /* read the interrupt1 level*/
  7037. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7038. dev_addr, BMI160_USER_INTR1_LEVEL__REG,
  7039. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7040. *v_intr_level_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7041. BMI160_USER_INTR1_LEVEL);
  7042. break;
  7043. case BMI160_INTR2_LEVEL:
  7044. /* read the interrupt2 level*/
  7045. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7046. dev_addr, BMI160_USER_INTR2_LEVEL__REG,
  7047. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7048. *v_intr_level_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7049. BMI160_USER_INTR2_LEVEL);
  7050. break;
  7051. default:
  7052. com_rslt = E_BMI160_OUT_OF_RANGE;
  7053. break;
  7054. }
  7055. }
  7056. return com_rslt;
  7057. }
  7058. /*!
  7059. * @brief This API is used to set the configure level condition of
  7060. * interrupt1 and interrupt2 pin from the register 0x53
  7061. * @brief interrupt1 - bit 1
  7062. * @brief interrupt2 - bit 5
  7063. *
  7064. * @param v_channel_u8: The value of level condition selection
  7065. * v_channel_u8 | level selection
  7066. * ---------------|---------------
  7067. * 0 | BMI160_INTR1_LEVEL
  7068. * 1 | BMI160_INTR2_LEVEL
  7069. *
  7070. * @param v_intr_level_u8 : The value of level of interrupt enable
  7071. * value | Behaviour
  7072. * ----------|-------------------
  7073. * 0x01 | BMI160_LEVEL_HIGH
  7074. * 0x00 | BMI160_LEVEL_LOW
  7075. *
  7076. * @return results of bus communication function
  7077. * @retval 0 -> Success
  7078. * @retval -1 -> Error
  7079. *
  7080. *
  7081. */
  7082. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_level(
  7083. u8 v_channel_u8, u8 v_intr_level_u8)
  7084. {
  7085. /* variable used to return the status of communication result*/
  7086. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7087. u8 v_data_u8 = BMI160_INIT_VALUE;
  7088. /* check the p_bmi160 structure for NULL pointer assignment*/
  7089. if (p_bmi160 == BMI160_NULL) {
  7090. return E_BMI160_NULL_PTR;
  7091. } else {
  7092. switch (v_channel_u8) {
  7093. case BMI160_INTR1_LEVEL:
  7094. /* write the interrupt1 level*/
  7095. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7096. dev_addr, BMI160_USER_INTR1_LEVEL__REG,
  7097. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7098. if (com_rslt == SUCCESS) {
  7099. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7100. BMI160_USER_INTR1_LEVEL, v_intr_level_u8);
  7101. com_rslt +=
  7102. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7103. dev_addr, BMI160_USER_INTR1_LEVEL__REG,
  7104. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7105. }
  7106. break;
  7107. case BMI160_INTR2_LEVEL:
  7108. /* write the interrupt2 level*/
  7109. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7110. dev_addr, BMI160_USER_INTR2_LEVEL__REG,
  7111. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7112. if (com_rslt == SUCCESS) {
  7113. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7114. BMI160_USER_INTR2_LEVEL, v_intr_level_u8);
  7115. com_rslt +=
  7116. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7117. dev_addr, BMI160_USER_INTR2_LEVEL__REG,
  7118. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7119. }
  7120. break;
  7121. default:
  7122. com_rslt = E_BMI160_OUT_OF_RANGE;
  7123. break;
  7124. }
  7125. /*Accel and Gyro power mode check*/
  7126. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  7127. /*interface idle time delay */
  7128. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  7129. }
  7130. return com_rslt;
  7131. }
  7132. /*!
  7133. * @brief This API is used to get configured output enable of interrupt1
  7134. * and interrupt2 from the register 0x53
  7135. * @brief interrupt1 - bit 2
  7136. * @brief interrupt2 - bit 6
  7137. *
  7138. *
  7139. * @param v_channel_u8: The value of output type enable selection
  7140. * v_channel_u8 | level selection
  7141. * ---------------|---------------
  7142. * 0 | BMI160_INTR1_OUTPUT_TYPE
  7143. * 1 | BMI160_INTR2_OUTPUT_TYPE
  7144. *
  7145. * @param v_intr_output_type_u8 :
  7146. * The value of output type of interrupt enable
  7147. * value | Behaviour
  7148. * ----------|-------------------
  7149. * 0x01 | BMI160_OPEN_DRAIN
  7150. * 0x00 | BMI160_PUSH_PULL
  7151. *
  7152. *
  7153. * @return results of bus communication function
  7154. * @retval 0 -> Success
  7155. * @retval -1 -> Error
  7156. *
  7157. *
  7158. */
  7159. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_output_type(
  7160. u8 v_channel_u8, u8 *v_intr_output_type_u8)
  7161. {
  7162. /* variable used to return the status of communication result*/
  7163. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7164. u8 v_data_u8 = BMI160_INIT_VALUE;
  7165. /* check the p_bmi160 structure for NULL pointer assignment*/
  7166. if (p_bmi160 == BMI160_NULL) {
  7167. return E_BMI160_NULL_PTR;
  7168. } else {
  7169. switch (v_channel_u8) {
  7170. case BMI160_INTR1_OUTPUT_TYPE:
  7171. /* read the output type of interrupt1*/
  7172. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7173. dev_addr, BMI160_USER_INTR1_OUTPUT_TYPE__REG,
  7174. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7175. *v_intr_output_type_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7176. BMI160_USER_INTR1_OUTPUT_TYPE);
  7177. break;
  7178. case BMI160_INTR2_OUTPUT_TYPE:
  7179. /* read the output type of interrupt2*/
  7180. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7181. dev_addr, BMI160_USER_INTR2_OUTPUT_TYPE__REG,
  7182. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7183. *v_intr_output_type_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7184. BMI160_USER_INTR2_OUTPUT_TYPE);
  7185. break;
  7186. default:
  7187. com_rslt = E_BMI160_OUT_OF_RANGE;
  7188. break;
  7189. }
  7190. }
  7191. return com_rslt;
  7192. }
  7193. /*!
  7194. * @brief This API is used to set output enable of interrupt1
  7195. * and interrupt2 from the register 0x53
  7196. * @brief interrupt1 - bit 2
  7197. * @brief interrupt2 - bit 6
  7198. *
  7199. *
  7200. * @param v_channel_u8: The value of output type enable selection
  7201. * v_channel_u8 | level selection
  7202. * ---------------|---------------
  7203. * 0 | BMI160_INTR1_OUTPUT_TYPE
  7204. * 1 | BMI160_INTR2_OUTPUT_TYPE
  7205. *
  7206. * @param v_intr_output_type_u8 :
  7207. * The value of output type of interrupt enable
  7208. * value | Behaviour
  7209. * ----------|-------------------
  7210. * 0x01 | BMI160_OPEN_DRAIN
  7211. * 0x00 | BMI160_PUSH_PULL
  7212. *
  7213. *
  7214. * @return results of bus communication function
  7215. * @retval 0 -> Success
  7216. * @retval -1 -> Error
  7217. *
  7218. *
  7219. */
  7220. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_output_type(
  7221. u8 v_channel_u8, u8 v_intr_output_type_u8)
  7222. {
  7223. /* variable used to return the status of communication result*/
  7224. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7225. u8 v_data_u8 = BMI160_INIT_VALUE;
  7226. /* check the p_bmi160 structure for NULL pointer assignment*/
  7227. if (p_bmi160 == BMI160_NULL) {
  7228. return E_BMI160_NULL_PTR;
  7229. } else {
  7230. switch (v_channel_u8) {
  7231. case BMI160_INTR1_OUTPUT_TYPE:
  7232. /* write the output type of interrupt1*/
  7233. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7234. dev_addr, BMI160_USER_INTR1_OUTPUT_TYPE__REG,
  7235. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7236. if (com_rslt == SUCCESS) {
  7237. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7238. BMI160_USER_INTR1_OUTPUT_TYPE,
  7239. v_intr_output_type_u8);
  7240. com_rslt +=
  7241. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7242. dev_addr, BMI160_USER_INTR1_OUTPUT_TYPE__REG,
  7243. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7244. }
  7245. break;
  7246. case BMI160_INTR2_OUTPUT_TYPE:
  7247. /* write the output type of interrupt2*/
  7248. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7249. dev_addr, BMI160_USER_INTR2_OUTPUT_TYPE__REG,
  7250. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7251. if (com_rslt == SUCCESS) {
  7252. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7253. BMI160_USER_INTR2_OUTPUT_TYPE,
  7254. v_intr_output_type_u8);
  7255. com_rslt +=
  7256. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7257. dev_addr, BMI160_USER_INTR2_OUTPUT_TYPE__REG,
  7258. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7259. }
  7260. break;
  7261. default:
  7262. com_rslt = E_BMI160_OUT_OF_RANGE;
  7263. break;
  7264. }
  7265. /*Accel and Gyro power mode check*/
  7266. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  7267. /*interface idle time delay */
  7268. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  7269. }
  7270. return com_rslt;
  7271. }
  7272. /*!
  7273. * @brief This API is used to get the output enable for interrupt1
  7274. * and interrupt2 pin from the register 0x53
  7275. * @brief interrupt1 - bit 3
  7276. * @brief interrupt2 - bit 7
  7277. *
  7278. * @param v_channel_u8: The value of output enable selection
  7279. * v_channel_u8 | level selection
  7280. * ---------------|---------------
  7281. * 0 | BMI160_INTR1_OUTPUT_ENABLE
  7282. * 1 | BMI160_INTR2_OUTPUT_ENABLE
  7283. *
  7284. * @param v_output_enable_u8 :
  7285. * The value of output enable of interrupt enable
  7286. * value | Behaviour
  7287. * ----------|-------------------
  7288. * 0x01 | INTERRUPT OUTPUT ENABLED
  7289. * 0x00 | INTERRUPT OUTPUT DISABLED
  7290. *
  7291. *
  7292. *
  7293. * @return results of bus communication function
  7294. * @retval 0 -> Success
  7295. * @retval -1 -> Error
  7296. *
  7297. *
  7298. */
  7299. BMI160_RETURN_FUNCTION_TYPE bmi160_get_output_enable(
  7300. u8 v_channel_u8, u8 *v_output_enable_u8)
  7301. {
  7302. /* variable used to return the status of communication result*/
  7303. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7304. u8 v_data_u8 = BMI160_INIT_VALUE;
  7305. /* check the p_bmi160 structure for NULL pointer assignment*/
  7306. if (p_bmi160 == BMI160_NULL) {
  7307. return E_BMI160_NULL_PTR;
  7308. } else {
  7309. switch (v_channel_u8) {
  7310. case BMI160_INTR1_OUTPUT_ENABLE:
  7311. /* read the output enable of interrupt1*/
  7312. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7313. dev_addr, BMI160_USER_INTR1_OUTPUT_ENABLE__REG,
  7314. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7315. *v_output_enable_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7316. BMI160_USER_INTR1_OUTPUT_ENABLE);
  7317. break;
  7318. case BMI160_INTR2_OUTPUT_ENABLE:
  7319. /* read the output enable of interrupt2*/
  7320. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7321. dev_addr, BMI160_USER_INTR2_OUTPUT_EN__REG,
  7322. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7323. *v_output_enable_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7324. BMI160_USER_INTR2_OUTPUT_EN);
  7325. break;
  7326. default:
  7327. com_rslt = E_BMI160_OUT_OF_RANGE;
  7328. break;
  7329. }
  7330. }
  7331. return com_rslt;
  7332. }
  7333. /*!
  7334. * @brief This API is used to set the Output enable for interrupt1
  7335. * and interrupt2 pin from the register 0x53
  7336. * @brief interrupt1 - bit 3
  7337. * @brief interrupt2 - bit 7
  7338. *
  7339. * @param v_channel_u8: The value of output enable selection
  7340. * v_channel_u8 | level selection
  7341. * ---------------|---------------
  7342. * 0 | BMI160_INTR1_OUTPUT_ENABLE
  7343. * 1 | BMI160_INTR2_OUTPUT_ENABLE
  7344. *
  7345. * @param v_output_enable_u8 :
  7346. * The value of output enable of interrupt enable
  7347. * value | Behaviour
  7348. * ----------|-------------------
  7349. * 0x01 | INTERRUPT OUTPUT ENABLED
  7350. * 0x00 | INTERRUPT OUTPUT DISABLED
  7351. *
  7352. *
  7353. *
  7354. * @return results of bus communication function
  7355. * @retval 0 -> Success
  7356. * @retval -1 -> Error
  7357. *
  7358. *
  7359. */
  7360. BMI160_RETURN_FUNCTION_TYPE bmi160_set_output_enable(
  7361. u8 v_channel_u8, u8 v_output_enable_u8)
  7362. {
  7363. /* variable used to return the status of communication result*/
  7364. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7365. u8 v_data_u8 = BMI160_INIT_VALUE;
  7366. /* check the p_bmi160 structure for NULL pointer assignment*/
  7367. if (p_bmi160 == BMI160_NULL) {
  7368. return E_BMI160_NULL_PTR;
  7369. } else {
  7370. switch (v_channel_u8) {
  7371. case BMI160_INTR1_OUTPUT_ENABLE:
  7372. /* write the output enable of interrupt1*/
  7373. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7374. dev_addr, BMI160_USER_INTR1_OUTPUT_ENABLE__REG,
  7375. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7376. if (com_rslt == SUCCESS) {
  7377. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7378. BMI160_USER_INTR1_OUTPUT_ENABLE,
  7379. v_output_enable_u8);
  7380. com_rslt +=
  7381. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7382. dev_addr, BMI160_USER_INTR1_OUTPUT_ENABLE__REG,
  7383. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7384. }
  7385. break;
  7386. case BMI160_INTR2_OUTPUT_ENABLE:
  7387. /* write the output enable of interrupt2*/
  7388. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7389. dev_addr, BMI160_USER_INTR2_OUTPUT_EN__REG,
  7390. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7391. if (com_rslt == SUCCESS) {
  7392. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7393. BMI160_USER_INTR2_OUTPUT_EN,
  7394. v_output_enable_u8);
  7395. com_rslt +=
  7396. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7397. dev_addr, BMI160_USER_INTR2_OUTPUT_EN__REG,
  7398. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7399. }
  7400. break;
  7401. default:
  7402. com_rslt = E_BMI160_OUT_OF_RANGE;
  7403. break;
  7404. }
  7405. /*Accel and Gyro power mode check*/
  7406. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  7407. /*interface idle time delay */
  7408. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  7409. }
  7410. return com_rslt;
  7411. }
  7412. /*!
  7413. * @brief This API is used to get the latch duration
  7414. * from the register 0x54 bit 0 to 3
  7415. * @brief This latch selection is not applicable for data ready,
  7416. * orientation and flat interrupts.
  7417. *
  7418. *
  7419. *
  7420. * @param v_latch_intr_u8 : The value of latch duration
  7421. * Latch Duration | value
  7422. * --------------------------------------|------------------
  7423. * BMI160_LATCH_DUR_NONE | 0x00
  7424. * BMI160_LATCH_DUR_312_5_MICRO_SEC | 0x01
  7425. * BMI160_LATCH_DUR_625_MICRO_SEC | 0x02
  7426. * BMI160_LATCH_DUR_1_25_MILLI_SEC | 0x03
  7427. * BMI160_LATCH_DUR_2_5_MILLI_SEC | 0x04
  7428. * BMI160_LATCH_DUR_5_MILLI_SEC | 0x05
  7429. * BMI160_LATCH_DUR_10_MILLI_SEC | 0x06
  7430. * BMI160_LATCH_DUR_20_MILLI_SEC | 0x07
  7431. * BMI160_LATCH_DUR_40_MILLI_SEC | 0x08
  7432. * BMI160_LATCH_DUR_80_MILLI_SEC | 0x09
  7433. * BMI160_LATCH_DUR_160_MILLI_SEC | 0x0A
  7434. * BMI160_LATCH_DUR_320_MILLI_SEC | 0x0B
  7435. * BMI160_LATCH_DUR_640_MILLI_SEC | 0x0C
  7436. * BMI160_LATCH_DUR_1_28_SEC | 0x0D
  7437. * BMI160_LATCH_DUR_2_56_SEC | 0x0E
  7438. * BMI160_LATCHED | 0x0F
  7439. *
  7440. *
  7441. *
  7442. * @return results of bus communication function
  7443. * @retval 0 -> Success
  7444. * @retval -1 -> Error
  7445. *
  7446. *
  7447. */
  7448. BMI160_RETURN_FUNCTION_TYPE bmi160_get_latch_intr(
  7449. u8 *v_latch_intr_u8)
  7450. {
  7451. /* variable used to return the status of communication result*/
  7452. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7453. u8 v_data_u8 = BMI160_INIT_VALUE;
  7454. /* check the p_bmi160 structure for NULL pointer assignment*/
  7455. if (p_bmi160 == BMI160_NULL) {
  7456. return E_BMI160_NULL_PTR;
  7457. } else {
  7458. /* read the latch duration value */
  7459. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7460. dev_addr, BMI160_USER_INTR_LATCH__REG,
  7461. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7462. *v_latch_intr_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7463. BMI160_USER_INTR_LATCH);
  7464. }
  7465. return com_rslt;
  7466. }
  7467. /*!
  7468. * @brief This API is used to set the latch duration
  7469. * from the register 0x54 bit 0 to 3
  7470. * @brief This latch selection is not applicable for data ready,
  7471. * orientation and flat interrupts.
  7472. *
  7473. *
  7474. *
  7475. * @param v_latch_intr_u8 : The value of latch duration
  7476. * Latch Duration | value
  7477. * --------------------------------------|------------------
  7478. * BMI160_LATCH_DUR_NONE | 0x00
  7479. * BMI160_LATCH_DUR_312_5_MICRO_SEC | 0x01
  7480. * BMI160_LATCH_DUR_625_MICRO_SEC | 0x02
  7481. * BMI160_LATCH_DUR_1_25_MILLI_SEC | 0x03
  7482. * BMI160_LATCH_DUR_2_5_MILLI_SEC | 0x04
  7483. * BMI160_LATCH_DUR_5_MILLI_SEC | 0x05
  7484. * BMI160_LATCH_DUR_10_MILLI_SEC | 0x06
  7485. * BMI160_LATCH_DUR_20_MILLI_SEC | 0x07
  7486. * BMI160_LATCH_DUR_40_MILLI_SEC | 0x08
  7487. * BMI160_LATCH_DUR_80_MILLI_SEC | 0x09
  7488. * BMI160_LATCH_DUR_160_MILLI_SEC | 0x0A
  7489. * BMI160_LATCH_DUR_320_MILLI_SEC | 0x0B
  7490. * BMI160_LATCH_DUR_640_MILLI_SEC | 0x0C
  7491. * BMI160_LATCH_DUR_1_28_SEC | 0x0D
  7492. * BMI160_LATCH_DUR_2_56_SEC | 0x0E
  7493. * BMI160_LATCHED | 0x0F
  7494. *
  7495. *
  7496. *
  7497. * @return results of bus communication function
  7498. * @retval 0 -> Success
  7499. * @retval -1 -> Error
  7500. *
  7501. *
  7502. */
  7503. BMI160_RETURN_FUNCTION_TYPE bmi160_set_latch_intr(u8 v_latch_intr_u8)
  7504. {
  7505. u8 v_data_u8 = BMI160_INIT_VALUE;
  7506. /* variable used to return the status of communication result*/
  7507. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7508. /* check the p_bmi160 structure for NULL pointer assignment*/
  7509. if (p_bmi160 == BMI160_NULL) {
  7510. return E_BMI160_NULL_PTR;
  7511. } else {
  7512. if (v_latch_intr_u8 <= BMI160_MAX_LATCH_INTR) {
  7513. /* write the latch duration value */
  7514. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7515. dev_addr, BMI160_USER_INTR_LATCH__REG,
  7516. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7517. if (com_rslt == SUCCESS) {
  7518. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7519. BMI160_USER_INTR_LATCH, v_latch_intr_u8);
  7520. com_rslt +=
  7521. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7522. dev_addr, BMI160_USER_INTR_LATCH__REG,
  7523. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7524. /*Accel and Gyro power mode check*/
  7525. if (bmi160_power_mode_status_u8_g !=
  7526. BMI160_NORMAL_MODE)
  7527. /*interface idle time delay */
  7528. p_bmi160->delay_msec(
  7529. BMI160_GEN_READ_WRITE_DELAY);
  7530. }
  7531. } else {
  7532. com_rslt = E_BMI160_OUT_OF_RANGE;
  7533. }
  7534. }
  7535. return com_rslt;
  7536. }
  7537. /*!
  7538. * @brief API is used to get input enable for interrupt1
  7539. * and interrupt2 pin from the register 0x54
  7540. * @brief interrupt1 - bit 4
  7541. * @brief interrupt2 - bit 5
  7542. *
  7543. * @param v_channel_u8: The value of input enable selection
  7544. * v_channel_u8 | input selection
  7545. * ---------------|---------------
  7546. * 0 | BMI160_INTR1_INPUT_ENABLE
  7547. * 1 | BMI160_INTR2_INPUT_ENABLE
  7548. *
  7549. * @param v_input_en_u8 :
  7550. * The value of input enable of interrupt enable
  7551. * value | Behaviour
  7552. * ----------|-------------------
  7553. * 0x01 | BMI160_INPUT_ENABLED
  7554. * 0x00 | BMI160_INPUT_DISABLED
  7555. *
  7556. *
  7557. *
  7558. * @return results of bus communication function
  7559. * @retval 0 -> Success
  7560. * @retval -1 -> Error
  7561. *
  7562. *
  7563. */
  7564. BMI160_RETURN_FUNCTION_TYPE bmi160_get_input_enable(
  7565. u8 v_channel_u8, u8 *v_input_en_u8)
  7566. {
  7567. /* variable used to return the status of communication result*/
  7568. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7569. u8 v_data_u8 = BMI160_INIT_VALUE;
  7570. /* check the p_bmi160 structure for NULL pointer assignment*/
  7571. if (p_bmi160 == BMI160_NULL) {
  7572. return E_BMI160_NULL_PTR;
  7573. } else {
  7574. switch (v_channel_u8) {
  7575. /* read input enable of interrupt1 and interrupt2*/
  7576. case BMI160_INTR1_INPUT_ENABLE:
  7577. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7578. dev_addr, BMI160_USER_INTR1_INPUT_ENABLE__REG,
  7579. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7580. *v_input_en_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7581. BMI160_USER_INTR1_INPUT_ENABLE);
  7582. break;
  7583. case BMI160_INTR2_INPUT_ENABLE:
  7584. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7585. dev_addr, BMI160_USER_INTR2_INPUT_ENABLE__REG,
  7586. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7587. *v_input_en_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7588. BMI160_USER_INTR2_INPUT_ENABLE);
  7589. break;
  7590. default:
  7591. com_rslt = E_BMI160_OUT_OF_RANGE;
  7592. break;
  7593. }
  7594. }
  7595. return com_rslt;
  7596. }
  7597. /*!
  7598. * @brief API is used to set input enable for interrupt1
  7599. * and interrupt2 pin from the register 0x54
  7600. * @brief interrupt1 - bit 4
  7601. * @brief interrupt2 - bit 5
  7602. *
  7603. * @param v_channel_u8: The value of input enable selection
  7604. * v_channel_u8 | input selection
  7605. * ---------------|---------------
  7606. * 0 | BMI160_INTR1_INPUT_ENABLE
  7607. * 1 | BMI160_INTR2_INPUT_ENABLE
  7608. *
  7609. * @param v_input_en_u8 :
  7610. * The value of input enable of interrupt enable
  7611. * value | Behaviour
  7612. * ----------|-------------------
  7613. * 0x01 | BMI160_INPUT_ENABLED
  7614. * 0x00 | BMI160_INPUT_DISABLED
  7615. *
  7616. *
  7617. *
  7618. * @return results of bus communication function
  7619. * @retval 0 -> Success
  7620. * @retval -1 -> Error
  7621. *
  7622. *
  7623. */
  7624. BMI160_RETURN_FUNCTION_TYPE bmi160_set_input_enable(
  7625. u8 v_channel_u8, u8 v_input_en_u8)
  7626. {
  7627. /* variable used to return the status of communication result*/
  7628. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7629. u8 v_data_u8 = BMI160_INIT_VALUE;
  7630. /* check the p_bmi160 structure for NULL pointer assignment*/
  7631. if (p_bmi160 == BMI160_NULL) {
  7632. return E_BMI160_NULL_PTR;
  7633. } else {
  7634. switch (v_channel_u8) {
  7635. /* write input enable of interrup1 and interrupt2*/
  7636. case BMI160_INTR1_INPUT_ENABLE:
  7637. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7638. dev_addr, BMI160_USER_INTR1_INPUT_ENABLE__REG,
  7639. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7640. if (com_rslt == SUCCESS) {
  7641. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7642. BMI160_USER_INTR1_INPUT_ENABLE, v_input_en_u8);
  7643. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7644. dev_addr, BMI160_USER_INTR1_INPUT_ENABLE__REG,
  7645. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7646. }
  7647. break;
  7648. case BMI160_INTR2_INPUT_ENABLE:
  7649. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7650. dev_addr, BMI160_USER_INTR2_INPUT_ENABLE__REG,
  7651. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7652. if (com_rslt == SUCCESS) {
  7653. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7654. BMI160_USER_INTR2_INPUT_ENABLE, v_input_en_u8);
  7655. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7656. dev_addr, BMI160_USER_INTR2_INPUT_ENABLE__REG,
  7657. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7658. }
  7659. break;
  7660. default:
  7661. com_rslt = E_BMI160_OUT_OF_RANGE;
  7662. break;
  7663. }
  7664. /*Accel and Gyro power mode check */
  7665. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  7666. /*interface idle time delay */
  7667. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  7668. }
  7669. return com_rslt;
  7670. }
  7671. /*!
  7672. * @brief This API reads the Low g interrupt which is mapped to interrupt1
  7673. * and interrupt2 from the register 0x55 and 0x57
  7674. * @brief interrupt1 bit 0 in the register 0x55
  7675. * @brief interrupt2 bit 0 in the register 0x57
  7676. *
  7677. *
  7678. * @param v_channel_u8: The value of low_g selection
  7679. * v_channel_u8 | interrupt
  7680. * ---------------|---------------
  7681. * 0 | BMI160_INTR1_MAP_LOW_G
  7682. * 1 | BMI160_INTR2_MAP_LOW_G
  7683. *
  7684. * @param v_intr_low_g_u8 : The value of low_g enable
  7685. * value | interrupt enable
  7686. * ----------|-------------------
  7687. * 0x01 | BMI160_ENABLE
  7688. * 0x00 | BMI160_DISABLE
  7689. *
  7690. *
  7691. *
  7692. * @return results of bus communication function
  7693. * @retval 0 -> Success
  7694. * @retval -1 -> Error
  7695. *
  7696. *
  7697. */
  7698. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_low_g(
  7699. u8 v_channel_u8, u8 *v_intr_low_g_u8)
  7700. {
  7701. /* variable used to return the status of communication result*/
  7702. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7703. u8 v_data_u8 = BMI160_INIT_VALUE;
  7704. /* check the p_bmi160 structure for NULL pointer assignment*/
  7705. if (p_bmi160 == BMI160_NULL) {
  7706. return E_BMI160_NULL_PTR;
  7707. } else {
  7708. switch (v_channel_u8) {
  7709. /* read the low_g interrupt */
  7710. case BMI160_INTR1_MAP_LOW_G:
  7711. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7712. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_LOW_G__REG,
  7713. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7714. *v_intr_low_g_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7715. BMI160_USER_INTR_MAP_0_INTR1_LOW_G);
  7716. break;
  7717. case BMI160_INTR2_MAP_LOW_G:
  7718. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7719. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_LOW_G__REG,
  7720. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7721. *v_intr_low_g_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7722. BMI160_USER_INTR_MAP_2_INTR2_LOW_G);
  7723. break;
  7724. default:
  7725. com_rslt = E_BMI160_OUT_OF_RANGE;
  7726. break;
  7727. }
  7728. }
  7729. return com_rslt;
  7730. }
  7731. /*!
  7732. * @brief This API sets the Low g interrupt to be mapped to interrupt1
  7733. * and interrupt2 from the register 0x55 and 0x57
  7734. * @brief interrupt1 bit 0 in the register 0x55
  7735. * @brief interrupt2 bit 0 in the register 0x57
  7736. *
  7737. *
  7738. * @param v_channel_u8: The value of low_g selection
  7739. * v_channel_u8 | interrupt
  7740. * ---------------|---------------
  7741. * 0 | BMI160_INTR1_MAP_LOW_G
  7742. * 1 | BMI160_INTR2_MAP_LOW_G
  7743. *
  7744. * @param v_intr_low_g_u8 : The value of low_g enable
  7745. * value | interrupt enable
  7746. * ----------|-------------------
  7747. * 0x01 | BMI160_ENABLE
  7748. * 0x00 | BMI160_DISABLE
  7749. *
  7750. *
  7751. *
  7752. * @return results of bus communication function
  7753. * @retval 0 -> Success
  7754. * @retval -1 -> Error
  7755. *
  7756. *
  7757. */
  7758. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_low_g(
  7759. u8 v_channel_u8, u8 v_intr_low_g_u8)
  7760. {
  7761. /* variable used to return the status of communication result*/
  7762. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7763. u8 v_data_u8 = BMI160_INIT_VALUE;
  7764. u8 v_step_cnt_stat_u8 = BMI160_INIT_VALUE;
  7765. u8 v_step_det_stat_u8 = BMI160_INIT_VALUE;
  7766. /* check the p_bmi160 structure for NULL pointer assignment*/
  7767. if (p_bmi160 == BMI160_NULL) {
  7768. return E_BMI160_NULL_PTR;
  7769. } else {
  7770. /* check the step detector interrupt enable status*/
  7771. com_rslt = bmi160_get_step_detector_enable(&v_step_det_stat_u8);
  7772. /* disable the step detector interrupt */
  7773. if (v_step_det_stat_u8 != BMI160_INIT_VALUE)
  7774. com_rslt += bmi160_set_step_detector_enable(BMI160_INIT_VALUE);
  7775. /* check the step counter interrupt enable status*/
  7776. com_rslt += bmi160_get_step_counter_enable(&v_step_cnt_stat_u8);
  7777. /* disable the step counter interrupt */
  7778. if (v_step_cnt_stat_u8 != BMI160_INIT_VALUE)
  7779. com_rslt += bmi160_set_step_counter_enable(
  7780. BMI160_INIT_VALUE);
  7781. switch (v_channel_u8) {
  7782. /* write the low_g interrupt*/
  7783. case BMI160_INTR1_MAP_LOW_G:
  7784. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7785. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_LOW_G__REG,
  7786. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7787. if (com_rslt == SUCCESS) {
  7788. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7789. BMI160_USER_INTR_MAP_0_INTR1_LOW_G, v_intr_low_g_u8);
  7790. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7791. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_LOW_G__REG,
  7792. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7793. }
  7794. break;
  7795. case BMI160_INTR2_MAP_LOW_G:
  7796. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7797. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_LOW_G__REG,
  7798. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7799. if (com_rslt == SUCCESS) {
  7800. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7801. BMI160_USER_INTR_MAP_2_INTR2_LOW_G, v_intr_low_g_u8);
  7802. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7803. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_LOW_G__REG,
  7804. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7805. }
  7806. break;
  7807. default:
  7808. com_rslt = E_BMI160_OUT_OF_RANGE;
  7809. break;
  7810. }
  7811. /*Accel and Gyro power mode check */
  7812. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  7813. /*interface idle time delay */
  7814. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  7815. }
  7816. return com_rslt;
  7817. }
  7818. /*!
  7819. * @brief This API reads the HIGH g interrupt which is mapped to interrupt1
  7820. * and interrupt2 from the register 0x55 and 0x57
  7821. * @brief interrupt1 bit 1 in the register 0x55
  7822. * @brief interrupt2 bit 1 in the register 0x57
  7823. *
  7824. *
  7825. * @param v_channel_u8: The value of high_g selection
  7826. * v_channel_u8 | interrupt
  7827. * ---------------|---------------
  7828. * 0 | BMI160_INTR1_MAP_HIGH_G
  7829. * 1 | BMI160_INTR2_MAP_HIGH_G
  7830. *
  7831. * @param v_intr_high_g_u8 : The value of high_g enable
  7832. * value | interrupt enable
  7833. * ----------|-------------------
  7834. * 0x01 | BMI160_ENABLE
  7835. * 0x00 | BMI160_DISABLE
  7836. *
  7837. *
  7838. *
  7839. *
  7840. * @return results of bus communication function
  7841. * @retval 0 -> Success
  7842. * @retval -1 -> Error
  7843. *
  7844. *
  7845. */
  7846. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_high_g(
  7847. u8 v_channel_u8, u8 *v_intr_high_g_u8)
  7848. {
  7849. /* variable used to return the status of communication result*/
  7850. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7851. u8 v_data_u8 = BMI160_INIT_VALUE;
  7852. /* check the p_bmi160 structure for NULL pointer assignment*/
  7853. if (p_bmi160 == BMI160_NULL) {
  7854. return E_BMI160_NULL_PTR;
  7855. } else {
  7856. /* read the high_g interrupt*/
  7857. switch (v_channel_u8) {
  7858. case BMI160_INTR1_MAP_HIGH_G:
  7859. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7860. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_HIGH_G__REG,
  7861. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7862. *v_intr_high_g_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7863. BMI160_USER_INTR_MAP_0_INTR1_HIGH_G);
  7864. break;
  7865. case BMI160_INTR2_MAP_HIGH_G:
  7866. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7867. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_HIGH_G__REG,
  7868. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7869. *v_intr_high_g_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7870. BMI160_USER_INTR_MAP_2_INTR2_HIGH_G);
  7871. break;
  7872. default:
  7873. com_rslt = E_BMI160_OUT_OF_RANGE;
  7874. break;
  7875. }
  7876. }
  7877. return com_rslt;
  7878. }
  7879. /*!
  7880. * @brief This API writes the HIGH g interrupt to be mapped to interrupt1
  7881. * and interrupt2 from the register 0x55 and 0x57
  7882. * @brief interrupt1 bit 1 in the register 0x55
  7883. * @brief interrupt2 bit 1 in the register 0x57
  7884. *
  7885. *
  7886. * @param v_channel_u8: The value of high_g selection
  7887. * v_channel_u8 | interrupt
  7888. * ---------------|---------------
  7889. * 0 | BMI160_INTR1_MAP_HIGH_G
  7890. * 1 | BMI160_INTR2_MAP_HIGH_G
  7891. *
  7892. * @param v_intr_high_g_u8 : The value of high_g enable
  7893. * value | interrupt enable
  7894. * ----------|-------------------
  7895. * 0x01 | BMI160_ENABLE
  7896. * 0x00 | BMI160_DISABLE
  7897. *
  7898. *
  7899. *
  7900. *
  7901. * @return results of bus communication function
  7902. * @retval 0 -> Success
  7903. * @retval -1 -> Error
  7904. *
  7905. *
  7906. */
  7907. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_high_g(
  7908. u8 v_channel_u8, u8 v_intr_high_g_u8)
  7909. {
  7910. /* variable used to return the status of communication result*/
  7911. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7912. u8 v_data_u8 = BMI160_INIT_VALUE;
  7913. /* check the p_bmi160 structure for NULL pointer assignment*/
  7914. if (p_bmi160 == BMI160_NULL) {
  7915. return E_BMI160_NULL_PTR;
  7916. } else {
  7917. switch (v_channel_u8) {
  7918. /* write the high_g interrupt*/
  7919. case BMI160_INTR1_MAP_HIGH_G:
  7920. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7921. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_HIGH_G__REG,
  7922. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7923. if (com_rslt == SUCCESS) {
  7924. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7925. BMI160_USER_INTR_MAP_0_INTR1_HIGH_G, v_intr_high_g_u8);
  7926. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7927. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_HIGH_G__REG,
  7928. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7929. }
  7930. break;
  7931. case BMI160_INTR2_MAP_HIGH_G:
  7932. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7933. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_HIGH_G__REG,
  7934. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7935. if (com_rslt == SUCCESS) {
  7936. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7937. BMI160_USER_INTR_MAP_2_INTR2_HIGH_G, v_intr_high_g_u8);
  7938. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7939. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_HIGH_G__REG,
  7940. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7941. }
  7942. break;
  7943. default:
  7944. com_rslt = E_BMI160_OUT_OF_RANGE;
  7945. break;
  7946. }
  7947. /*Accel and Gyro power mode check */
  7948. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  7949. /*interface idle time delay */
  7950. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  7951. }
  7952. return com_rslt;
  7953. }
  7954. /*!
  7955. * @brief This API reads the Any motion interrupt which is mapped to
  7956. * interrupt1 and interrupt2 from the register 0x55 and 0x57
  7957. * @brief interrupt1 bit 2 in the register 0x55
  7958. * @brief interrupt2 bit 2 in the register 0x57
  7959. *
  7960. *
  7961. * @param v_channel_u8: The value of any motion selection
  7962. * v_channel_u8 | interrupt
  7963. * ---------------|---------------
  7964. * 0 | BMI160_INTR1_MAP_ANY_MOTION
  7965. * 1 | BMI160_INTR2_MAP_ANY_MOTION
  7966. *
  7967. * @param v_intr_any_motion_u8 : The value of any motion enable
  7968. * value | interrupt enable
  7969. * ----------|-------------------
  7970. * 0x01 | BMI160_ENABLE
  7971. * 0x00 | BMI160_DISABLE
  7972. *
  7973. *
  7974. *
  7975. * @return results of bus communication function
  7976. * @retval 0 -> Success
  7977. * @retval -1 -> Error
  7978. *
  7979. *
  7980. */
  7981. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_any_motion(
  7982. u8 v_channel_u8, u8 *v_intr_any_motion_u8)
  7983. {
  7984. /* variable used to return the status of communication result*/
  7985. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7986. u8 v_data_u8 = BMI160_INIT_VALUE;
  7987. /* check the p_bmi160 structure for NULL pointer assignment*/
  7988. if (p_bmi160 == BMI160_NULL) {
  7989. return E_BMI160_NULL_PTR;
  7990. } else {
  7991. switch (v_channel_u8) {
  7992. /* read the any motion interrupt */
  7993. case BMI160_INTR1_MAP_ANY_MOTION:
  7994. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7995. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG,
  7996. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  7997. *v_intr_any_motion_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7998. BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION);
  7999. break;
  8000. case BMI160_INTR2_MAP_ANY_MOTION:
  8001. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8002. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG,
  8003. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8004. *v_intr_any_motion_u8 = BMI160_GET_BITSLICE(v_data_u8,
  8005. BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION);
  8006. break;
  8007. default:
  8008. com_rslt = E_BMI160_OUT_OF_RANGE;
  8009. break;
  8010. }
  8011. }
  8012. return com_rslt;
  8013. }
  8014. /*!
  8015. * @brief This API writes the Any motion interrupt
  8016. * to be mapped to interrupt1
  8017. * and interrupt2 from the register 0x55 and 0x57
  8018. * @brief interrupt1 bit 2 in the register 0x55
  8019. * @brief interrupt2 bit 2 in the register 0x57
  8020. *
  8021. *
  8022. * @param v_channel_u8: The value of any motion selection
  8023. * v_channel_u8 | interrupt
  8024. * ---------------|---------------
  8025. * 0 | BMI160_INTR1_MAP_ANY_MOTION
  8026. * 1 | BMI160_INTR2_MAP_ANY_MOTION
  8027. *
  8028. * @param v_intr_any_motion_u8 : The value of any motion enable
  8029. * value | interrupt enable
  8030. * ----------|-------------------
  8031. * 0x01 | BMI160_ENABLE
  8032. * 0x00 | BMI160_DISABLE
  8033. *
  8034. *
  8035. *
  8036. * @return results of bus communication function
  8037. * @retval 0 -> Success
  8038. * @retval -1 -> Error
  8039. *
  8040. *
  8041. */
  8042. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_any_motion(
  8043. u8 v_channel_u8, u8 v_intr_any_motion_u8)
  8044. {
  8045. /* variable used to return the status of communication result*/
  8046. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8047. u8 v_data_u8 = BMI160_INIT_VALUE;
  8048. u8 sig_mot_stat = BMI160_INIT_VALUE;
  8049. /* check the p_bmi160 structure for NULL pointer assignment*/
  8050. if (p_bmi160 == BMI160_NULL) {
  8051. return E_BMI160_NULL_PTR;
  8052. } else {
  8053. /* read the status of significant motion interrupt */
  8054. com_rslt = bmi160_get_intr_significant_motion_select(&sig_mot_stat);
  8055. /* disable the significant motion interrupt */
  8056. if (sig_mot_stat != BMI160_INIT_VALUE)
  8057. com_rslt += bmi160_set_intr_significant_motion_select(
  8058. BMI160_INIT_VALUE);
  8059. switch (v_channel_u8) {
  8060. /* write the any motion interrupt */
  8061. case BMI160_INTR1_MAP_ANY_MOTION:
  8062. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8063. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG,
  8064. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8065. if (com_rslt == SUCCESS) {
  8066. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  8067. BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION,
  8068. v_intr_any_motion_u8);
  8069. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8070. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG,
  8071. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8072. }
  8073. break;
  8074. case BMI160_INTR2_MAP_ANY_MOTION:
  8075. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8076. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG,
  8077. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8078. if (com_rslt == SUCCESS) {
  8079. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  8080. BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION,
  8081. v_intr_any_motion_u8);
  8082. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8083. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG,
  8084. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8085. }
  8086. break;
  8087. default:
  8088. com_rslt = E_BMI160_OUT_OF_RANGE;
  8089. break;
  8090. }
  8091. /*Accel and Gyro power mode check */
  8092. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  8093. /*interface idle time delay */
  8094. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  8095. }
  8096. return com_rslt;
  8097. }
  8098. /*!
  8099. * @brief This API reads the No motion interrupt
  8100. * which is mapped to interrupt1
  8101. * and interrupt2 from the register 0x55 and 0x57
  8102. * @brief interrupt1 bit 3 in the register 0x55
  8103. * @brief interrupt2 bit 3 in the register 0x57
  8104. *
  8105. *
  8106. * @param v_channel_u8: The value of no motion selection
  8107. * v_channel_u8 | interrupt
  8108. * ---------------|---------------
  8109. * 0 | BMI160_INTR1_MAP_NOMO
  8110. * 1 | BMI160_INTR2_MAP_NOMO
  8111. *
  8112. * @param v_intr_nomotion_u8 : The value of no motion enable
  8113. * value | interrupt enable
  8114. * ----------|-------------------
  8115. * 0x01 | BMI160_ENABLE
  8116. * 0x00 | BMI160_DISABLE
  8117. *
  8118. *
  8119. * @return results of bus communication function
  8120. * @retval 0 -> Success
  8121. * @retval -1 -> Error
  8122. *
  8123. *
  8124. */
  8125. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_nomotion(
  8126. u8 v_channel_u8, u8 *v_intr_nomotion_u8)
  8127. {
  8128. /* variable used to return the status of communication result*/
  8129. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8130. u8 v_data_u8 = BMI160_INIT_VALUE;
  8131. /* check the p_bmi160 structure for NULL pointer assignment*/
  8132. if (p_bmi160 == BMI160_NULL) {
  8133. return E_BMI160_NULL_PTR;
  8134. } else {
  8135. switch (v_channel_u8) {
  8136. /* read the no motion interrupt*/
  8137. case BMI160_INTR1_MAP_NOMO:
  8138. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8139. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_NOMOTION__REG,
  8140. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8141. *v_intr_nomotion_u8 = BMI160_GET_BITSLICE(v_data_u8,
  8142. BMI160_USER_INTR_MAP_0_INTR1_NOMOTION);
  8143. break;
  8144. case BMI160_INTR2_MAP_NOMO:
  8145. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8146. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_NOMOTION__REG,
  8147. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8148. *v_intr_nomotion_u8 = BMI160_GET_BITSLICE(v_data_u8,
  8149. BMI160_USER_INTR_MAP_2_INTR2_NOMOTION);
  8150. break;
  8151. default:
  8152. com_rslt = E_BMI160_OUT_OF_RANGE;
  8153. break;
  8154. }
  8155. }
  8156. return com_rslt;
  8157. }
  8158. /*!
  8159. * @brief This API configures the No motion interrupt
  8160. * to be mapped to interrupt1
  8161. * and interrupt2 from the register 0x55 and 0x57
  8162. * @brief interrupt1 bit 3 in the register 0x55
  8163. * @brief interrupt2 bit 3 in the register 0x57
  8164. *
  8165. *
  8166. * @param v_channel_u8: The value of no motion selection
  8167. * v_channel_u8 | interrupt
  8168. * ---------------|---------------
  8169. * 0 | BMI160_INTR1_MAP_NOMO
  8170. * 1 | BMI160_INTR2_MAP_NOMO
  8171. *
  8172. * @param v_intr_nomotion_u8 : The value of no motion enable
  8173. * value | interrupt enable
  8174. * ----------|-------------------
  8175. * 0x01 | BMI160_ENABLE
  8176. * 0x00 | BMI160_DISABLE
  8177. *
  8178. *
  8179. * @return results of bus communication function
  8180. * @retval 0 -> Success
  8181. * @retval -1 -> Error
  8182. *
  8183. *
  8184. */
  8185. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_nomotion(
  8186. u8 v_channel_u8, u8 v_intr_nomotion_u8)
  8187. {
  8188. /* variable used to return the status of communication result*/
  8189. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8190. u8 v_data_u8 = BMI160_INIT_VALUE;
  8191. /* check the p_bmi160 structure for NULL pointer assignment*/
  8192. if (p_bmi160 == BMI160_NULL) {
  8193. return E_BMI160_NULL_PTR;
  8194. } else {
  8195. switch (v_channel_u8) {
  8196. /* write the no motion interrupt*/
  8197. case BMI160_INTR1_MAP_NOMO:
  8198. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8199. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_NOMOTION__REG,
  8200. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8201. if (com_rslt == SUCCESS) {
  8202. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  8203. BMI160_USER_INTR_MAP_0_INTR1_NOMOTION,
  8204. v_intr_nomotion_u8);
  8205. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8206. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_NOMOTION__REG,
  8207. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8208. }
  8209. break;
  8210. case BMI160_INTR2_MAP_NOMO:
  8211. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8212. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_NOMOTION__REG,
  8213. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8214. if (com_rslt == SUCCESS) {
  8215. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  8216. BMI160_USER_INTR_MAP_2_INTR2_NOMOTION,
  8217. v_intr_nomotion_u8);
  8218. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8219. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_NOMOTION__REG,
  8220. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8221. }
  8222. break;
  8223. default:
  8224. com_rslt = E_BMI160_OUT_OF_RANGE;
  8225. break;
  8226. }
  8227. /*Accel and Gyro power mode check */
  8228. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  8229. /*interface idle time delay */
  8230. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  8231. }
  8232. return com_rslt;
  8233. }
  8234. /*!
  8235. * @brief This API reads the Double Tap interrupt
  8236. * which is mapped to interrupt1
  8237. * and interrupt2 from the register 0x55 and 0x57
  8238. * @brief interrupt1 bit 4 in the register 0x55
  8239. * @brief interrupt2 bit 4 in the register 0x57
  8240. *
  8241. *
  8242. * @param v_channel_u8: The value of double tap interrupt selection
  8243. * v_channel_u8 | interrupt
  8244. * ---------------|---------------
  8245. * 0 | BMI160_INTR1_MAP_DOUBLE_TAP
  8246. * 1 | BMI160_INTR2_MAP_DOUBLE_TAP
  8247. *
  8248. * @param v_intr_double_tap_u8 : The value of double tap enable
  8249. * value | interrupt enable
  8250. * ----------|-------------------
  8251. * 0x01 | BMI160_ENABLE
  8252. * 0x00 | BMI160_DISABLE
  8253. *
  8254. * @return results of bus communication function
  8255. * @retval 0 -> Success
  8256. * @retval -1 -> Error
  8257. *
  8258. *
  8259. */
  8260. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_double_tap(
  8261. u8 v_channel_u8, u8 *v_intr_double_tap_u8)
  8262. {
  8263. /* variable used to return the status of communication result*/
  8264. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8265. u8 v_data_u8 = BMI160_INIT_VALUE;
  8266. /* check the p_bmi160 structure for NULL pointer assignment*/
  8267. if (p_bmi160 == BMI160_NULL) {
  8268. return E_BMI160_NULL_PTR;
  8269. } else {
  8270. switch (v_channel_u8) {
  8271. case BMI160_INTR1_MAP_DOUBLE_TAP:
  8272. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8273. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_DOUBLE_TAP__REG,
  8274. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8275. *v_intr_double_tap_u8 = BMI160_GET_BITSLICE(v_data_u8,
  8276. BMI160_USER_INTR_MAP_0_INTR1_DOUBLE_TAP);
  8277. break;
  8278. case BMI160_INTR2_MAP_DOUBLE_TAP:
  8279. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8280. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_DOUBLE_TAP__REG,
  8281. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8282. *v_intr_double_tap_u8 = BMI160_GET_BITSLICE(v_data_u8,
  8283. BMI160_USER_INTR_MAP_2_INTR2_DOUBLE_TAP);
  8284. break;
  8285. default:
  8286. com_rslt = E_BMI160_OUT_OF_RANGE;
  8287. break;
  8288. }
  8289. }
  8290. return com_rslt;
  8291. }
  8292. /*!
  8293. * @brief This API configures the Double Tap interrupt
  8294. * to be mapped to interrupt1
  8295. * and interrupt2 from the register 0x55 and 0x57
  8296. * @brief interrupt1 bit 4 in the register 0x55
  8297. * @brief interrupt2 bit 4 in the register 0x57
  8298. *
  8299. *
  8300. * @param v_channel_u8: The value of double tap interrupt selection
  8301. * v_channel_u8 | interrupt
  8302. * ---------------|---------------
  8303. * 0 | BMI160_INTR1_MAP_DOUBLE_TAP
  8304. * 1 | BMI160_INTR2_MAP_DOUBLE_TAP
  8305. *
  8306. * @param v_intr_double_tap_u8 : The value of double tap enable
  8307. * value | interrupt enable
  8308. * ----------|-------------------
  8309. * 0x01 | BMI160_ENABLE
  8310. * 0x00 | BMI160_DISABLE
  8311. *
  8312. * @return results of bus communication function
  8313. * @retval 0 -> Success
  8314. * @retval -1 -> Error
  8315. *
  8316. *
  8317. */
  8318. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_double_tap(
  8319. u8 v_channel_u8, u8 v_intr_double_tap_u8)
  8320. {
  8321. /* variable used to return the status of communication result*/
  8322. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8323. u8 v_data_u8 = BMI160_INIT_VALUE;
  8324. /* check the p_bmi160 structure for NULL pointer assignment*/
  8325. if (p_bmi160 == BMI160_NULL) {
  8326. return E_BMI160_NULL_PTR;
  8327. } else {
  8328. switch (v_channel_u8) {
  8329. /* set the double tap interrupt */
  8330. case BMI160_INTR1_MAP_DOUBLE_TAP:
  8331. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8332. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_DOUBLE_TAP__REG,
  8333. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8334. if (com_rslt == SUCCESS) {
  8335. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  8336. BMI160_USER_INTR_MAP_0_INTR1_DOUBLE_TAP,
  8337. v_intr_double_tap_u8);
  8338. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8339. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_DOUBLE_TAP__REG,
  8340. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8341. }
  8342. break;
  8343. case BMI160_INTR2_MAP_DOUBLE_TAP:
  8344. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8345. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_DOUBLE_TAP__REG,
  8346. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8347. if (com_rslt == SUCCESS) {
  8348. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  8349. BMI160_USER_INTR_MAP_2_INTR2_DOUBLE_TAP,
  8350. v_intr_double_tap_u8);
  8351. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8352. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_DOUBLE_TAP__REG,
  8353. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8354. }
  8355. break;
  8356. default:
  8357. com_rslt = E_BMI160_OUT_OF_RANGE;
  8358. break;
  8359. }
  8360. /*Accel and Gyro power mode check */
  8361. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  8362. /*interface idle time delay */
  8363. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  8364. }
  8365. return com_rslt;
  8366. }
  8367. /*!
  8368. * @brief This API reads the Single Tap interrupt
  8369. * which is mapped to interrupt1
  8370. * and interrupt2 from the register 0x55 and 0x57
  8371. * @brief interrupt1 bit 5 in the register 0x55
  8372. * @brief interrupt2 bit 5 in the register 0x57
  8373. *
  8374. *
  8375. * @param v_channel_u8: The value of single tap interrupt selection
  8376. * v_channel_u8 | interrupt
  8377. * ---------------|---------------
  8378. * 0 | BMI160_INTR1_MAP_SINGLE_TAP
  8379. * 1 | BMI160_INTR2_MAP_SINGLE_TAP
  8380. *
  8381. * @param v_intr_single_tap_u8 : The value of single tap enable
  8382. * value | interrupt enable
  8383. * ----------|-------------------
  8384. * 0x01 | BMI160_ENABLE
  8385. * 0x00 | BMI160_DISABLE
  8386. *
  8387. *
  8388. * @return results of bus communication function
  8389. * @retval 0 -> Success
  8390. * @retval -1 -> Error
  8391. *
  8392. *
  8393. */
  8394. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_single_tap(
  8395. u8 v_channel_u8, u8 *v_intr_single_tap_u8)
  8396. {
  8397. /* variable used to return the status of communication result*/
  8398. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8399. u8 v_data_u8 = BMI160_INIT_VALUE;
  8400. /* check the p_bmi160 structure for NULL pointer assignment*/
  8401. if (p_bmi160 == BMI160_NULL) {
  8402. return E_BMI160_NULL_PTR;
  8403. } else {
  8404. switch (v_channel_u8) {
  8405. /* reads the single tap interrupt*/
  8406. case BMI160_INTR1_MAP_SINGLE_TAP:
  8407. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8408. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_SINGLE_TAP__REG,
  8409. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8410. *v_intr_single_tap_u8 = BMI160_GET_BITSLICE(v_data_u8,
  8411. BMI160_USER_INTR_MAP_0_INTR1_SINGLE_TAP);
  8412. break;
  8413. case BMI160_INTR2_MAP_SINGLE_TAP:
  8414. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8415. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_SINGLE_TAP__REG,
  8416. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8417. *v_intr_single_tap_u8 = BMI160_GET_BITSLICE(v_data_u8,
  8418. BMI160_USER_INTR_MAP_2_INTR2_SINGLE_TAP);
  8419. break;
  8420. default:
  8421. com_rslt = E_BMI160_OUT_OF_RANGE;
  8422. break;
  8423. }
  8424. }
  8425. return com_rslt;
  8426. }
  8427. /*!
  8428. * @brief This API configures the Single Tap interrupt
  8429. * to be mapped to interrupt1
  8430. * and interrupt2 from the register 0x55 and 0x57
  8431. * @brief interrupt1 bit 5 in the register 0x55
  8432. * @brief interrupt2 bit 5 in the register 0x57
  8433. *
  8434. *
  8435. * @param v_channel_u8: The value of single tap interrupt selection
  8436. * v_channel_u8 | interrupt
  8437. * ---------------|---------------
  8438. * 0 | BMI160_INTR1_MAP_SINGLE_TAP
  8439. * 1 | BMI160_INTR2_MAP_SINGLE_TAP
  8440. *
  8441. * @param v_intr_single_tap_u8 : The value of single tap enable
  8442. * value | interrupt enable
  8443. * ----------|-------------------
  8444. * 0x01 | BMI160_ENABLE
  8445. * 0x00 | BMI160_DISABLE
  8446. *
  8447. *
  8448. * @return results of bus communication function
  8449. * @retval 0 -> Success
  8450. * @retval -1 -> Error
  8451. *
  8452. *
  8453. */
  8454. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_single_tap(
  8455. u8 v_channel_u8, u8 v_intr_single_tap_u8)
  8456. {
  8457. /* variable used to return the status of communication result*/
  8458. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8459. u8 v_data_u8 = BMI160_INIT_VALUE;
  8460. /* check the p_bmi160 structure for NULL pointer assignment*/
  8461. if (p_bmi160 == BMI160_NULL) {
  8462. return E_BMI160_NULL_PTR;
  8463. } else {
  8464. switch (v_channel_u8) {
  8465. /* write the single tap interrupt */
  8466. case BMI160_INTR1_MAP_SINGLE_TAP:
  8467. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8468. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_SINGLE_TAP__REG,
  8469. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8470. if (com_rslt == SUCCESS) {
  8471. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  8472. BMI160_USER_INTR_MAP_0_INTR1_SINGLE_TAP,
  8473. v_intr_single_tap_u8);
  8474. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8475. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_SINGLE_TAP__REG,
  8476. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8477. }
  8478. break;
  8479. case BMI160_INTR2_MAP_SINGLE_TAP:
  8480. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8481. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_SINGLE_TAP__REG,
  8482. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8483. if (com_rslt == SUCCESS) {
  8484. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  8485. BMI160_USER_INTR_MAP_2_INTR2_SINGLE_TAP,
  8486. v_intr_single_tap_u8);
  8487. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8488. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_SINGLE_TAP__REG,
  8489. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8490. }
  8491. break;
  8492. default:
  8493. com_rslt = E_BMI160_OUT_OF_RANGE;
  8494. break;
  8495. }
  8496. /*Accel and Gyro power mode check */
  8497. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  8498. /*interface idle time delay */
  8499. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  8500. }
  8501. return com_rslt;
  8502. }
  8503. /*!
  8504. * @brief This API reads the Orient interrupt which is mapped to interrupt1
  8505. * and interrupt2 from the register 0x55 and 0x57
  8506. * @brief interrupt1 bit 6 in the register 0x55
  8507. * @brief interrupt2 bit 6 in the register 0x57
  8508. *
  8509. *
  8510. * @param v_channel_u8: The value of orient interrupt selection
  8511. * v_channel_u8 | interrupt
  8512. * ---------------|---------------
  8513. * 0 | BMI160_INTR1_MAP_ORIENT
  8514. * 1 | BMI160_INTR2_MAP_ORIENT
  8515. *
  8516. * @param v_intr_orient_u8 : The value of orient enable
  8517. * value | interrupt enable
  8518. * ----------|-------------------
  8519. * 0x01 | BMI160_ENABLE
  8520. * 0x00 | BMI160_DISABLE
  8521. *
  8522. *
  8523. *
  8524. * @return results of bus communication function
  8525. * @retval 0 -> Success
  8526. * @retval -1 -> Error
  8527. *
  8528. *
  8529. */
  8530. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_orient(
  8531. u8 v_channel_u8, u8 *v_intr_orient_u8)
  8532. {
  8533. /* variable used to return the status of communication result*/
  8534. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8535. u8 v_data_u8 = BMI160_INIT_VALUE;
  8536. /* check the p_bmi160 structure for NULL pointer assignment*/
  8537. if (p_bmi160 == BMI160_NULL) {
  8538. return E_BMI160_NULL_PTR;
  8539. } else {
  8540. switch (v_channel_u8) {
  8541. /* read the orientation interrupt*/
  8542. case BMI160_INTR1_MAP_ORIENT:
  8543. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8544. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_ORIENT__REG,
  8545. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8546. *v_intr_orient_u8 = BMI160_GET_BITSLICE(v_data_u8,
  8547. BMI160_USER_INTR_MAP_0_INTR1_ORIENT);
  8548. break;
  8549. case BMI160_INTR2_MAP_ORIENT:
  8550. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8551. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_ORIENT__REG,
  8552. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8553. *v_intr_orient_u8 = BMI160_GET_BITSLICE(v_data_u8,
  8554. BMI160_USER_INTR_MAP_2_INTR2_ORIENT);
  8555. break;
  8556. default:
  8557. com_rslt = E_BMI160_OUT_OF_RANGE;
  8558. break;
  8559. }
  8560. }
  8561. return com_rslt;
  8562. }
  8563. /*!
  8564. * @brief This API configures the Orient interrupt
  8565. * to be mapped to interrupt1
  8566. * and interrupt2 from the register 0x55 and 0x57
  8567. * @brief interrupt1 bit 6 in the register 0x55
  8568. * @brief interrupt2 bit 6 in the register 0x57
  8569. *
  8570. *
  8571. * @param v_channel_u8: The value of orient interrupt selection
  8572. * v_channel_u8 | interrupt
  8573. * ---------------|---------------
  8574. * 0 | BMI160_INTR1_MAP_ORIENT
  8575. * 1 | BMI160_INTR2_MAP_ORIENT
  8576. *
  8577. * @param v_intr_orient_u8 : The value of orient enable
  8578. * value | interrupt enable
  8579. * ----------|-------------------
  8580. * 0x01 | BMI160_ENABLE
  8581. * 0x00 | BMI160_DISABLE
  8582. *
  8583. *
  8584. *
  8585. * @return results of bus communication function
  8586. * @retval 0 -> Success
  8587. * @retval -1 -> Error
  8588. *
  8589. *
  8590. */
  8591. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_orient(
  8592. u8 v_channel_u8, u8 v_intr_orient_u8)
  8593. {
  8594. /* variable used to return the status of communication result*/
  8595. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8596. u8 v_data_u8 = BMI160_INIT_VALUE;
  8597. /* check the p_bmi160 structure for NULL pointer assignment*/
  8598. if (p_bmi160 == BMI160_NULL) {
  8599. return E_BMI160_NULL_PTR;
  8600. } else {
  8601. switch (v_channel_u8) {
  8602. /* write the orientation interrupt*/
  8603. case BMI160_INTR1_MAP_ORIENT:
  8604. com_rslt =
  8605. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8606. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_ORIENT__REG,
  8607. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8608. if (com_rslt == SUCCESS) {
  8609. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  8610. BMI160_USER_INTR_MAP_0_INTR1_ORIENT, v_intr_orient_u8);
  8611. com_rslt +=
  8612. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8613. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_ORIENT__REG,
  8614. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8615. }
  8616. break;
  8617. case BMI160_INTR2_MAP_ORIENT:
  8618. com_rslt =
  8619. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8620. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_ORIENT__REG,
  8621. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8622. if (com_rslt == SUCCESS) {
  8623. v_data_u8 =
  8624. BMI160_SET_BITSLICE(v_data_u8,
  8625. BMI160_USER_INTR_MAP_2_INTR2_ORIENT, v_intr_orient_u8);
  8626. com_rslt +=
  8627. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8628. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_ORIENT__REG,
  8629. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8630. }
  8631. break;
  8632. default:
  8633. com_rslt = E_BMI160_OUT_OF_RANGE;
  8634. break;
  8635. }
  8636. /*Accel and Gyro power mode check */
  8637. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  8638. /*interface idle time delay */
  8639. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  8640. }
  8641. return com_rslt;
  8642. }
  8643. /*!
  8644. * @brief This API reads the Flat interrupt which is
  8645. * mapped to interrupt1
  8646. * and interrupt2 from the register 0x55 and 0x57
  8647. * @brief interrupt1 bit 7 in the register 0x55
  8648. * @brief interrupt2 bit 7 in the register 0x57
  8649. *
  8650. *
  8651. * @param v_channel_u8: The value of flat interrupt selection
  8652. * v_channel_u8 | interrupt
  8653. * ---------------|---------------
  8654. * 0 | BMI160_INTR1_MAP_FLAT
  8655. * 1 | BMI160_INTR2_MAP_FLAT
  8656. *
  8657. * @param v_intr_flat_u8 : The value of flat enable
  8658. * value | interrupt enable
  8659. * ----------|-------------------
  8660. * 0x01 | BMI160_ENABLE
  8661. * 0x00 | BMI160_DISABLE
  8662. *
  8663. *
  8664. * @return results of bus communication function
  8665. * @retval 0 -> Success
  8666. * @retval -1 -> Error
  8667. *
  8668. *
  8669. */
  8670. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_flat(
  8671. u8 v_channel_u8, u8 *v_intr_flat_u8)
  8672. {
  8673. /* variable used to return the status of communication result*/
  8674. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8675. u8 v_data_u8 = BMI160_INIT_VALUE;
  8676. /* check the p_bmi160 structure for NULL pointer assignment*/
  8677. if (p_bmi160 == BMI160_NULL) {
  8678. return E_BMI160_NULL_PTR;
  8679. } else {
  8680. switch (v_channel_u8) {
  8681. /* read the flat interrupt*/
  8682. case BMI160_INTR1_MAP_FLAT:
  8683. com_rslt =
  8684. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8685. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_FLAT__REG,
  8686. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8687. *v_intr_flat_u8 =
  8688. BMI160_GET_BITSLICE(v_data_u8,
  8689. BMI160_USER_INTR_MAP_0_INTR1_FLAT);
  8690. break;
  8691. case BMI160_INTR2_MAP_FLAT:
  8692. com_rslt =
  8693. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8694. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_FLAT__REG,
  8695. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8696. *v_intr_flat_u8 =
  8697. BMI160_GET_BITSLICE(v_data_u8,
  8698. BMI160_USER_INTR_MAP_2_INTR2_FLAT);
  8699. break;
  8700. default:
  8701. com_rslt = E_BMI160_OUT_OF_RANGE;
  8702. break;
  8703. }
  8704. }
  8705. return com_rslt;
  8706. }
  8707. /*!
  8708. * @brief This API configures the Flat interrupt to be
  8709. * mapped to interrupt1
  8710. * and interrupt2 from the register 0x55 and 0x57
  8711. * @brief interrupt1 bit 7 in the register 0x55
  8712. * @brief interrupt2 bit 7 in the register 0x57
  8713. *
  8714. *
  8715. * @param v_channel_u8: The value of flat interrupt selection
  8716. * v_channel_u8 | interrupt
  8717. * ---------------|---------------
  8718. * 0 | BMI160_INTR1_MAP_FLAT
  8719. * 1 | BMI160_INTR2_MAP_FLAT
  8720. *
  8721. * @param v_intr_flat_u8 : The value of flat enable
  8722. * value | interrupt enable
  8723. * ----------|-------------------
  8724. * 0x01 | BMI160_ENABLE
  8725. * 0x00 | BMI160_DISABLE
  8726. *
  8727. *
  8728. * @return results of bus communication function
  8729. * @retval 0 -> Success
  8730. * @retval -1 -> Error
  8731. *
  8732. *
  8733. */
  8734. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_flat(
  8735. u8 v_channel_u8, u8 v_intr_flat_u8)
  8736. {
  8737. /* variable used to return the status of communication result*/
  8738. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8739. u8 v_data_u8 = BMI160_INIT_VALUE;
  8740. /* check the p_bmi160 structure for NULL pointer assignment*/
  8741. if (p_bmi160 == BMI160_NULL) {
  8742. return E_BMI160_NULL_PTR;
  8743. } else {
  8744. switch (v_channel_u8) {
  8745. /* write the flat interrupt */
  8746. case BMI160_INTR1_MAP_FLAT:
  8747. com_rslt =
  8748. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8749. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_FLAT__REG,
  8750. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8751. if (com_rslt == SUCCESS) {
  8752. v_data_u8 =
  8753. BMI160_SET_BITSLICE(v_data_u8,
  8754. BMI160_USER_INTR_MAP_0_INTR1_FLAT,
  8755. v_intr_flat_u8);
  8756. com_rslt +=
  8757. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8758. dev_addr,
  8759. BMI160_USER_INTR_MAP_0_INTR1_FLAT__REG,
  8760. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8761. }
  8762. break;
  8763. case BMI160_INTR2_MAP_FLAT:
  8764. com_rslt =
  8765. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8766. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_FLAT__REG,
  8767. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8768. if (com_rslt == SUCCESS) {
  8769. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  8770. BMI160_USER_INTR_MAP_2_INTR2_FLAT,
  8771. v_intr_flat_u8);
  8772. com_rslt +=
  8773. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8774. dev_addr,
  8775. BMI160_USER_INTR_MAP_2_INTR2_FLAT__REG,
  8776. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8777. }
  8778. break;
  8779. default:
  8780. com_rslt = E_BMI160_OUT_OF_RANGE;
  8781. break;
  8782. }
  8783. /*Accel and Gyro power mode check*/
  8784. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  8785. /*interface idle time delay */
  8786. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  8787. }
  8788. return com_rslt;
  8789. }
  8790. /*!
  8791. * @brief This API reads the PMU trigger interrupt which is mapped to
  8792. * interrupt1 and interrupt2 from the register 0x56 bit 0 and 4
  8793. * @brief interrupt1 bit 0 in the register 0x56
  8794. * @brief interrupt2 bit 4 in the register 0x56
  8795. *
  8796. *
  8797. * @param v_channel_u8: The value of pmu trigger selection
  8798. * v_channel_u8 | interrupt
  8799. * ---------------|---------------
  8800. * 0 | BMI160_INTR1_MAP_PMUTRIG
  8801. * 1 | BMI160_INTR2_MAP_PMUTRIG
  8802. *
  8803. * @param v_intr_pmu_trig_u8 : The value of pmu trigger enable
  8804. * value | interrupt enable
  8805. * ----------|-------------------
  8806. * 0x01 | BMI160_ENABLE
  8807. * 0x00 | BMI160_DISABLE
  8808. *
  8809. *
  8810. * @return results of bus communication function
  8811. * @retval 0 -> Success
  8812. * @retval -1 -> Error
  8813. *
  8814. *
  8815. */
  8816. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_pmu_trig(
  8817. u8 v_channel_u8, u8 *v_intr_pmu_trig_u8)
  8818. {
  8819. /* variable used to return the status of communication result*/
  8820. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8821. u8 v_data_u8 = BMI160_INIT_VALUE;
  8822. /* check the p_bmi160 structure for NULL pointer assignment*/
  8823. if (p_bmi160 == BMI160_NULL) {
  8824. return E_BMI160_NULL_PTR;
  8825. } else {
  8826. switch (v_channel_u8) {
  8827. /* read the pmu trigger interrupt*/
  8828. case BMI160_INTR1_MAP_PMUTRIG:
  8829. com_rslt =
  8830. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8831. dev_addr, BMI160_USER_INTR_MAP_1_INTR1_PMU_TRIG__REG,
  8832. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8833. *v_intr_pmu_trig_u8 =
  8834. BMI160_GET_BITSLICE(v_data_u8,
  8835. BMI160_USER_INTR_MAP_1_INTR1_PMU_TRIG);
  8836. break;
  8837. case BMI160_INTR2_MAP_PMUTRIG:
  8838. com_rslt =
  8839. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8840. dev_addr, BMI160_USER_INTR_MAP_1_INTR2_PMU_TRIG__REG,
  8841. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8842. *v_intr_pmu_trig_u8 =
  8843. BMI160_GET_BITSLICE(v_data_u8,
  8844. BMI160_USER_INTR_MAP_1_INTR2_PMU_TRIG);
  8845. break;
  8846. default:
  8847. com_rslt = E_BMI160_OUT_OF_RANGE;
  8848. break;
  8849. }
  8850. }
  8851. return com_rslt;
  8852. }
  8853. /*!
  8854. * @brief This API configures the PMU trigger interrupt to be mapped to
  8855. * interrupt1 and interrupt2 from the register 0x56 bit 0 and 4
  8856. * @brief interrupt1 bit 0 in the register 0x56
  8857. * @brief interrupt2 bit 4 in the register 0x56
  8858. *
  8859. *
  8860. * @param v_channel_u8: The value of pmu trigger selection
  8861. * v_channel_u8 | interrupt
  8862. * ---------------|---------------
  8863. * 0 | BMI160_INTR1_MAP_PMUTRIG
  8864. * 1 | BMI160_INTR2_MAP_PMUTRIG
  8865. *
  8866. * @param v_intr_pmu_trig_u8 : The value of pmu trigger enable
  8867. * value | trigger enable
  8868. * ----------|-------------------
  8869. * 0x01 | BMI160_ENABLE
  8870. * 0x00 | BMI160_DISABLE
  8871. *
  8872. *
  8873. * @return results of bus communication function
  8874. * @retval 0 -> Success
  8875. * @retval -1 -> Error
  8876. *
  8877. *
  8878. */
  8879. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_pmu_trig(
  8880. u8 v_channel_u8, u8 v_intr_pmu_trig_u8)
  8881. {
  8882. /* variable used to return the status of communication result*/
  8883. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8884. u8 v_data_u8 = BMI160_INIT_VALUE;
  8885. /* check the p_bmi160 structure for NULL pointer assignment*/
  8886. if (p_bmi160 == BMI160_NULL) {
  8887. return E_BMI160_NULL_PTR;
  8888. } else {
  8889. switch (v_channel_u8) {
  8890. /* write the pmu trigger interrupt */
  8891. case BMI160_INTR1_MAP_PMUTRIG:
  8892. com_rslt =
  8893. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8894. dev_addr, BMI160_USER_INTR_MAP_1_INTR1_PMU_TRIG__REG,
  8895. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8896. if (com_rslt == SUCCESS) {
  8897. v_data_u8 =
  8898. BMI160_SET_BITSLICE(v_data_u8,
  8899. BMI160_USER_INTR_MAP_1_INTR1_PMU_TRIG,
  8900. v_intr_pmu_trig_u8);
  8901. com_rslt +=
  8902. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8903. dev_addr, BMI160_USER_INTR_MAP_1_INTR1_PMU_TRIG__REG,
  8904. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8905. }
  8906. break;
  8907. case BMI160_INTR2_MAP_PMUTRIG:
  8908. com_rslt =
  8909. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8910. dev_addr, BMI160_USER_INTR_MAP_1_INTR2_PMU_TRIG__REG,
  8911. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8912. if (com_rslt == SUCCESS) {
  8913. v_data_u8 =
  8914. BMI160_SET_BITSLICE(v_data_u8,
  8915. BMI160_USER_INTR_MAP_1_INTR2_PMU_TRIG,
  8916. v_intr_pmu_trig_u8);
  8917. com_rslt +=
  8918. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8919. dev_addr, BMI160_USER_INTR_MAP_1_INTR2_PMU_TRIG__REG,
  8920. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8921. }
  8922. break;
  8923. default:
  8924. com_rslt = E_BMI160_OUT_OF_RANGE;
  8925. break;
  8926. }
  8927. /*Accel and Gyro power mode check */
  8928. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  8929. /*interface idle time delay */
  8930. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  8931. }
  8932. return com_rslt;
  8933. }
  8934. #ifdef FIFO_ENABLE
  8935. /*!
  8936. * @brief This API reads the FIFO Full interrupt which is mapped to
  8937. * interrupt1 and interrupt2 from the register 0x56 bit 5 and 1
  8938. * @brief interrupt1 bit 5 in the register 0x56
  8939. * @brief interrupt2 bit 1 in the register 0x56
  8940. *
  8941. *
  8942. * @param v_channel_u8: The value of FIFO full interrupt selection
  8943. * v_channel_u8 | interrupt
  8944. * ---------------|---------------
  8945. * 0 | BMI160_INTR1_MAP_FIFO_FULL
  8946. * 1 | BMI160_INTR2_MAP_FIFO_FULL
  8947. *
  8948. * @param v_intr_fifo_full_u8 : The value of FIFO full interrupt enable
  8949. * value | interrupt enable
  8950. * ----------|-------------------
  8951. * 0x01 | BMI160_ENABLE
  8952. * 0x00 | BMI160_DISABLE
  8953. *
  8954. *
  8955. *
  8956. * @return results of bus communication function
  8957. * @retval 0 -> Success
  8958. * @retval -1 -> Error
  8959. *
  8960. *
  8961. */
  8962. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_fifo_full(
  8963. u8 v_channel_u8, u8 *v_intr_fifo_full_u8)
  8964. {
  8965. /* variable used to return the status of communication result*/
  8966. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8967. u8 v_data_u8 = BMI160_INIT_VALUE;
  8968. /* check the p_bmi160 structure for NULL pointer assignment*/
  8969. if (p_bmi160 == BMI160_NULL) {
  8970. return E_BMI160_NULL_PTR;
  8971. } else {
  8972. switch (v_channel_u8) {
  8973. /* read the FIFO full interrupt */
  8974. case BMI160_INTR1_MAP_FIFO_FULL:
  8975. com_rslt =
  8976. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8977. dev_addr, BMI160_USER_INTR_MAP_1_INTR1_FIFO_FULL__REG,
  8978. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8979. *v_intr_fifo_full_u8 =
  8980. BMI160_GET_BITSLICE(v_data_u8,
  8981. BMI160_USER_INTR_MAP_1_INTR1_FIFO_FULL);
  8982. break;
  8983. case BMI160_INTR2_MAP_FIFO_FULL:
  8984. com_rslt =
  8985. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8986. dev_addr, BMI160_USER_INTR_MAP_1_INTR2_FIFO_FULL__REG,
  8987. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  8988. *v_intr_fifo_full_u8 =
  8989. BMI160_GET_BITSLICE(v_data_u8,
  8990. BMI160_USER_INTR_MAP_1_INTR2_FIFO_FULL);
  8991. break;
  8992. default:
  8993. com_rslt = E_BMI160_OUT_OF_RANGE;
  8994. break;
  8995. }
  8996. }
  8997. return com_rslt;
  8998. }
  8999. /*!
  9000. * @brief This API configures the FIFO Full interrupt to be mapped to
  9001. * interrupt1 and interrupt2 from the register 0x56 bit 5 and 1
  9002. * @brief interrupt1 bit 5 in the register 0x56
  9003. * @brief interrupt2 bit 1 in the register 0x56
  9004. *
  9005. *
  9006. * @param v_channel_u8: The value of FIFO full interrupt selection
  9007. * v_channel_u8 | interrupt
  9008. * ---------------|---------------
  9009. * 0 | BMI160_INTR1_MAP_FIFO_FULL
  9010. * 1 | BMI160_INTR2_MAP_FIFO_FULL
  9011. *
  9012. * @param v_intr_fifo_full_u8 : The value of FIFO full interrupt enable
  9013. * value | interrupt enable
  9014. * ----------|-------------------
  9015. * 0x01 | BMI160_ENABLE
  9016. * 0x00 | BMI160_DISABLE
  9017. *
  9018. *
  9019. *
  9020. * @return results of bus communication function
  9021. * @retval 0 -> Success
  9022. * @retval -1 -> Error
  9023. *
  9024. *
  9025. */
  9026. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_fifo_full(
  9027. u8 v_channel_u8, u8 v_intr_fifo_full_u8)
  9028. {
  9029. /* variable used to return the status of communication result*/
  9030. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9031. u8 v_data_u8 = BMI160_INIT_VALUE;
  9032. /* check the p_bmi160 structure for NULL pointer assignment*/
  9033. if (p_bmi160 == BMI160_NULL) {
  9034. return E_BMI160_NULL_PTR;
  9035. } else {
  9036. switch (v_channel_u8) {
  9037. /* write the FIFO full interrupt */
  9038. case BMI160_INTR1_MAP_FIFO_FULL:
  9039. com_rslt =
  9040. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  9041. dev_addr, BMI160_USER_INTR_MAP_1_INTR1_FIFO_FULL__REG,
  9042. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9043. if (com_rslt == SUCCESS) {
  9044. v_data_u8 =
  9045. BMI160_SET_BITSLICE(v_data_u8,
  9046. BMI160_USER_INTR_MAP_1_INTR1_FIFO_FULL,
  9047. v_intr_fifo_full_u8);
  9048. com_rslt +=
  9049. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  9050. dev_addr,
  9051. BMI160_USER_INTR_MAP_1_INTR1_FIFO_FULL__REG,
  9052. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9053. }
  9054. break;
  9055. case BMI160_INTR2_MAP_FIFO_FULL:
  9056. com_rslt =
  9057. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  9058. dev_addr, BMI160_USER_INTR_MAP_1_INTR2_FIFO_FULL__REG,
  9059. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9060. if (com_rslt == SUCCESS) {
  9061. v_data_u8 =
  9062. BMI160_SET_BITSLICE(v_data_u8,
  9063. BMI160_USER_INTR_MAP_1_INTR2_FIFO_FULL,
  9064. v_intr_fifo_full_u8);
  9065. com_rslt +=
  9066. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  9067. dev_addr,
  9068. BMI160_USER_INTR_MAP_1_INTR2_FIFO_FULL__REG,
  9069. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9070. }
  9071. break;
  9072. default:
  9073. com_rslt = E_BMI160_OUT_OF_RANGE;
  9074. break;
  9075. }
  9076. }
  9077. return com_rslt;
  9078. }
  9079. /*!
  9080. * @brief This API reads FIFO Watermark interrupt which is mapped to
  9081. * interrupt1 and interrupt2 from the register 0x56 bit 6 and 2
  9082. * @brief interrupt1 bit 6 in the register 0x56
  9083. * @brief interrupt2 bit 2 in the register 0x56
  9084. *
  9085. *
  9086. * @param v_channel_u8: The value of FIFO Watermark interrupt selection
  9087. * v_channel_u8 | interrupt
  9088. * ---------------|---------------
  9089. * 0 | BMI160_INTR1_MAP_FIFO_WM
  9090. * 1 | BMI160_INTR2_MAP_FIFO_WM
  9091. *
  9092. * @param v_intr_fifo_wm_u8 : The value of FIFO Watermark interrupt enable
  9093. * value | interrupt enable
  9094. * ----------|-------------------
  9095. * 0x01 | BMI160_ENABLE
  9096. * 0x00 | BMI160_DISABLE
  9097. *
  9098. *
  9099. *
  9100. *
  9101. * @return results of bus communication function
  9102. * @retval 0 -> Success
  9103. * @retval -1 -> Error
  9104. *
  9105. *
  9106. */
  9107. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_fifo_wm(
  9108. u8 v_channel_u8, u8 *v_intr_fifo_wm_u8)
  9109. {
  9110. /* variable used to return the status of communication result*/
  9111. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9112. u8 v_data_u8 = BMI160_INIT_VALUE;
  9113. /* check the p_bmi160 structure for NULL pointer assignment*/
  9114. if (p_bmi160 == BMI160_NULL) {
  9115. return E_BMI160_NULL_PTR;
  9116. } else {
  9117. switch (v_channel_u8) {
  9118. /* read the FIFO water mark interrupt */
  9119. case BMI160_INTR1_MAP_FIFO_WM:
  9120. com_rslt =
  9121. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  9122. dev_addr, BMI160_USER_INTR_MAP_1_INTR1_FIFO_WM__REG,
  9123. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9124. *v_intr_fifo_wm_u8 =
  9125. BMI160_GET_BITSLICE(v_data_u8,
  9126. BMI160_USER_INTR_MAP_1_INTR1_FIFO_WM);
  9127. break;
  9128. case BMI160_INTR2_MAP_FIFO_WM:
  9129. com_rslt =
  9130. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  9131. dev_addr, BMI160_USER_INTR_MAP_1_INTR2_FIFO_WM__REG,
  9132. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9133. *v_intr_fifo_wm_u8 =
  9134. BMI160_GET_BITSLICE(v_data_u8,
  9135. BMI160_USER_INTR_MAP_1_INTR2_FIFO_WM);
  9136. break;
  9137. default:
  9138. com_rslt = E_BMI160_OUT_OF_RANGE;
  9139. break;
  9140. }
  9141. }
  9142. return com_rslt;
  9143. }
  9144. /*!
  9145. * @brief This API configures FIFO Watermark interrupt to be mapped to
  9146. * interrupt1 and interrupt2 from the register 0x56 bit 6 and 2
  9147. * @brief interrupt1 bit 6 in the register 0x56
  9148. * @brief interrupt2 bit 2 in the register 0x56
  9149. *
  9150. *
  9151. * @param v_channel_u8: The value of FIFO Watermark interrupt selection
  9152. * v_channel_u8 | interrupt
  9153. * ---------------|---------------
  9154. * 0 | BMI160_INTR1_MAP_FIFO_WM
  9155. * 1 | BMI160_INTR2_MAP_FIFO_WM
  9156. *
  9157. * @param v_intr_fifo_wm_u8 : The value of FIFO Watermark interrupt enable
  9158. * value | interrupt enable
  9159. * ----------|-------------------
  9160. * 0x01 | BMI160_ENABLE
  9161. * 0x00 | BMI160_DISABLE
  9162. *
  9163. *
  9164. *
  9165. *
  9166. * @return results of bus communication function
  9167. * @retval 0 -> Success
  9168. * @retval -1 -> Error
  9169. *
  9170. *
  9171. */
  9172. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_fifo_wm(
  9173. u8 v_channel_u8, u8 v_intr_fifo_wm_u8)
  9174. {
  9175. /* variable used to return the status of communication result*/
  9176. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9177. u8 v_data_u8 = BMI160_INIT_VALUE;
  9178. /* check the p_bmi160 structure for NULL pointer assignment*/
  9179. if (p_bmi160 == BMI160_NULL) {
  9180. return E_BMI160_NULL_PTR;
  9181. } else {
  9182. switch (v_channel_u8) {
  9183. /* write the FIFO water mark interrupt */
  9184. case BMI160_INTR1_MAP_FIFO_WM:
  9185. com_rslt =
  9186. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  9187. dev_addr, BMI160_USER_INTR_MAP_1_INTR1_FIFO_WM__REG,
  9188. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9189. if (com_rslt == SUCCESS) {
  9190. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  9191. BMI160_USER_INTR_MAP_1_INTR1_FIFO_WM,
  9192. v_intr_fifo_wm_u8);
  9193. com_rslt +=
  9194. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  9195. dev_addr,
  9196. BMI160_USER_INTR_MAP_1_INTR1_FIFO_WM__REG,
  9197. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9198. }
  9199. break;
  9200. case BMI160_INTR2_MAP_FIFO_WM:
  9201. com_rslt =
  9202. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  9203. dev_addr, BMI160_USER_INTR_MAP_1_INTR2_FIFO_WM__REG,
  9204. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9205. if (com_rslt == SUCCESS) {
  9206. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  9207. BMI160_USER_INTR_MAP_1_INTR2_FIFO_WM,
  9208. v_intr_fifo_wm_u8);
  9209. com_rslt +=
  9210. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  9211. dev_addr,
  9212. BMI160_USER_INTR_MAP_1_INTR2_FIFO_WM__REG,
  9213. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9214. }
  9215. break;
  9216. default:
  9217. com_rslt = E_BMI160_OUT_OF_RANGE;
  9218. break;
  9219. }
  9220. }
  9221. return com_rslt;
  9222. }
  9223. #endif
  9224. /*!
  9225. * @brief This API reads Data Ready interrupt which is mapped to interrupt1
  9226. * and interrupt2 from the register 0x56
  9227. * @brief interrupt1 bit 7 in the register 0x56
  9228. * @brief interrupt2 bit 3 in the register 0x56
  9229. *
  9230. *
  9231. * @param v_channel_u8: The value of data ready interrupt selection
  9232. * v_channel_u8 | interrupt
  9233. * ---------------|---------------
  9234. * 0 | BMI160_INTR1_MAP_DATA_RDY
  9235. * 1 | BMI160_INTR2_MAP_DATA_RDY
  9236. *
  9237. * @param v_intr_data_rdy_u8 : The value of data ready interrupt enable
  9238. * value | interrupt enable
  9239. * ----------|-------------------
  9240. * 0x01 | BMI160_ENABLE
  9241. * 0x00 | BMI160_DISABLE
  9242. *
  9243. *
  9244. *
  9245. * @return results of bus communication function
  9246. * @retval 0 -> Success
  9247. * @retval -1 -> Error
  9248. *
  9249. *
  9250. */
  9251. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_data_rdy(
  9252. u8 v_channel_u8, u8 *v_intr_data_rdy_u8)
  9253. {
  9254. /* variable used to return the status of communication result*/
  9255. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9256. u8 v_data_u8 = BMI160_INIT_VALUE;
  9257. /* check the p_bmi160 structure for NULL pointer assignment*/
  9258. if (p_bmi160 == BMI160_NULL) {
  9259. return E_BMI160_NULL_PTR;
  9260. } else {
  9261. switch (v_channel_u8) {
  9262. /*Read Data Ready interrupt*/
  9263. case BMI160_INTR1_MAP_DATA_RDY:
  9264. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  9265. dev_addr, BMI160_USER_INTR_MAP_1_INTR1_DATA_RDY__REG,
  9266. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9267. *v_intr_data_rdy_u8 = BMI160_GET_BITSLICE(v_data_u8,
  9268. BMI160_USER_INTR_MAP_1_INTR1_DATA_RDY);
  9269. break;
  9270. case BMI160_INTR2_MAP_DATA_RDY:
  9271. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  9272. dev_addr, BMI160_USER_INTR_MAP_1_INTR2_DATA_RDY__REG,
  9273. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9274. *v_intr_data_rdy_u8 = BMI160_GET_BITSLICE(v_data_u8,
  9275. BMI160_USER_INTR_MAP_1_INTR2_DATA_RDY);
  9276. break;
  9277. default:
  9278. com_rslt = E_BMI160_OUT_OF_RANGE;
  9279. break;
  9280. }
  9281. }
  9282. return com_rslt;
  9283. }
  9284. /*!
  9285. * @brief This API configures Data Ready interrupt to be mapped to
  9286. * interrupt1 and interrupt2 from the register 0x56
  9287. * @brief interrupt1 bit 7 in the register 0x56
  9288. * @brief interrupt2 bit 3 in the register 0x56
  9289. *
  9290. *
  9291. * @param v_channel_u8: The value of data ready interrupt selection
  9292. * v_channel_u8 | interrupt
  9293. * ---------------|---------------
  9294. * 0 | BMI160_INTR1_MAP_DATA_RDY
  9295. * 1 | BMI160_INTR2_MAP_DATA_RDY
  9296. *
  9297. * @param v_intr_data_rdy_u8 : The value of data ready interrupt enable
  9298. * value | interrupt enable
  9299. * ----------|-------------------
  9300. * 0x01 | BMI160_ENABLE
  9301. * 0x00 | BMI160_DISABLE
  9302. *
  9303. *
  9304. *
  9305. * @return results of bus communication function
  9306. * @retval 0 -> Success
  9307. * @retval -1 -> Error
  9308. *
  9309. *
  9310. */
  9311. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_data_rdy(
  9312. u8 v_channel_u8, u8 v_intr_data_rdy_u8)
  9313. {
  9314. /* variable used to return the status of communication result*/
  9315. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9316. u8 v_data_u8 = BMI160_INIT_VALUE;
  9317. /* check the p_bmi160 structure for NULL pointer assignment*/
  9318. if (p_bmi160 == BMI160_NULL) {
  9319. return E_BMI160_NULL_PTR;
  9320. } else {
  9321. switch (v_channel_u8) {
  9322. /*Write Data Ready interrupt*/
  9323. case BMI160_INTR1_MAP_DATA_RDY:
  9324. com_rslt =
  9325. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  9326. dev_addr, BMI160_USER_INTR_MAP_1_INTR1_DATA_RDY__REG,
  9327. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9328. if (com_rslt == SUCCESS) {
  9329. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  9330. BMI160_USER_INTR_MAP_1_INTR1_DATA_RDY,
  9331. v_intr_data_rdy_u8);
  9332. com_rslt +=
  9333. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  9334. dev_addr, BMI160_USER_INTR_MAP_1_INTR1_DATA_RDY__REG,
  9335. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9336. }
  9337. break;
  9338. case BMI160_INTR2_MAP_DATA_RDY:
  9339. com_rslt =
  9340. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  9341. dev_addr, BMI160_USER_INTR_MAP_1_INTR2_DATA_RDY__REG,
  9342. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9343. if (com_rslt == SUCCESS) {
  9344. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  9345. BMI160_USER_INTR_MAP_1_INTR2_DATA_RDY,
  9346. v_intr_data_rdy_u8);
  9347. com_rslt +=
  9348. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  9349. dev_addr, BMI160_USER_INTR_MAP_1_INTR2_DATA_RDY__REG,
  9350. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9351. }
  9352. break;
  9353. default:
  9354. com_rslt = E_BMI160_OUT_OF_RANGE;
  9355. break;
  9356. }
  9357. /*Accel and Gyro power mode check */
  9358. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  9359. /*interface idle time delay */
  9360. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  9361. }
  9362. return com_rslt;
  9363. }
  9364. /*!
  9365. * @brief This API reads data source for the interrupt
  9366. * engine for the single and double tap interrupts from the register
  9367. * 0x58 bit 3
  9368. *
  9369. *
  9370. * @param v_tap_source_u8 : The value of the tap source
  9371. * value | Description
  9372. * ----------|-------------------
  9373. * 0x01 | UNFILTER_DATA
  9374. * 0x00 | FILTER_DATA
  9375. *
  9376. *
  9377. * @return results of bus communication function
  9378. * @retval 0 -> Success
  9379. * @retval -1 -> Error
  9380. *
  9381. *
  9382. */
  9383. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_tap_source(u8 *v_tap_source_u8)
  9384. {
  9385. /* variable used to return the status of communication result*/
  9386. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9387. u8 v_data_u8 = BMI160_INIT_VALUE;
  9388. /* check the p_bmi160 structure for NULL pointer assignment*/
  9389. if (p_bmi160 == BMI160_NULL) {
  9390. return E_BMI160_NULL_PTR;
  9391. } else {
  9392. /* read the tap source interrupt */
  9393. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  9394. p_bmi160->dev_addr,
  9395. BMI160_USER_INTR_DATA_0_INTR_TAP_SOURCE__REG,
  9396. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9397. *v_tap_source_u8 = BMI160_GET_BITSLICE(v_data_u8,
  9398. BMI160_USER_INTR_DATA_0_INTR_TAP_SOURCE);
  9399. }
  9400. return com_rslt;
  9401. }
  9402. /*!
  9403. * @brief This API writes data source for the interrupt
  9404. * engine for the single and double tap interrupts from the register
  9405. * 0x58 bit 3
  9406. *
  9407. *
  9408. * @param v_tap_source_u8 : The value of the tap source
  9409. * value | Description
  9410. * ----------|-------------------
  9411. * 0x01 | UNFILTER_DATA
  9412. * 0x00 | FILTER_DATA
  9413. *
  9414. *
  9415. * @return results of bus communication function
  9416. * @retval 0 -> Success
  9417. * @retval -1 -> Error
  9418. *
  9419. *
  9420. */
  9421. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_tap_source(
  9422. u8 v_tap_source_u8)
  9423. {
  9424. /* variable used to return the status of communication result*/
  9425. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9426. u8 v_data_u8 = BMI160_INIT_VALUE;
  9427. /* check the p_bmi160 structure for NULL pointer assignment*/
  9428. if (p_bmi160 == BMI160_NULL) {
  9429. return E_BMI160_NULL_PTR;
  9430. } else {
  9431. if (v_tap_source_u8 <= BMI160_MAX_VALUE_SOURCE_INTR) {
  9432. /* write the tap source interrupt */
  9433. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  9434. (p_bmi160->dev_addr,
  9435. BMI160_USER_INTR_DATA_0_INTR_TAP_SOURCE__REG,
  9436. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9437. if (com_rslt == SUCCESS) {
  9438. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  9439. BMI160_USER_INTR_DATA_0_INTR_TAP_SOURCE,
  9440. v_tap_source_u8);
  9441. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  9442. (p_bmi160->dev_addr,
  9443. BMI160_USER_INTR_DATA_0_INTR_TAP_SOURCE__REG,
  9444. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9445. /*Check for the power mode of Accel and
  9446. gyro not in normal mode */
  9447. if (bmi160_power_mode_status_u8_g !=
  9448. BMI160_NORMAL_MODE)
  9449. /*interface idle time delay */
  9450. p_bmi160->delay_msec(
  9451. BMI160_GEN_READ_WRITE_DELAY);
  9452. }
  9453. } else {
  9454. com_rslt = E_BMI160_OUT_OF_RANGE;
  9455. }
  9456. }
  9457. return com_rslt;
  9458. }
  9459. /*!
  9460. * @brief This API Reads Data source for the
  9461. * interrupt engine for the low and high g interrupts
  9462. * from the register 0x58 bit 7
  9463. *
  9464. * @param v_low_high_source_u8 : The value of the low-g/high-g source
  9465. * value | Description
  9466. * ----------|-------------------
  9467. * 0x01 | UNFILTER_DATA
  9468. * 0x00 | FILTER_DATA
  9469. *
  9470. *
  9471. * @return results of bus communication function
  9472. * @retval 0 -> Success
  9473. * @retval -1 -> Error
  9474. *
  9475. *
  9476. */
  9477. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_low_high_source(
  9478. u8 *v_low_high_source_u8)
  9479. {
  9480. /* variable used to return the status of communication result*/
  9481. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9482. u8 v_data_u8 = BMI160_INIT_VALUE;
  9483. /* check the p_bmi160 structure for NULL pointer assignment*/
  9484. if (p_bmi160 == BMI160_NULL) {
  9485. return E_BMI160_NULL_PTR;
  9486. } else {
  9487. /* read the high_low_g source interrupt */
  9488. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  9489. p_bmi160->dev_addr,
  9490. BMI160_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE__REG,
  9491. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9492. *v_low_high_source_u8 = BMI160_GET_BITSLICE(v_data_u8,
  9493. BMI160_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE);
  9494. }
  9495. return com_rslt;
  9496. }
  9497. /*!
  9498. * @brief This API writes Data source for the
  9499. * interrupt engine for the low and high g interrupts
  9500. * from the register 0x58 bit 7
  9501. *
  9502. * @param v_low_high_source_u8 : The value of the low-g/high-g source
  9503. * value | Description
  9504. * ----------|-------------------
  9505. * 0x01 | UNFILTER_DATA
  9506. * 0x00 | FILTER_DATA
  9507. *
  9508. *
  9509. * @return results of bus communication function
  9510. * @retval 0 -> Success
  9511. * @retval -1 -> Error
  9512. *
  9513. *
  9514. */
  9515. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_low_high_source(
  9516. u8 v_low_high_source_u8)
  9517. {
  9518. /* variable used to return the status of communication result*/
  9519. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9520. u8 v_data_u8 = BMI160_INIT_VALUE;
  9521. /* check the p_bmi160 structure for NULL pointer assignment*/
  9522. if (p_bmi160 == BMI160_NULL) {
  9523. return E_BMI160_NULL_PTR;
  9524. } else {
  9525. if (v_low_high_source_u8 <= BMI160_MAX_VALUE_SOURCE_INTR) {
  9526. /* write the high_low_g source interrupt */
  9527. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  9528. (p_bmi160->dev_addr,
  9529. BMI160_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE__REG,
  9530. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9531. if (com_rslt == SUCCESS) {
  9532. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  9533. BMI160_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE,
  9534. v_low_high_source_u8);
  9535. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  9536. (p_bmi160->dev_addr,
  9537. BMI160_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE__REG,
  9538. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9539. /*Check for the power mode of Accel and
  9540. gyro not in normal mode */
  9541. if (bmi160_power_mode_status_u8_g !=
  9542. BMI160_NORMAL_MODE)
  9543. /*interface idle time delay */
  9544. p_bmi160->delay_msec(
  9545. BMI160_GEN_READ_WRITE_DELAY);
  9546. }
  9547. } else {
  9548. com_rslt = E_BMI160_OUT_OF_RANGE;
  9549. }
  9550. }
  9551. return com_rslt;
  9552. }
  9553. /*!
  9554. * @brief This API reads Data source for the
  9555. * interrupt engine for the nomotion and anymotion interrupts
  9556. * from the register 0x59 bit 7
  9557. *
  9558. * @param v_motion_source_u8 :
  9559. * The value of the any/no motion interrupt source
  9560. * value | Description
  9561. * ----------|-------------------
  9562. * 0x01 | UNFILTER_DATA
  9563. * 0x00 | FILTER_DATA
  9564. *
  9565. * @return results of bus communication function
  9566. * @retval 0 -> Success
  9567. * @retval -1 -> Error
  9568. *
  9569. *
  9570. */
  9571. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_motion_source(
  9572. u8 *v_motion_source_u8)
  9573. {
  9574. /* variable used to return the status of communication result*/
  9575. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9576. u8 v_data_u8 = BMI160_INIT_VALUE;
  9577. /* check the p_bmi160 structure for NULL pointer assignment*/
  9578. if (p_bmi160 == BMI160_NULL) {
  9579. return E_BMI160_NULL_PTR;
  9580. } else {
  9581. /* read the any/no motion interrupt */
  9582. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  9583. p_bmi160->dev_addr,
  9584. BMI160_USER_INTR_DATA_1_INTR_MOTION_SOURCE__REG,
  9585. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9586. *v_motion_source_u8 = BMI160_GET_BITSLICE(v_data_u8,
  9587. BMI160_USER_INTR_DATA_1_INTR_MOTION_SOURCE);
  9588. }
  9589. return com_rslt;
  9590. }
  9591. /*!
  9592. * @brief This API writes Data source for the
  9593. * interrupt engine for the nomotion and anymotion interrupts
  9594. * from the register 0x59 bit 7
  9595. *
  9596. * @param v_motion_source_u8 :
  9597. * The value of the any/no motion interrupt source
  9598. * value | Description
  9599. * ----------|-------------------
  9600. * 0x01 | UNFILTER_DATA
  9601. * 0x00 | FILTER_DATA
  9602. *
  9603. * @return results of bus communication function
  9604. * @retval 0 -> Success
  9605. * @retval -1 -> Error
  9606. *
  9607. *
  9608. */
  9609. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_motion_source(
  9610. u8 v_motion_source_u8)
  9611. {
  9612. /* variable used to return the status of communication result*/
  9613. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9614. u8 v_data_u8 = BMI160_INIT_VALUE;
  9615. /* check the p_bmi160 structure for NULL pointer assignment*/
  9616. if (p_bmi160 == BMI160_NULL) {
  9617. return E_BMI160_NULL_PTR;
  9618. } else {
  9619. if (v_motion_source_u8 <= BMI160_MAX_VALUE_SOURCE_INTR) {
  9620. /* write the any/no motion interrupt */
  9621. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  9622. p_bmi160->dev_addr,
  9623. BMI160_USER_INTR_DATA_1_INTR_MOTION_SOURCE__REG,
  9624. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9625. if (com_rslt == SUCCESS) {
  9626. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  9627. BMI160_USER_INTR_DATA_1_INTR_MOTION_SOURCE,
  9628. v_motion_source_u8);
  9629. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  9630. p_bmi160->dev_addr,
  9631. BMI160_USER_INTR_DATA_1_INTR_MOTION_SOURCE__REG,
  9632. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9633. /*Check for the power mode of Accel and
  9634. gyro not in normal mode */
  9635. if (bmi160_power_mode_status_u8_g !=
  9636. BMI160_NORMAL_MODE)
  9637. /*interface idle time delay */
  9638. p_bmi160->delay_msec(
  9639. BMI160_GEN_READ_WRITE_DELAY);
  9640. }
  9641. } else {
  9642. com_rslt = E_BMI160_OUT_OF_RANGE;
  9643. }
  9644. }
  9645. return com_rslt;
  9646. }
  9647. /*!
  9648. * @brief This API is used to read the low_g duration from register
  9649. * 0x5A bit 0 to 7
  9650. *
  9651. *
  9652. *
  9653. *
  9654. * @param v_low_g_durn_u8 : The value of low_g duration
  9655. *
  9656. * @note Low_g duration trigger trigger delay according to
  9657. * "(v_low_g_durn_u8 * 2.5)ms" in a range from 2.5ms to 640ms.
  9658. * the default corresponds delay is 20ms
  9659. * @note When low_g data source of interrupt is unfiltered
  9660. * the sensor must not be in low power mode
  9661. *
  9662. * @return results of bus communication function
  9663. * @retval 0 -> Success
  9664. * @retval -1 -> Error
  9665. *
  9666. *
  9667. */
  9668. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_low_g_durn(
  9669. u8 *v_low_g_durn_u8)
  9670. {
  9671. /* variable used to return the status of communication result*/
  9672. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9673. u8 v_data_u8 = BMI160_INIT_VALUE;
  9674. /* check the p_bmi160 structure for NULL pointer assignment*/
  9675. if (p_bmi160 == BMI160_NULL) {
  9676. return E_BMI160_NULL_PTR;
  9677. } else {
  9678. /* read the low_g interrupt */
  9679. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  9680. p_bmi160->dev_addr,
  9681. BMI160_USER_INTR_LOWHIGH_0_INTR_LOW_DURN__REG,
  9682. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9683. *v_low_g_durn_u8 =
  9684. BMI160_GET_BITSLICE(v_data_u8,
  9685. BMI160_USER_INTR_LOWHIGH_0_INTR_LOW_DURN);
  9686. }
  9687. return com_rslt;
  9688. }
  9689. /*!
  9690. * @brief This API is used to write the low_g duration from register
  9691. * 0x5A bit 0 to 7
  9692. *
  9693. *
  9694. *
  9695. *
  9696. * @param v_low_g_durn_u8 : The value of low_g duration
  9697. *
  9698. * @note Low_g duration trigger trigger delay according to
  9699. * "(v_low_g_durn_u8 * 2.5)ms" in a range from 2.5ms to 640ms.
  9700. * the default corresponds delay is 20ms
  9701. * @note When low_g data source of interrupt is unfiltered
  9702. * the sensor must not be in low power mode
  9703. *
  9704. * @return results of bus communication function
  9705. * @retval 0 -> Success
  9706. * @retval -1 -> Error
  9707. *
  9708. *
  9709. */
  9710. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_low_g_durn(u8 v_low_g_durn_u8)
  9711. {
  9712. /* variable used to return the status of communication result*/
  9713. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9714. /* check the p_bmi160 structure for NULL pointer assignment*/
  9715. if (p_bmi160 == BMI160_NULL) {
  9716. return E_BMI160_NULL_PTR;
  9717. } else {
  9718. /* write the low_g interrupt */
  9719. com_rslt = p_bmi160->BMI160_BUS_WRITE_FUNC(
  9720. p_bmi160->dev_addr,
  9721. BMI160_USER_INTR_LOWHIGH_0_INTR_LOW_DURN__REG,
  9722. &v_low_g_durn_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9723. /*Check for the power mode of Accel and
  9724. gyro not in normal mode */
  9725. if (bmi160_power_mode_status_u8_g !=
  9726. BMI160_NORMAL_MODE)
  9727. /*interface idle time delay */
  9728. p_bmi160->delay_msec(
  9729. BMI160_GEN_READ_WRITE_DELAY);
  9730. }
  9731. return com_rslt;
  9732. }
  9733. /*!
  9734. * @brief This API is used to read Threshold
  9735. * definition for the low-g interrupt from the register 0x5B bit 0 to 7
  9736. *
  9737. *
  9738. *
  9739. *
  9740. * @param v_low_g_thres_u8 : The value of low_g threshold
  9741. *
  9742. * @note Low_g interrupt trigger threshold according to
  9743. * (v_low_g_thres_u8 * 7.81)mg for v_low_g_thres_u8 > 0
  9744. * 3.91 mg for v_low_g_thres_u8 = 0
  9745. * The threshold range is from 3.91mg to 2.000mg
  9746. *
  9747. *
  9748. * @return results of bus communication function
  9749. * @retval 0 -> Success
  9750. * @retval -1 -> Error
  9751. *
  9752. *
  9753. */
  9754. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_low_g_thres(
  9755. u8 *v_low_g_thres_u8)
  9756. {
  9757. /* variable used to return the status of communication result*/
  9758. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9759. u8 v_data_u8 = BMI160_INIT_VALUE;
  9760. /* check the p_bmi160 structure for NULL pointer assignment*/
  9761. if (p_bmi160 == BMI160_NULL) {
  9762. return E_BMI160_NULL_PTR;
  9763. } else {
  9764. /* read low_g threshold */
  9765. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  9766. p_bmi160->dev_addr,
  9767. BMI160_USER_INTR_LOWHIGH_1_INTR_LOW_THRES__REG,
  9768. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9769. *v_low_g_thres_u8 =
  9770. BMI160_GET_BITSLICE(v_data_u8,
  9771. BMI160_USER_INTR_LOWHIGH_1_INTR_LOW_THRES);
  9772. }
  9773. return com_rslt;
  9774. }
  9775. /*!
  9776. * @brief This API is used to write Threshold
  9777. * definition for the low-g interrupt from the register 0x5B bit 0 to 7
  9778. *
  9779. *
  9780. *
  9781. *
  9782. * @param v_low_g_thres_u8 : The value of low_g threshold
  9783. *
  9784. * @note Low_g interrupt trigger threshold according to
  9785. * (v_low_g_thres_u8 * 7.81)mg for v_low_g_thres_u8 > 0
  9786. * 3.91 mg for v_low_g_thres_u8 = 0
  9787. * The threshold range is from 3.91mg to 2.000mg
  9788. *
  9789. *
  9790. * @return results of bus communication function
  9791. * @retval 0 -> Success
  9792. * @retval -1 -> Error
  9793. *
  9794. *
  9795. */
  9796. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_low_g_thres(
  9797. u8 v_low_g_thres_u8)
  9798. {
  9799. /* variable used to return the status of communication result*/
  9800. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9801. /* check the p_bmi160 structure for NULL pointer assignment*/
  9802. if (p_bmi160 == BMI160_NULL) {
  9803. return E_BMI160_NULL_PTR;
  9804. } else {
  9805. /* write low_g threshold */
  9806. com_rslt = p_bmi160->BMI160_BUS_WRITE_FUNC(
  9807. p_bmi160->dev_addr,
  9808. BMI160_USER_INTR_LOWHIGH_1_INTR_LOW_THRES__REG,
  9809. &v_low_g_thres_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9810. /*Check for the power mode of Accel and
  9811. gyro not in normal mode */
  9812. if (bmi160_power_mode_status_u8_g !=
  9813. BMI160_NORMAL_MODE)
  9814. /*interface idle time delay */
  9815. p_bmi160->delay_msec(
  9816. BMI160_GEN_READ_WRITE_DELAY);
  9817. }
  9818. return com_rslt;
  9819. }
  9820. /*!
  9821. * @brief This API reads Low-g interrupt hysteresis
  9822. * from the register 0x5C bit 0 to 1
  9823. *
  9824. * @param v_low_hyst_u8 :The value of low_g hysteresis
  9825. *
  9826. * @note Low_g hysteresis calculated by v_low_hyst_u8*125 mg
  9827. *
  9828. * @return results of bus communication function
  9829. * @retval 0 -> Success
  9830. * @retval -1 -> Error
  9831. *
  9832. *
  9833. */
  9834. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_low_g_hyst(
  9835. u8 *v_low_hyst_u8)
  9836. {
  9837. /* variable used to return the status of communication result*/
  9838. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9839. u8 v_data_u8 = BMI160_INIT_VALUE;
  9840. /* check the p_bmi160 structure for NULL pointer assignment*/
  9841. if (p_bmi160 == BMI160_NULL) {
  9842. return E_BMI160_NULL_PTR;
  9843. } else {
  9844. /* read low_g hysteresis*/
  9845. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  9846. p_bmi160->dev_addr,
  9847. BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST__REG,
  9848. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9849. *v_low_hyst_u8 = BMI160_GET_BITSLICE(
  9850. v_data_u8,
  9851. BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST);
  9852. }
  9853. return com_rslt;
  9854. }
  9855. /*!
  9856. * @brief This API writes Low-g interrupt hysteresis
  9857. * from the register 0x5C bit 0 to 1
  9858. *
  9859. * @param v_low_hyst_u8 :The value of low_g hysteresis
  9860. *
  9861. * @note Low_g hysteresis calculated by v_low_hyst_u8*125 mg
  9862. *
  9863. * @return results of bus communication function
  9864. * @retval 0 -> Success
  9865. * @retval -1 -> Error
  9866. *
  9867. *
  9868. */
  9869. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_low_g_hyst(
  9870. u8 v_low_hyst_u8)
  9871. {
  9872. /* variable used to return the status of communication result*/
  9873. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9874. u8 v_data_u8 = BMI160_INIT_VALUE;
  9875. /* check the p_bmi160 structure for NULL pointer assignment*/
  9876. if (p_bmi160 == BMI160_NULL) {
  9877. return E_BMI160_NULL_PTR;
  9878. } else {
  9879. /* write low_g hysteresis*/
  9880. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  9881. (p_bmi160->dev_addr,
  9882. BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST__REG,
  9883. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9884. if (com_rslt == SUCCESS) {
  9885. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  9886. BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST,
  9887. v_low_hyst_u8);
  9888. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  9889. p_bmi160->dev_addr,
  9890. BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST__REG,
  9891. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9892. /*Check for the power mode of Accel and
  9893. gyro not in normal mode */
  9894. if (bmi160_power_mode_status_u8_g !=
  9895. BMI160_NORMAL_MODE)
  9896. /*interface idle time delay */
  9897. p_bmi160->delay_msec(
  9898. BMI160_GEN_READ_WRITE_DELAY);
  9899. }
  9900. }
  9901. return com_rslt;
  9902. }
  9903. /*!
  9904. * @brief This API reads Low-g interrupt mode
  9905. * from the register 0x5C bit 2
  9906. *
  9907. * @param v_low_g_mode_u8 : The value of low_g mode
  9908. * Value | Description
  9909. * ----------|-----------------
  9910. * 0 | single-axis
  9911. * 1 | axis-summing
  9912. *
  9913. *
  9914. * @return results of bus communication function
  9915. * @retval 0 -> Success
  9916. * @retval -1 -> Error
  9917. *
  9918. *
  9919. */
  9920. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_low_g_mode(u8 *v_low_g_mode_u8)
  9921. {
  9922. /* variable used to return the status of communication result*/
  9923. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9924. u8 v_data_u8 = BMI160_INIT_VALUE;
  9925. /* check the p_bmi160 structure for NULL pointer assignment*/
  9926. if (p_bmi160 == BMI160_NULL) {
  9927. return E_BMI160_NULL_PTR;
  9928. } else {
  9929. /*read Low-g interrupt mode*/
  9930. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  9931. p_bmi160->dev_addr,
  9932. BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE__REG,
  9933. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9934. *v_low_g_mode_u8 = BMI160_GET_BITSLICE(v_data_u8,
  9935. BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE);
  9936. }
  9937. return com_rslt;
  9938. }
  9939. /*!
  9940. * @brief This API writes Low-g interrupt mode
  9941. * from the register 0x5C bit 2
  9942. *
  9943. * @param v_low_g_mode_u8 : The value of low_g mode
  9944. * Value | Description
  9945. * ----------|-----------------
  9946. * 0 | single-axis
  9947. * 1 | axis-summing
  9948. *
  9949. *
  9950. * @return results of bus communication function
  9951. * @retval 0 -> Success
  9952. * @retval -1 -> Error
  9953. *
  9954. *
  9955. */
  9956. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_low_g_mode(
  9957. u8 v_low_g_mode_u8)
  9958. {
  9959. /* variable used to return the status of communication result*/
  9960. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9961. u8 v_data_u8 = BMI160_INIT_VALUE;
  9962. /* check the p_bmi160 structure for NULL pointer assignment*/
  9963. if (p_bmi160 == BMI160_NULL) {
  9964. return E_BMI160_NULL_PTR;
  9965. } else {
  9966. if (v_low_g_mode_u8 <= BMI160_MAX_VALUE_LOW_G_MODE) {
  9967. /*write Low-g interrupt mode*/
  9968. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  9969. p_bmi160->dev_addr,
  9970. BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE__REG,
  9971. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9972. if (com_rslt == SUCCESS) {
  9973. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  9974. BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE,
  9975. v_low_g_mode_u8);
  9976. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  9977. p_bmi160->dev_addr,
  9978. BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE__REG,
  9979. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  9980. /*Check for the power mode of Accel and
  9981. gyro not in normal mode */
  9982. if (bmi160_power_mode_status_u8_g !=
  9983. BMI160_NORMAL_MODE)
  9984. /*interface idle time delay */
  9985. p_bmi160->delay_msec(
  9986. BMI160_GEN_READ_WRITE_DELAY);
  9987. }
  9988. } else {
  9989. com_rslt = E_BMI160_OUT_OF_RANGE;
  9990. }
  9991. }
  9992. return com_rslt;
  9993. }
  9994. /*!
  9995. * @brief This API reads High-g interrupt hysteresis
  9996. * from the register 0x5C bit 6 and 7
  9997. *
  9998. * @param v_high_g_hyst_u8 : The value of high hysteresis
  9999. *
  10000. * @note High_g hysteresis changes according to Accel g range
  10001. * Accel g range can be set by the function "bmi160_set_accel_range"
  10002. * accel_range | high_g hysteresis
  10003. * ----------------|---------------------
  10004. * 2g | high_hy*125 mg
  10005. * 4g | high_hy*250 mg
  10006. * 8g | high_hy*500 mg
  10007. * 16g | high_hy*1000 mg
  10008. *
  10009. * @return results of bus communication function
  10010. * @retval 0 -> Success
  10011. * @retval -1 -> Error
  10012. *
  10013. *
  10014. */
  10015. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_high_g_hyst(
  10016. u8 *v_high_g_hyst_u8)
  10017. {
  10018. /* variable used to return the status of communication result*/
  10019. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10020. u8 v_data_u8 = BMI160_INIT_VALUE;
  10021. /* check the p_bmi160 structure for NULL pointer assignment*/
  10022. if (p_bmi160 == BMI160_NULL) {
  10023. return E_BMI160_NULL_PTR;
  10024. } else {
  10025. /* read high_g hysteresis*/
  10026. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  10027. (p_bmi160->dev_addr,
  10028. BMI160_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST__REG,
  10029. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10030. *v_high_g_hyst_u8 = BMI160_GET_BITSLICE(v_data_u8,
  10031. BMI160_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST);
  10032. }
  10033. return com_rslt;
  10034. }
  10035. /*!
  10036. * @brief This API writes High-g interrupt hysteresis
  10037. * from the register 0x5C bit 6 and 7
  10038. *
  10039. * @param v_high_g_hyst_u8 : The value of high hysteresis
  10040. *
  10041. * @note High_g hysteresis changes according to Accel g range
  10042. * Accel g range can be set by the function "bmi160_set_accel_range"
  10043. * accel_range | high_g hysteresis
  10044. * ----------------|---------------------
  10045. * 2g | high_hy*125 mg
  10046. * 4g | high_hy*250 mg
  10047. * 8g | high_hy*500 mg
  10048. * 16g | high_hy*1000 mg
  10049. *
  10050. * @return results of bus communication function
  10051. * @retval 0 -> Success
  10052. * @retval -1 -> Error
  10053. *
  10054. *
  10055. */
  10056. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_high_g_hyst(
  10057. u8 v_high_g_hyst_u8)
  10058. {
  10059. /* variable used to return the status of communication result*/
  10060. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10061. u8 v_data_u8 = BMI160_INIT_VALUE;
  10062. /* check the p_bmi160 structure for NULL pointer assignment*/
  10063. if (p_bmi160 == BMI160_NULL) {
  10064. return E_BMI160_NULL_PTR;
  10065. } else {
  10066. /* write high_g hysteresis*/
  10067. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  10068. p_bmi160->dev_addr,
  10069. BMI160_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST__REG,
  10070. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10071. if (com_rslt == SUCCESS) {
  10072. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  10073. BMI160_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST,
  10074. v_high_g_hyst_u8);
  10075. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  10076. p_bmi160->dev_addr,
  10077. BMI160_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST__REG,
  10078. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10079. /*Check for the power mode of Accel and
  10080. gyro not in normal mode */
  10081. if (bmi160_power_mode_status_u8_g !=
  10082. BMI160_NORMAL_MODE)
  10083. /*interface idle time delay */
  10084. p_bmi160->delay_msec(
  10085. BMI160_GEN_READ_WRITE_DELAY);
  10086. }
  10087. }
  10088. return com_rslt;
  10089. }
  10090. /*!
  10091. * @brief This API is used to read Delay
  10092. * time definition for the high-g interrupt from the register
  10093. * 0x5D bit 0 to 7
  10094. *
  10095. *
  10096. *
  10097. * @param v_high_g_durn_u8 : The value of high duration
  10098. *
  10099. * @note High_g interrupt delay triggered according to
  10100. * v_high_g_durn_u8 * 2.5ms in a range from 2.5ms to 640ms
  10101. *
  10102. * @return results of bus communication function
  10103. * @retval 0 -> Success
  10104. * @retval -1 -> Error
  10105. *
  10106. *
  10107. */
  10108. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_high_g_durn(
  10109. u8 *v_high_g_durn_u8)
  10110. {
  10111. /* variable used to return the status of communication result*/
  10112. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10113. u8 v_data_u8 = BMI160_INIT_VALUE;
  10114. /* check the p_bmi160 structure for NULL pointer assignment*/
  10115. if (p_bmi160 == BMI160_NULL) {
  10116. return E_BMI160_NULL_PTR;
  10117. } else {
  10118. /* read high_g duration*/
  10119. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  10120. p_bmi160->dev_addr,
  10121. BMI160_USER_INTR_LOWHIGH_3_INTR_HIGH_G_DURN__REG,
  10122. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10123. *v_high_g_durn_u8 =
  10124. BMI160_GET_BITSLICE(v_data_u8,
  10125. BMI160_USER_INTR_LOWHIGH_3_INTR_HIGH_G_DURN);
  10126. }
  10127. return com_rslt;
  10128. }
  10129. /*!
  10130. * @brief This API is used to write Delay
  10131. * time definition for the high-g interrupt from the register
  10132. * 0x5D bit 0 to 7
  10133. *
  10134. *
  10135. *
  10136. * @param v_high_g_durn_u8 : The value of high duration
  10137. *
  10138. * @note High_g interrupt delay triggered according to
  10139. * v_high_g_durn_u8 * 2.5ms in a range from 2.5ms to 640ms
  10140. *
  10141. * @return results of bus communication function
  10142. * @retval 0 -> Success
  10143. * @retval -1 -> Error
  10144. *
  10145. *
  10146. */
  10147. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_high_g_durn(
  10148. u8 v_high_g_durn_u8)
  10149. {
  10150. /* variable used to return the status of communication result*/
  10151. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10152. /* check the p_bmi160 structure for NULL pointer assignment*/
  10153. if (p_bmi160 == BMI160_NULL) {
  10154. return E_BMI160_NULL_PTR;
  10155. } else {
  10156. /* write high_g duration*/
  10157. com_rslt = p_bmi160->BMI160_BUS_WRITE_FUNC
  10158. (p_bmi160->dev_addr,
  10159. BMI160_USER_INTR_LOWHIGH_3_INTR_HIGH_G_DURN__REG,
  10160. &v_high_g_durn_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10161. /*Check for the power mode of Accel and
  10162. gyro not in normal mode */
  10163. if (bmi160_power_mode_status_u8_g !=
  10164. BMI160_NORMAL_MODE)
  10165. /*interface idle time delay */
  10166. p_bmi160->delay_msec(
  10167. BMI160_GEN_READ_WRITE_DELAY);
  10168. }
  10169. return com_rslt;
  10170. }
  10171. /*!
  10172. * @brief This API is used to read Threshold
  10173. * definition for the high-g interrupt from the register 0x5E 0 to 7
  10174. *
  10175. *
  10176. *
  10177. *
  10178. * @param v_high_g_thres_u8 : Pointer holding the value of Threshold
  10179. * @note High_g threshold changes according to Accel g range
  10180. * Accel g range can be set by the function "bmi160_set_accel_range"
  10181. * accel_range | high_g threshold
  10182. * ----------------|---------------------
  10183. * 2g | v_high_g_thres_u8*7.81 mg
  10184. * 4g | v_high_g_thres_u8*15.63 mg
  10185. * 8g | v_high_g_thres_u8*31.25 mg
  10186. * 16g | v_high_g_thres_u8*62.5 mg
  10187. * @note when v_high_g_thres_u8 = 0
  10188. * accel_range | high_g threshold
  10189. * ----------------|---------------------
  10190. * 2g | 3.91 mg
  10191. * 4g | 7.81 mg
  10192. * 8g | 15.63 mg
  10193. * 16g | 31.25 mg
  10194. *
  10195. *
  10196. * @return results of bus communication function
  10197. * @retval 0 -> Success
  10198. * @retval -1 -> Error
  10199. *
  10200. *
  10201. */
  10202. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_high_g_thres(
  10203. u8 *v_high_g_thres_u8)
  10204. {
  10205. /* variable used to return the status of communication result*/
  10206. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10207. u8 v_data_u8 = BMI160_INIT_VALUE;
  10208. /* check the p_bmi160 structure for NULL pointer assignment*/
  10209. if (p_bmi160 == BMI160_NULL) {
  10210. return E_BMI160_NULL_PTR;
  10211. } else {
  10212. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  10213. p_bmi160->dev_addr,
  10214. BMI160_USER_INTR_LOWHIGH_4_INTR_HIGH_THRES__REG,
  10215. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10216. *v_high_g_thres_u8 =
  10217. BMI160_GET_BITSLICE(v_data_u8,
  10218. BMI160_USER_INTR_LOWHIGH_4_INTR_HIGH_THRES);
  10219. }
  10220. return com_rslt;
  10221. }
  10222. /*!
  10223. * @brief This API is used to write Threshold
  10224. * definition for the high-g interrupt from the register 0x5E 0 to 7
  10225. *
  10226. *
  10227. *
  10228. *
  10229. * @param v_high_g_thres_u8 : Pointer holding the value of Threshold
  10230. * @note High_g threshold changes according to Accel g range
  10231. * Accel g range can be set by the function "bmi160_set_accel_range"
  10232. * accel_range | high_g threshold
  10233. * ----------------|---------------------
  10234. * 2g | v_high_g_thres_u8*7.81 mg
  10235. * 4g | v_high_g_thres_u8*15.63 mg
  10236. * 8g | v_high_g_thres_u8*31.25 mg
  10237. * 16g | v_high_g_thres_u8*62.5 mg
  10238. * @note when v_high_g_thres_u8 = 0
  10239. * accel_range | high_g threshold
  10240. * ----------------|---------------------
  10241. * 2g | 3.91 mg
  10242. * 4g | 7.81 mg
  10243. * 8g | 15.63 mg
  10244. * 16g | 31.25 mg
  10245. *
  10246. *
  10247. * @return results of bus communication function
  10248. * @retval 0 -> Success
  10249. * @retval -1 -> Error
  10250. *
  10251. *
  10252. */
  10253. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_high_g_thres(
  10254. u8 v_high_g_thres_u8)
  10255. {
  10256. /* variable used to return the status of communication result*/
  10257. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10258. /* check the p_bmi160 structure for NULL pointer assignment*/
  10259. if (p_bmi160 == BMI160_NULL) {
  10260. return E_BMI160_NULL_PTR;
  10261. } else {
  10262. com_rslt = p_bmi160->BMI160_BUS_WRITE_FUNC(
  10263. p_bmi160->dev_addr,
  10264. BMI160_USER_INTR_LOWHIGH_4_INTR_HIGH_THRES__REG,
  10265. &v_high_g_thres_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10266. /*Check for the power mode of Accel and
  10267. gyro not in normal mode */
  10268. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  10269. /*interface idle time delay */
  10270. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  10271. }
  10272. return com_rslt;
  10273. }
  10274. /*!
  10275. * @brief This API reads any motion duration
  10276. * from the register 0x5F bit 0 and 1
  10277. *
  10278. * @param v_any_motion_durn_u8 : The value of any motion duration
  10279. *
  10280. * @note Any motion duration can be calculated by "v_any_motion_durn_u8 + 1"
  10281. *
  10282. * @return results of bus communication function
  10283. * @retval 0 -> Success
  10284. * @retval -1 -> Error
  10285. *
  10286. *
  10287. */
  10288. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_any_motion_durn(
  10289. u8 *v_any_motion_durn_u8)
  10290. {
  10291. /* variable used to return the status of communication result*/
  10292. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10293. u8 v_data_u8 = BMI160_INIT_VALUE;
  10294. /* check the p_bmi160 structure for NULL pointer assignment*/
  10295. if (p_bmi160 == BMI160_NULL) {
  10296. return E_BMI160_NULL_PTR;
  10297. } else {
  10298. /* read any motion duration*/
  10299. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  10300. (p_bmi160->dev_addr,
  10301. BMI160_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN__REG,
  10302. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10303. *v_any_motion_durn_u8 = BMI160_GET_BITSLICE
  10304. (v_data_u8,
  10305. BMI160_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN);
  10306. }
  10307. return com_rslt;
  10308. }
  10309. /*!
  10310. * @brief This API writes any motion duration
  10311. * from the register 0x5F bit 0 and 1
  10312. *
  10313. * @param v_any_motion_durn_u8 : The value of any motion duration
  10314. *
  10315. * @note Any motion duration can be calculated by "v_any_motion_durn_u8 + 1"
  10316. *
  10317. * @return results of bus communication function
  10318. * @retval 0 -> Success
  10319. * @retval -1 -> Error
  10320. *
  10321. *
  10322. */
  10323. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_any_motion_durn(
  10324. u8 v_any_motion_durn_u8)
  10325. {
  10326. /* variable used to return the status of communication result*/
  10327. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10328. u8 v_data_u8 = BMI160_INIT_VALUE;
  10329. /* check the p_bmi160 structure for NULL pointer assignment*/
  10330. if (p_bmi160 == BMI160_NULL) {
  10331. return E_BMI160_NULL_PTR;
  10332. } else {
  10333. /* write any motion duration*/
  10334. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  10335. (p_bmi160->dev_addr,
  10336. BMI160_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN__REG,
  10337. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10338. if (com_rslt == SUCCESS) {
  10339. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  10340. BMI160_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN,
  10341. v_any_motion_durn_u8);
  10342. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  10343. (p_bmi160->dev_addr,
  10344. BMI160_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN__REG,
  10345. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10346. /*Check for the power mode of Accel and
  10347. gyro not in normal mode */
  10348. if (bmi160_power_mode_status_u8_g !=
  10349. BMI160_NORMAL_MODE)
  10350. /*interface idle time delay */
  10351. p_bmi160->delay_msec(
  10352. BMI160_GEN_READ_WRITE_DELAY);
  10353. }
  10354. }
  10355. return com_rslt;
  10356. }
  10357. /*!
  10358. * @brief This API reads Slow/no-motion
  10359. * interrupt trigger delay duration from the register 0x5F bit 2 to 7
  10360. *
  10361. * @param v_slow_no_motion_u8 :The value of slow no motion duration
  10362. *
  10363. *
  10364. *
  10365. * @return results of bus communication function
  10366. * @retval 0 -> Success
  10367. * @retval -1 -> Error
  10368. *
  10369. * @note
  10370. * @note v_slow_no_motion_u8(5:4)=0b00 ->
  10371. * [v_slow_no_motion_u8(3:0) + 1] * 1.28s (1.28s-20.48s)
  10372. * @note v_slow_no_motion_u8(5:4)=1 ->
  10373. * [v_slow_no_motion_u8(3:0)+5] * 5.12s (25.6s-102.4s)
  10374. * @note v_slow_no_motion_u8(5)='1' ->
  10375. * [(v_slow_no_motion_u8:0)+11] * 10.24s (112.64s-430.08s);
  10376. *
  10377. */
  10378. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_slow_no_motion_durn(
  10379. u8 *v_slow_no_motion_u8)
  10380. {
  10381. /* variable used to return the status of communication result*/
  10382. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10383. u8 v_data_u8 = BMI160_INIT_VALUE;
  10384. /* check the p_bmi160 structure for NULL pointer assignment*/
  10385. if (p_bmi160 == BMI160_NULL) {
  10386. return E_BMI160_NULL_PTR;
  10387. } else {
  10388. /* read slow no motion duration*/
  10389. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  10390. (p_bmi160->dev_addr,
  10391. BMI160_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN__REG,
  10392. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10393. *v_slow_no_motion_u8 = BMI160_GET_BITSLICE
  10394. (v_data_u8,
  10395. BMI160_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN);
  10396. }
  10397. return com_rslt;
  10398. }
  10399. /*!
  10400. * @brief This API writes Slow/no-motion
  10401. * interrupt trigger delay duration from the register 0x5F bit 2 to 7
  10402. *
  10403. * @param v_slow_no_motion_u8 :The value of slow no motion duration
  10404. *
  10405. *
  10406. *
  10407. * @return results of bus communication function
  10408. * @retval 0 -> Success
  10409. * @retval -1 -> Error
  10410. *
  10411. * @note
  10412. * @note v_slow_no_motion_u8(5:4)=0b00 ->
  10413. * [v_slow_no_motion_u8(3:0) + 1] * 1.28s (1.28s-20.48s)
  10414. * @note v_slow_no_motion_u8(5:4)=1 ->
  10415. * [v_slow_no_motion_u8(3:0)+5] * 5.12s (25.6s-102.4s)
  10416. * @note v_slow_no_motion_u8(5)='1' ->
  10417. * [(v_slow_no_motion_u8:0)+11] * 10.24s (112.64s-430.08s);
  10418. *
  10419. */
  10420. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_slow_no_motion_durn(
  10421. u8 v_slow_no_motion_u8)
  10422. {
  10423. /* variable used to return the status of communication result*/
  10424. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10425. u8 v_data_u8 = BMI160_INIT_VALUE;
  10426. /* check the p_bmi160 structure for NULL pointer assignment*/
  10427. if (p_bmi160 == BMI160_NULL) {
  10428. return E_BMI160_NULL_PTR;
  10429. } else {
  10430. /* write slow no motion duration*/
  10431. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  10432. (p_bmi160->dev_addr,
  10433. BMI160_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN__REG,
  10434. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10435. if (com_rslt == SUCCESS) {
  10436. v_data_u8 = BMI160_SET_BITSLICE
  10437. (v_data_u8,
  10438. BMI160_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN,
  10439. v_slow_no_motion_u8);
  10440. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  10441. (p_bmi160->dev_addr,
  10442. BMI160_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN__REG,
  10443. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10444. /*Check for the power mode of Accel and
  10445. gyro not in normal mode */
  10446. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  10447. /*interface idle time delay */
  10448. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  10449. }
  10450. }
  10451. return com_rslt;
  10452. }
  10453. /*!
  10454. * @brief This API is used to read threshold
  10455. * definition for the any-motion interrupt
  10456. * from the register 0x60 bit 0 to 7
  10457. *
  10458. *
  10459. * @param v_any_motion_thres_u8 : The value of any motion threshold
  10460. *
  10461. * @note any motion threshold changes according to Accel g range
  10462. * Accel g range can be set by the function "bmi160_set_accel_range"
  10463. * accel_range | any motion threshold
  10464. * ----------------|---------------------
  10465. * 2g | v_any_motion_thres_u8*3.91 mg
  10466. * 4g | v_any_motion_thres_u8*7.81 mg
  10467. * 8g | v_any_motion_thres_u8*15.63 mg
  10468. * 16g | v_any_motion_thres_u8*31.25 mg
  10469. * @note when v_any_motion_thres_u8 = 0
  10470. * accel_range | any motion threshold
  10471. * ----------------|---------------------
  10472. * 2g | 1.95 mg
  10473. * 4g | 3.91 mg
  10474. * 8g | 7.81 mg
  10475. * 16g | 15.63 mg
  10476. *
  10477. *
  10478. * @return results of bus communication function
  10479. * @retval 0 -> Success
  10480. * @retval -1 -> Error
  10481. *
  10482. *
  10483. */
  10484. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_any_motion_thres(
  10485. u8 *v_any_motion_thres_u8)
  10486. {
  10487. /* variable used to return the status of communication result*/
  10488. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10489. u8 v_data_u8 = BMI160_INIT_VALUE;
  10490. /* check the p_bmi160 structure for NULL pointer assignment*/
  10491. if (p_bmi160 == BMI160_NULL) {
  10492. return E_BMI160_NULL_PTR;
  10493. } else {
  10494. /* read any motion threshold*/
  10495. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  10496. (p_bmi160->dev_addr,
  10497. BMI160_USER_INTR_MOTION_1_INTR_ANY_MOTION_THRES__REG,
  10498. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10499. *v_any_motion_thres_u8 =
  10500. BMI160_GET_BITSLICE(v_data_u8,
  10501. BMI160_USER_INTR_MOTION_1_INTR_ANY_MOTION_THRES);
  10502. }
  10503. return com_rslt;
  10504. }
  10505. /*!
  10506. * @brief This API is used to write threshold
  10507. * definition for any-motion interrupt
  10508. * from the register 0x60 bit 0 to 7
  10509. *
  10510. *
  10511. * @param v_any_motion_thres_u8 : The value of any motion threshold
  10512. *
  10513. * @note any motion threshold changes according to Accel g range
  10514. * Accel g range can be set by the function "bmi160_set_accel_range"
  10515. * accel_range | any motion threshold
  10516. * ----------------|---------------------
  10517. * 2g | v_any_motion_thres_u8*3.91 mg
  10518. * 4g | v_any_motion_thres_u8*7.81 mg
  10519. * 8g | v_any_motion_thres_u8*15.63 mg
  10520. * 16g | v_any_motion_thres_u8*31.25 mg
  10521. * @note when v_any_motion_thres_u8 = 0
  10522. * accel_range | any motion threshold
  10523. * ----------------|---------------------
  10524. * 2g | 1.95 mg
  10525. * 4g | 3.91 mg
  10526. * 8g | 7.81 mg
  10527. * 16g | 15.63 mg
  10528. *
  10529. *
  10530. * @return results of bus communication function
  10531. * @retval 0 -> Success
  10532. * @retval -1 -> Error
  10533. *
  10534. *
  10535. */
  10536. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_any_motion_thres(
  10537. u8 v_any_motion_thres_u8)
  10538. {
  10539. /* variable used to return the status of communication result*/
  10540. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10541. /* check the p_bmi160 structure for NULL pointer assignment*/
  10542. if (p_bmi160 == BMI160_NULL) {
  10543. return E_BMI160_NULL_PTR;
  10544. } else {
  10545. /* write any motion threshold*/
  10546. com_rslt = p_bmi160->BMI160_BUS_WRITE_FUNC
  10547. (p_bmi160->dev_addr,
  10548. BMI160_USER_INTR_MOTION_1_INTR_ANY_MOTION_THRES__REG,
  10549. &v_any_motion_thres_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10550. /*Check for the power mode of Accel and
  10551. gyro not in normal mode */
  10552. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  10553. /*interface idle time delay */
  10554. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  10555. }
  10556. return com_rslt;
  10557. }
  10558. /*!
  10559. * @brief This API is used to read threshold
  10560. * for the slow/no-motion interrupt
  10561. * from the register 0x61 bit 0 to 7
  10562. *
  10563. *
  10564. *
  10565. *
  10566. * @param v_slow_no_motion_thres_u8 : The value of slow no motion threshold
  10567. * @note slow no motion threshold changes according to Accel g range
  10568. * Accel g range can be set by the function "bmi160_set_accel_range"
  10569. * accel_range | slow no motion threshold
  10570. * ----------------|---------------------
  10571. * 2g | v_slow_no_motion_thres_u8*3.91 mg
  10572. * 4g | v_slow_no_motion_thres_u8*7.81 mg
  10573. * 8g | v_slow_no_motion_thres_u8*15.63 mg
  10574. * 16g | v_slow_no_motion_thres_u8*31.25 mg
  10575. * @note when v_slow_no_motion_thres_u8 = 0
  10576. * accel_range | slow no motion threshold
  10577. * ----------------|---------------------
  10578. * 2g | 1.95 mg
  10579. * 4g | 3.91 mg
  10580. * 8g | 7.81 mg
  10581. * 16g | 15.63 mg
  10582. *
  10583. *
  10584. * @return results of bus communication function
  10585. * @retval 0 -> Success
  10586. * @retval -1 -> Error
  10587. *
  10588. *
  10589. */
  10590. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_slow_no_motion_thres(
  10591. u8 *v_slow_no_motion_thres_u8)
  10592. {
  10593. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10594. u8 v_data_u8 = BMI160_INIT_VALUE;
  10595. /* check the p_bmi160 structure for NULL pointer assignment*/
  10596. if (p_bmi160 == BMI160_NULL) {
  10597. return E_BMI160_NULL_PTR;
  10598. } else {
  10599. /* read slow no motion threshold*/
  10600. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  10601. (p_bmi160->dev_addr,
  10602. BMI160_USER_INTR_MOTION_2_INTR_SLOW_NO_MOTION_THRES__REG,
  10603. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10604. *v_slow_no_motion_thres_u8 =
  10605. BMI160_GET_BITSLICE(v_data_u8,
  10606. BMI160_USER_INTR_MOTION_2_INTR_SLOW_NO_MOTION_THRES);
  10607. }
  10608. return com_rslt;
  10609. }
  10610. /*!
  10611. * @brief This API is used to write threshold
  10612. * for the slow/no-motion interrupt
  10613. * in the register 0x61 bit 0 to 7
  10614. *
  10615. *
  10616. *
  10617. *
  10618. * @param v_slow_no_motion_thres_u8 : The value of slow no motion threshold
  10619. * @note slow no motion threshold changes according to Accel g range
  10620. * Accel g range can be set by the function "bmi160_set_accel_range"
  10621. * accel_range | slow no motion threshold
  10622. * ----------------|---------------------
  10623. * 2g | v_slow_no_motion_thres_u8*3.91 mg
  10624. * 4g | v_slow_no_motion_thres_u8*7.81 mg
  10625. * 8g | v_slow_no_motion_thres_u8*15.63 mg
  10626. * 16g | v_slow_no_motion_thres_u8*31.25 mg
  10627. * @note when v_slow_no_motion_thres_u8 = 0
  10628. * accel_range | slow no motion threshold
  10629. * ----------------|---------------------
  10630. * 2g | 1.95 mg
  10631. * 4g | 3.91 mg
  10632. * 8g | 7.81 mg
  10633. * 16g | 15.63 mg
  10634. *
  10635. *
  10636. * @return results of bus communication function
  10637. * @retval 0 -> Success
  10638. * @retval -1 -> Error
  10639. *
  10640. *
  10641. */
  10642. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_slow_no_motion_thres(
  10643. u8 v_slow_no_motion_thres_u8)
  10644. {
  10645. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10646. /* check the p_bmi160 structure for NULL pointer assignment*/
  10647. if (p_bmi160 == BMI160_NULL) {
  10648. return E_BMI160_NULL_PTR;
  10649. } else {
  10650. /* write slow no motion threshold*/
  10651. com_rslt = p_bmi160->BMI160_BUS_WRITE_FUNC(
  10652. p_bmi160->dev_addr,
  10653. BMI160_USER_INTR_MOTION_2_INTR_SLOW_NO_MOTION_THRES__REG,
  10654. &v_slow_no_motion_thres_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10655. /*Check for the power mode of Accel and
  10656. gyro not in normal mode */
  10657. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  10658. /*interface idle time delay */
  10659. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  10660. }
  10661. return com_rslt;
  10662. }
  10663. /*!
  10664. * @brief This API is used to read
  10665. * the slow/no-motion selection from the register 0x62 bit 0
  10666. *
  10667. *
  10668. *
  10669. *
  10670. * @param v_intr_slow_no_motion_select_u8 :
  10671. * The value of slow/no-motion select
  10672. * value | Behaviour
  10673. * ----------|-------------------
  10674. * 0x00 | SLOW_MOTION
  10675. * 0x01 | NO_MOTION
  10676. *
  10677. *
  10678. * @return results of bus communication function
  10679. * @retval 0 -> Success
  10680. * @retval -1 -> Error
  10681. *
  10682. *
  10683. */
  10684. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_slow_no_motion_select(
  10685. u8 *v_intr_slow_no_motion_select_u8)
  10686. {
  10687. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10688. u8 v_data_u8 = BMI160_INIT_VALUE;
  10689. /* check the p_bmi160 structure for NULL pointer assignment*/
  10690. if (p_bmi160 == BMI160_NULL) {
  10691. return E_BMI160_NULL_PTR;
  10692. } else {
  10693. /* read slow no motion select*/
  10694. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  10695. p_bmi160->dev_addr,
  10696. BMI160_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT__REG,
  10697. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10698. *v_intr_slow_no_motion_select_u8 =
  10699. BMI160_GET_BITSLICE(v_data_u8,
  10700. BMI160_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT);
  10701. }
  10702. return com_rslt;
  10703. }
  10704. /*!
  10705. * @brief This API is used to write
  10706. * the slow/no-motion selection from the register 0x62 bit 0
  10707. *
  10708. *
  10709. *
  10710. *
  10711. * @param v_intr_slow_no_motion_select_u8 :
  10712. * The value of slow/no-motion select
  10713. * value | Behaviour
  10714. * ----------|-------------------
  10715. * 0x00 | SLOW_MOTION
  10716. * 0x01 | NO_MOTION
  10717. *
  10718. *
  10719. * @return results of bus communication function
  10720. * @retval 0 -> Success
  10721. * @retval -1 -> Error
  10722. *
  10723. *
  10724. */
  10725. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_slow_no_motion_select(
  10726. u8 v_intr_slow_no_motion_select_u8)
  10727. {
  10728. /* variable used to return the status of communication result*/
  10729. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10730. u8 v_data_u8 = BMI160_INIT_VALUE;
  10731. /* check the p_bmi160 structure for NULL pointer assignment*/
  10732. if (p_bmi160 == BMI160_NULL) {
  10733. return E_BMI160_NULL_PTR;
  10734. } else {
  10735. if (v_intr_slow_no_motion_select_u8 <= BMI160_MAX_VALUE_NO_MOTION) {
  10736. /* write slow no motion select*/
  10737. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  10738. (p_bmi160->dev_addr,
  10739. BMI160_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT__REG,
  10740. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10741. if (com_rslt == SUCCESS) {
  10742. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  10743. BMI160_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT,
  10744. v_intr_slow_no_motion_select_u8);
  10745. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  10746. (p_bmi160->dev_addr,
  10747. BMI160_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT__REG,
  10748. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10749. /*Check for the power mode of Accel and
  10750. gyro not in normal mode */
  10751. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  10752. /*interface idle time delay */
  10753. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  10754. }
  10755. } else {
  10756. com_rslt = E_BMI160_OUT_OF_RANGE;
  10757. }
  10758. }
  10759. return com_rslt;
  10760. }
  10761. /*!
  10762. * @brief This API is used to select
  10763. * the significant or any motion interrupt from the register 0x62 bit 1
  10764. *
  10765. *
  10766. *
  10767. *
  10768. * @param v_intr_significant_motion_select_u8 :
  10769. * the value of significant or any motion interrupt selection
  10770. * value | Behaviour
  10771. * ----------|-------------------
  10772. * 0x00 | ANY_MOTION
  10773. * 0x01 | SIGNIFICANT_MOTION
  10774. *
  10775. *
  10776. * @return results of bus communication function
  10777. * @retval 0 -> Success
  10778. * @retval -1 -> Error
  10779. *
  10780. *
  10781. */
  10782. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_significant_motion_select(
  10783. u8 *v_intr_significant_motion_select_u8)
  10784. {
  10785. /* variable used to return the status of communication result*/
  10786. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10787. u8 v_data_u8 = BMI160_INIT_VALUE;
  10788. /* check the p_bmi160 structure for NULL pointer assignment*/
  10789. if (p_bmi160 == BMI160_NULL) {
  10790. return E_BMI160_NULL_PTR;
  10791. } else {
  10792. /* read the significant or any motion interrupt*/
  10793. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  10794. p_bmi160->dev_addr,
  10795. BMI160_USER_INTR_SIGNIFICATION_MOTION_SELECT__REG,
  10796. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10797. *v_intr_significant_motion_select_u8 =
  10798. BMI160_GET_BITSLICE(v_data_u8,
  10799. BMI160_USER_INTR_SIGNIFICATION_MOTION_SELECT);
  10800. }
  10801. return com_rslt;
  10802. }
  10803. /*!
  10804. * @brief This API is used to write, select
  10805. * the significant or any motion interrupt from the register 0x62 bit 1
  10806. *
  10807. *
  10808. *
  10809. *
  10810. * @param v_intr_significant_motion_select_u8 :
  10811. * the value of significant or any motion interrupt selection
  10812. * value | Behaviour
  10813. * ----------|-------------------
  10814. * 0x00 | ANY_MOTION
  10815. * 0x01 | SIGNIFICANT_MOTION
  10816. *
  10817. *
  10818. * @return results of bus communication function
  10819. * @retval 0 -> Success
  10820. * @retval -1 -> Error
  10821. *
  10822. *
  10823. */
  10824. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_significant_motion_select(
  10825. u8 v_intr_significant_motion_select_u8)
  10826. {
  10827. /* variable used to return the status of communication result*/
  10828. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10829. u8 v_data_u8 = BMI160_INIT_VALUE;
  10830. /* check the p_bmi160 structure for NULL pointer assignment*/
  10831. if (p_bmi160 == BMI160_NULL) {
  10832. return E_BMI160_NULL_PTR;
  10833. } else {
  10834. if (v_intr_significant_motion_select_u8 <=
  10835. BMI160_MAX_VALUE_SIGNIFICANT_MOTION) {
  10836. /* write the significant or any motion interrupt*/
  10837. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  10838. (p_bmi160->dev_addr,
  10839. BMI160_USER_INTR_SIGNIFICATION_MOTION_SELECT__REG,
  10840. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10841. if (com_rslt == SUCCESS) {
  10842. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  10843. BMI160_USER_INTR_SIGNIFICATION_MOTION_SELECT,
  10844. v_intr_significant_motion_select_u8);
  10845. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  10846. (p_bmi160->dev_addr,
  10847. BMI160_USER_INTR_SIGNIFICATION_MOTION_SELECT__REG,
  10848. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10849. /*Accel and Gyro power mode check*/
  10850. if (bmi160_power_mode_status_u8_g !=
  10851. BMI160_NORMAL_MODE)
  10852. /*interface idle time delay */
  10853. p_bmi160->delay_msec(
  10854. BMI160_GEN_READ_WRITE_DELAY);
  10855. }
  10856. } else {
  10857. com_rslt = E_BMI160_OUT_OF_RANGE;
  10858. }
  10859. }
  10860. return com_rslt;
  10861. }
  10862. /*!
  10863. * @brief This API is used to unmap the signification motion
  10864. * interrupt
  10865. *
  10866. *
  10867. * @param v_significant_u8 : The value of interrupt selection
  10868. *
  10869. * BMI160_MAP_INTR1 0
  10870. * BMI160_MAP_INTR2 1
  10871. *
  10872. * \return results of communication routine
  10873. *
  10874. *
  10875. */
  10876. BMI160_RETURN_FUNCTION_TYPE bmi160_unmap_significant_motion_intr(
  10877. u8 v_significant_u8)
  10878. {
  10879. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10880. u8 v_any_motion_intr1_stat_u8 = V_ANY_MOTION_INTR_STAT;
  10881. u8 v_any_motion_intr2_stat_u8 = V_ANY_MOTION_INTR_STAT;
  10882. u8 v_any_motion_axis_stat_u8 = V_ANY_MOTION_AXIS_STAT;
  10883. u8 v_data_u8 = BMI160_INIT_VALUE;
  10884. switch (v_significant_u8) {
  10885. case BMI160_MAP_INTR1:
  10886. /* interrupt */
  10887. com_rslt = bmi160_read_reg(
  10888. BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG,
  10889. &v_data_u8, BMI160_ASSIGN_DATA);
  10890. v_data_u8 &= ~(v_any_motion_intr1_stat_u8);
  10891. /* map the signification interrupt
  10892. to any-motion interrupt1*/
  10893. com_rslt += bmi160_write_reg(
  10894. BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG,
  10895. &v_data_u8, BMI160_ASSIGN_DATA);
  10896. p_bmi160->delay_msec(BMI160_ASSIGN_DATA);
  10897. /* axis*/
  10898. com_rslt = bmi160_read_reg(
  10899. BMI160_USER_INTR_ENABLE_0_ADDR,
  10900. &v_data_u8, BMI160_ASSIGN_DATA);
  10901. v_data_u8 &= ~(v_any_motion_axis_stat_u8);
  10902. com_rslt += bmi160_write_reg(
  10903. BMI160_USER_INTR_ENABLE_0_ADDR,
  10904. &v_data_u8, BMI160_ASSIGN_DATA);
  10905. p_bmi160->delay_msec(BMI160_ASSIGN_DATA);
  10906. break;
  10907. case BMI160_MAP_INTR2:
  10908. /* map the signification interrupt
  10909. to any-motion interrupt2*/
  10910. com_rslt = bmi160_read_reg(
  10911. BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG,
  10912. &v_data_u8, BMI160_ASSIGN_DATA);
  10913. v_data_u8 &= ~(v_any_motion_intr2_stat_u8);
  10914. com_rslt += bmi160_write_reg(
  10915. BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG,
  10916. &v_data_u8, BMI160_ASSIGN_DATA);
  10917. p_bmi160->delay_msec(BMI160_ASSIGN_DATA);
  10918. /* axis*/
  10919. com_rslt = bmi160_read_reg(BMI160_USER_INTR_ENABLE_0_ADDR,
  10920. &v_data_u8, BMI160_ASSIGN_DATA);
  10921. v_data_u8 &= ~(v_any_motion_axis_stat_u8);
  10922. com_rslt += bmi160_write_reg(
  10923. BMI160_USER_INTR_ENABLE_0_ADDR,
  10924. &v_data_u8, BMI160_ASSIGN_DATA);
  10925. p_bmi160->delay_msec(BMI160_ASSIGN_DATA);
  10926. break;
  10927. default:
  10928. com_rslt = E_BMI160_OUT_OF_RANGE;
  10929. break;
  10930. }
  10931. return com_rslt;
  10932. }
  10933. /*!
  10934. * @brief This API is used to read
  10935. * the significant skip time from the register 0x62 bit 2 and 3
  10936. *
  10937. *
  10938. *
  10939. *
  10940. * @param v_int_sig_mot_skip_u8 : the value of significant skip time
  10941. * value | Behaviour
  10942. * ----------|-------------------
  10943. * 0x00 | skip time 1.5 seconds
  10944. * 0x01 | skip time 3 seconds
  10945. * 0x02 | skip time 6 seconds
  10946. * 0x03 | skip time 12 seconds
  10947. *
  10948. *
  10949. * @return results of bus communication function
  10950. * @retval 0 -> Success
  10951. * @retval -1 -> Error
  10952. *
  10953. *
  10954. */
  10955. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_significant_motion_skip(
  10956. u8 *v_int_sig_mot_skip_u8)
  10957. {
  10958. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10959. u8 v_data_u8 = BMI160_INIT_VALUE;
  10960. /* check the p_bmi160 structure for NULL pointer assignment*/
  10961. if (p_bmi160 == BMI160_NULL) {
  10962. return E_BMI160_NULL_PTR;
  10963. } else {
  10964. /* read significant skip time*/
  10965. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  10966. p_bmi160->dev_addr,
  10967. BMI160_USER_INTR_SIGNIFICANT_MOTION_SKIP__REG,
  10968. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  10969. *v_int_sig_mot_skip_u8 =
  10970. BMI160_GET_BITSLICE(v_data_u8,
  10971. BMI160_USER_INTR_SIGNIFICANT_MOTION_SKIP);
  10972. }
  10973. return com_rslt;
  10974. }
  10975. /*!
  10976. * @brief This API is used to write
  10977. * the significant skip time in the register 0x62 bit 2 and 3
  10978. *
  10979. *
  10980. *
  10981. *
  10982. * @param v_int_sig_mot_skip_u8 : the value of significant skip time
  10983. * value | Behaviour
  10984. * ----------|-------------------
  10985. * 0x00 | skip time 1.5 seconds
  10986. * 0x01 | skip time 3 seconds
  10987. * 0x02 | skip time 6 seconds
  10988. * 0x03 | skip time 12 seconds
  10989. *
  10990. *
  10991. * @return results of bus communication function
  10992. * @retval 0 -> Success
  10993. * @retval -1 -> Error
  10994. *
  10995. *
  10996. */
  10997. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_significant_motion_skip(
  10998. u8 v_int_sig_mot_skip_u8)
  10999. {
  11000. /* variable used to return the status of communication result*/
  11001. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11002. u8 v_data_u8 = BMI160_INIT_VALUE;
  11003. /* check the p_bmi160 structure for NULL pointer assignment*/
  11004. if (p_bmi160 == BMI160_NULL) {
  11005. return E_BMI160_NULL_PTR;
  11006. } else {
  11007. if (v_int_sig_mot_skip_u8 <= BMI160_MAX_UNDER_SIG_MOTION) {
  11008. /* write significant skip time*/
  11009. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11010. (p_bmi160->dev_addr,
  11011. BMI160_USER_INTR_SIGNIFICANT_MOTION_SKIP__REG,
  11012. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11013. if (com_rslt == SUCCESS) {
  11014. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  11015. BMI160_USER_INTR_SIGNIFICANT_MOTION_SKIP,
  11016. v_int_sig_mot_skip_u8);
  11017. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  11018. (p_bmi160->dev_addr,
  11019. BMI160_USER_INTR_SIGNIFICANT_MOTION_SKIP__REG,
  11020. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11021. /*Accel and Gyro power mode check*/
  11022. if (bmi160_power_mode_status_u8_g !=
  11023. BMI160_NORMAL_MODE)
  11024. /*interface idle time delay */
  11025. p_bmi160->delay_msec(
  11026. BMI160_GEN_READ_WRITE_DELAY);
  11027. }
  11028. } else {
  11029. com_rslt = E_BMI160_OUT_OF_RANGE;
  11030. }
  11031. }
  11032. return com_rslt;
  11033. }
  11034. /*!
  11035. * @brief This API is used to read
  11036. * the significant proof time from the register 0x62 bit 4 and 5
  11037. *
  11038. *
  11039. *
  11040. *
  11041. * @param v_significant_motion_proof_u8 :
  11042. * the value of significant proof time
  11043. * value | Behaviour
  11044. * ----------|-------------------
  11045. * 0x00 | proof time 0.25 seconds
  11046. * 0x01 | proof time 0.5 seconds
  11047. * 0x02 | proof time 1 seconds
  11048. * 0x03 | proof time 2 seconds
  11049. *
  11050. *
  11051. * @return results of bus communication function
  11052. * @retval 0 -> Success
  11053. * @retval -1 -> Error
  11054. *
  11055. *
  11056. */
  11057. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_significant_motion_proof(
  11058. u8 *v_significant_motion_proof_u8)
  11059. {
  11060. /* variable used to return the status of communication result*/
  11061. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11062. u8 v_data_u8 = BMI160_INIT_VALUE;
  11063. /* check the p_bmi160 structure for NULL pointer assignment*/
  11064. if (p_bmi160 == BMI160_NULL) {
  11065. return E_BMI160_NULL_PTR;
  11066. } else {
  11067. /* read significant proof time */
  11068. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  11069. p_bmi160->dev_addr,
  11070. BMI160_USER_INTR_SIGNIFICANT_MOTION_PROOF__REG,
  11071. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11072. *v_significant_motion_proof_u8 =
  11073. BMI160_GET_BITSLICE(v_data_u8,
  11074. BMI160_USER_INTR_SIGNIFICANT_MOTION_PROOF);
  11075. }
  11076. return com_rslt;
  11077. }
  11078. /*!
  11079. * @brief This API is used to write
  11080. * the significant proof time in the register 0x62 bit 4 and 5
  11081. *
  11082. *
  11083. *
  11084. *
  11085. * @param v_significant_motion_proof_u8 :
  11086. * the value of significant proof time
  11087. * value | Behaviour
  11088. * ----------|-------------------
  11089. * 0x00 | proof time 0.25 seconds
  11090. * 0x01 | proof time 0.5 seconds
  11091. * 0x02 | proof time 1 seconds
  11092. * 0x03 | proof time 2 seconds
  11093. *
  11094. *
  11095. * @return results of bus communication function
  11096. * @retval 0 -> Success
  11097. * @retval -1 -> Error
  11098. *
  11099. *
  11100. */
  11101. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_significant_motion_proof(
  11102. u8 v_significant_motion_proof_u8)
  11103. {
  11104. /* variable used to return the status of communication result*/
  11105. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11106. u8 v_data_u8 = BMI160_INIT_VALUE;
  11107. /* check the p_bmi160 structure for NULL pointer assignment*/
  11108. if (p_bmi160 == BMI160_NULL) {
  11109. return E_BMI160_NULL_PTR;
  11110. } else {
  11111. if (v_significant_motion_proof_u8
  11112. <= BMI160_MAX_UNDER_SIG_MOTION) {
  11113. /* write significant proof time */
  11114. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11115. (p_bmi160->dev_addr,
  11116. BMI160_USER_INTR_SIGNIFICANT_MOTION_PROOF__REG,
  11117. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11118. if (com_rslt == SUCCESS) {
  11119. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  11120. BMI160_USER_INTR_SIGNIFICANT_MOTION_PROOF,
  11121. v_significant_motion_proof_u8);
  11122. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  11123. (p_bmi160->dev_addr,
  11124. BMI160_USER_INTR_SIGNIFICANT_MOTION_PROOF__REG,
  11125. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11126. /*Accel and Gyro power mode check*/
  11127. if (bmi160_power_mode_status_u8_g !=
  11128. BMI160_NORMAL_MODE)
  11129. /*interface idle time delay */
  11130. p_bmi160->delay_msec(
  11131. BMI160_GEN_READ_WRITE_DELAY);
  11132. }
  11133. } else {
  11134. com_rslt = E_BMI160_OUT_OF_RANGE;
  11135. }
  11136. }
  11137. return com_rslt;
  11138. }
  11139. /*!
  11140. * @brief This API is used to get the tap duration
  11141. * from the register 0x63 bit 0 to 2
  11142. *
  11143. *
  11144. *
  11145. * @param v_tap_durn_u8 : The value of tap duration
  11146. * value | Behaviour
  11147. * ----------|-------------------
  11148. * 0x00 | BMI160_TAP_DURN_50MS
  11149. * 0x01 | BMI160_TAP_DURN_100MS
  11150. * 0x02 | BMI160_TAP_DURN_150MS
  11151. * 0x03 | BMI160_TAP_DURN_200MS
  11152. * 0x04 | BMI160_TAP_DURN_250MS
  11153. * 0x05 | BMI160_TAP_DURN_375MS
  11154. * 0x06 | BMI160_TAP_DURN_500MS
  11155. * 0x07 | BMI160_TAP_DURN_700MS
  11156. *
  11157. *
  11158. *
  11159. * @return results of bus communication function
  11160. * @retval 0 -> Success
  11161. * @retval -1 -> Error
  11162. *
  11163. *
  11164. */
  11165. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_tap_durn(
  11166. u8 *v_tap_durn_u8)
  11167. {
  11168. /* variable used to return the status of communication result*/
  11169. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11170. u8 v_data_u8 = BMI160_INIT_VALUE;
  11171. /* check the p_bmi160 structure for NULL pointer assignment*/
  11172. if (p_bmi160 == BMI160_NULL) {
  11173. return E_BMI160_NULL_PTR;
  11174. } else {
  11175. /* read tap duration*/
  11176. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11177. (p_bmi160->dev_addr,
  11178. BMI160_USER_INTR_TAP_0_INTR_TAP_DURN__REG,
  11179. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11180. *v_tap_durn_u8 = BMI160_GET_BITSLICE(
  11181. v_data_u8,
  11182. BMI160_USER_INTR_TAP_0_INTR_TAP_DURN);
  11183. }
  11184. return com_rslt;
  11185. }
  11186. /*!
  11187. * @brief This API is used to write the tap duration
  11188. * in the register 0x63 bit 0 to 2
  11189. *
  11190. *
  11191. *
  11192. * @param v_tap_durn_u8 : The value of tap duration
  11193. * value | Behaviour
  11194. * ----------|-------------------
  11195. * 0x00 | BMI160_TAP_DURN_50MS
  11196. * 0x01 | BMI160_TAP_DURN_100MS
  11197. * 0x02 | BMI160_TAP_DURN_150MS
  11198. * 0x03 | BMI160_TAP_DURN_200MS
  11199. * 0x04 | BMI160_TAP_DURN_250MS
  11200. * 0x05 | BMI160_TAP_DURN_375MS
  11201. * 0x06 | BMI160_TAP_DURN_500MS
  11202. * 0x07 | BMI160_TAP_DURN_700MS
  11203. *
  11204. *
  11205. *
  11206. * @return results of bus communication function
  11207. * @retval 0 -> Success
  11208. * @retval -1 -> Error
  11209. *
  11210. *
  11211. */
  11212. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_tap_durn(
  11213. u8 v_tap_durn_u8)
  11214. {
  11215. u8 v_data_u8 = BMI160_INIT_VALUE;
  11216. /* variable used to return the status of communication result*/
  11217. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11218. u8 v_data_tap_durn_u8 = BMI160_INIT_VALUE;
  11219. /* check the p_bmi160 structure for NULL pointer assignment*/
  11220. if (p_bmi160 == BMI160_NULL) {
  11221. return E_BMI160_NULL_PTR;
  11222. } else {
  11223. if (v_tap_durn_u8 <= BMI160_MAX_TAP_TURN) {
  11224. switch (v_tap_durn_u8) {
  11225. case BMI160_TAP_DURN_50MS:
  11226. v_data_tap_durn_u8 = BMI160_TAP_DURN_50MS;
  11227. break;
  11228. case BMI160_TAP_DURN_100MS:
  11229. v_data_tap_durn_u8 = BMI160_TAP_DURN_100MS;
  11230. break;
  11231. case BMI160_TAP_DURN_150MS:
  11232. v_data_tap_durn_u8 = BMI160_TAP_DURN_150MS;
  11233. break;
  11234. case BMI160_TAP_DURN_200MS:
  11235. v_data_tap_durn_u8 = BMI160_TAP_DURN_200MS;
  11236. break;
  11237. case BMI160_TAP_DURN_250MS:
  11238. v_data_tap_durn_u8 = BMI160_TAP_DURN_250MS;
  11239. break;
  11240. case BMI160_TAP_DURN_375MS:
  11241. v_data_tap_durn_u8 = BMI160_TAP_DURN_375MS;
  11242. break;
  11243. case BMI160_TAP_DURN_500MS:
  11244. v_data_tap_durn_u8 = BMI160_TAP_DURN_500MS;
  11245. break;
  11246. case BMI160_TAP_DURN_700MS:
  11247. v_data_tap_durn_u8 = BMI160_TAP_DURN_700MS;
  11248. break;
  11249. default:
  11250. break;
  11251. }
  11252. /* write tap duration*/
  11253. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  11254. p_bmi160->dev_addr,
  11255. BMI160_USER_INTR_TAP_0_INTR_TAP_DURN__REG,
  11256. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11257. if (com_rslt == SUCCESS) {
  11258. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  11259. BMI160_USER_INTR_TAP_0_INTR_TAP_DURN,
  11260. v_data_tap_durn_u8);
  11261. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  11262. (p_bmi160->dev_addr,
  11263. BMI160_USER_INTR_TAP_0_INTR_TAP_DURN__REG,
  11264. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11265. /*Accel and Gyro power mode check*/
  11266. if (bmi160_power_mode_status_u8_g !=
  11267. BMI160_NORMAL_MODE)
  11268. /*interface idle time delay */
  11269. p_bmi160->delay_msec(
  11270. BMI160_GEN_READ_WRITE_DELAY);
  11271. }
  11272. } else {
  11273. com_rslt = E_BMI160_OUT_OF_RANGE;
  11274. }
  11275. }
  11276. return com_rslt;
  11277. }
  11278. /*!
  11279. * @brief This API reads the
  11280. * tap shock duration from the register 0x63 bit 2
  11281. *
  11282. * @param v_tap_shock_u8 :The value of tap shock
  11283. * value | Behaviour
  11284. * ----------|-------------------
  11285. * 0x00 | BMI160_TAP_SHOCK_50MS
  11286. * 0x01 | BMI160_TAP_SHOCK_75MS
  11287. *
  11288. *
  11289. * @return results of bus communication function
  11290. * @retval 0 -> Success
  11291. * @retval -1 -> Error
  11292. *
  11293. *
  11294. */
  11295. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_tap_shock(
  11296. u8 *v_tap_shock_u8)
  11297. {
  11298. /* variable used to return the status of communication result*/
  11299. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11300. u8 v_data_u8 = BMI160_INIT_VALUE;
  11301. /* check the p_bmi160 structure for NULL pointer assignment*/
  11302. if (p_bmi160 == BMI160_NULL) {
  11303. return E_BMI160_NULL_PTR;
  11304. } else {
  11305. /* read tap shock duration*/
  11306. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  11307. p_bmi160->dev_addr,
  11308. BMI160_USER_INTR_TAP_0_INTR_TAP_SHOCK__REG,
  11309. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11310. *v_tap_shock_u8 = BMI160_GET_BITSLICE(v_data_u8,
  11311. BMI160_USER_INTR_TAP_0_INTR_TAP_SHOCK);
  11312. }
  11313. return com_rslt;
  11314. }
  11315. /*!
  11316. * @brief This API writes the
  11317. * tap shock duration from the register 0x63 bit 2
  11318. *
  11319. * @param v_tap_shock_u8 :The value of tap shock
  11320. * value | Behaviour
  11321. * ----------|-------------------
  11322. * 0x00 | BMI160_TAP_SHOCK_50MS
  11323. * 0x01 | BMI160_TAP_SHOCK_75MS
  11324. *
  11325. *
  11326. * @return results of bus communication function
  11327. * @retval 0 -> Success
  11328. * @retval -1 -> Error
  11329. *
  11330. *
  11331. */
  11332. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_tap_shock(u8 v_tap_shock_u8)
  11333. {
  11334. /* variable used to return the status of communication result*/
  11335. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11336. u8 v_data_u8 = BMI160_INIT_VALUE;
  11337. /* check the p_bmi160 structure for NULL pointer assignment*/
  11338. if (p_bmi160 == BMI160_NULL) {
  11339. return E_BMI160_NULL_PTR;
  11340. } else {
  11341. if (v_tap_shock_u8 <= BMI160_MAX_VALUE_TAP_SHOCK) {
  11342. /* write tap shock duration*/
  11343. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11344. (p_bmi160->dev_addr,
  11345. BMI160_USER_INTR_TAP_0_INTR_TAP_SHOCK__REG,
  11346. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11347. if (com_rslt == SUCCESS) {
  11348. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  11349. BMI160_USER_INTR_TAP_0_INTR_TAP_SHOCK,
  11350. v_tap_shock_u8);
  11351. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  11352. (p_bmi160->dev_addr,
  11353. BMI160_USER_INTR_TAP_0_INTR_TAP_SHOCK__REG,
  11354. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11355. /*Accel and Gyro power mode check*/
  11356. if (bmi160_power_mode_status_u8_g !=
  11357. BMI160_NORMAL_MODE)
  11358. /*interface idle time delay */
  11359. p_bmi160->delay_msec(
  11360. BMI160_GEN_READ_WRITE_DELAY);
  11361. }
  11362. } else {
  11363. com_rslt = E_BMI160_OUT_OF_RANGE;
  11364. }
  11365. }
  11366. return com_rslt;
  11367. }
  11368. /*!
  11369. * @brief This API reads
  11370. * tap quiet duration from the register 0x63 bit 7
  11371. *
  11372. *
  11373. * @param v_tap_quiet_u8 : The value of tap quiet
  11374. * value | Behaviour
  11375. * ----------|-------------------
  11376. * 0x00 | BMI160_TAP_QUIET_30MS
  11377. * 0x01 | BMI160_TAP_QUIET_20MS
  11378. *
  11379. *
  11380. * @return results of bus communication function
  11381. * @retval 0 -> Success
  11382. * @retval -1 -> Error
  11383. *
  11384. *
  11385. */
  11386. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_tap_quiet(
  11387. u8 *v_tap_quiet_u8)
  11388. {
  11389. /* variable used to return the status of communication result*/
  11390. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11391. u8 v_data_u8 = BMI160_INIT_VALUE;
  11392. /* check the p_bmi160 structure for NULL pointer assignment*/
  11393. if (p_bmi160 == BMI160_NULL) {
  11394. return E_BMI160_NULL_PTR;
  11395. } else {
  11396. /* read tap quiet duration*/
  11397. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  11398. p_bmi160->dev_addr,
  11399. BMI160_USER_INTR_TAP_0_INTR_TAP_QUIET__REG,
  11400. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11401. *v_tap_quiet_u8 = BMI160_GET_BITSLICE(
  11402. v_data_u8,
  11403. BMI160_USER_INTR_TAP_0_INTR_TAP_QUIET);
  11404. }
  11405. return com_rslt;
  11406. }
  11407. /*!
  11408. * @brief This API writes
  11409. * tap quiet duration in the register 0x63 bit 7
  11410. *
  11411. *
  11412. * @param v_tap_quiet_u8 : The value of tap quiet
  11413. * value | Behaviour
  11414. * ----------|-------------------
  11415. * 0x00 | BMI160_TAP_QUIET_30MS
  11416. * 0x01 | BMI160_TAP_QUIET_20MS
  11417. *
  11418. *
  11419. * @return results of bus communication function
  11420. * @retval 0 -> Success
  11421. * @retval -1 -> Error
  11422. *
  11423. *
  11424. */
  11425. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_tap_quiet(u8 v_tap_quiet_u8)
  11426. {
  11427. /* variable used to return the status of communication result*/
  11428. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11429. u8 v_data_u8 = BMI160_INIT_VALUE;
  11430. /* check the p_bmi160 structure for NULL pointer assignment*/
  11431. if (p_bmi160 == BMI160_NULL) {
  11432. return E_BMI160_NULL_PTR;
  11433. } else {
  11434. if (v_tap_quiet_u8 <= BMI160_MAX_VALUE_TAP_QUIET) {
  11435. /* write tap quiet duration*/
  11436. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11437. (p_bmi160->dev_addr,
  11438. BMI160_USER_INTR_TAP_0_INTR_TAP_QUIET__REG,
  11439. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11440. if (com_rslt == SUCCESS) {
  11441. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  11442. BMI160_USER_INTR_TAP_0_INTR_TAP_QUIET,
  11443. v_tap_quiet_u8);
  11444. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  11445. (p_bmi160->dev_addr,
  11446. BMI160_USER_INTR_TAP_0_INTR_TAP_QUIET__REG,
  11447. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11448. /*Accel and Gyro power mode check*/
  11449. if (bmi160_power_mode_status_u8_g !=
  11450. BMI160_NORMAL_MODE)
  11451. /*interface idle time delay */
  11452. p_bmi160->delay_msec(
  11453. BMI160_GEN_READ_WRITE_DELAY);
  11454. }
  11455. } else {
  11456. com_rslt = E_BMI160_OUT_OF_RANGE;
  11457. }
  11458. }
  11459. return com_rslt;
  11460. }
  11461. /*!
  11462. * @brief This API reads the threshold of the
  11463. * single/double tap interrupt from the register 0x64 bit 0 to 4
  11464. *
  11465. *
  11466. * @param v_tap_thres_u8 : The value of single/double tap threshold
  11467. *
  11468. * @note single/double tap threshold changes according to Accel g range
  11469. * Accel g range can be set by the function "bmi160_set_accel_range"
  11470. * accel_range | single/double tap threshold
  11471. * ----------------|---------------------
  11472. * 2g | ((v_tap_thres_u8 + 1) * 62.5)mg
  11473. * 4g | ((v_tap_thres_u8 + 1) * 125)mg
  11474. * 8g | ((v_tap_thres_u8 + 1) * 250)mg
  11475. * 16g | ((v_tap_thres_u8 + 1) * 500)mg
  11476. *
  11477. * @return results of bus communication function
  11478. * @retval 0 -> Success
  11479. * @retval -1 -> Error
  11480. *
  11481. *
  11482. */
  11483. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_tap_thres(
  11484. u8 *v_tap_thres_u8)
  11485. {
  11486. /* variable used to return the status of communication result*/
  11487. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11488. u8 v_data_u8 = BMI160_INIT_VALUE;
  11489. /* check the p_bmi160 structure for NULL pointer assignment*/
  11490. if (p_bmi160 == BMI160_NULL) {
  11491. return E_BMI160_NULL_PTR;
  11492. } else {
  11493. /* read tap threshold*/
  11494. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  11495. p_bmi160->dev_addr,
  11496. BMI160_USER_INTR_TAP_1_INTR_TAP_THRES__REG,
  11497. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11498. *v_tap_thres_u8 = BMI160_GET_BITSLICE
  11499. (v_data_u8,
  11500. BMI160_USER_INTR_TAP_1_INTR_TAP_THRES);
  11501. }
  11502. return com_rslt;
  11503. }
  11504. /*!
  11505. * @brief This API writes the threshold of the
  11506. * single/double tap interrupt in the register 0x64 bit 0 to 4
  11507. *
  11508. *
  11509. * @param v_tap_thres_u8 : The value of single/double tap threshold
  11510. *
  11511. * @note single/double tap threshold changes according to Accel g range
  11512. * Accel g range can be set by the function "bmi160_set_accel_range"
  11513. * accel_range | single/double tap threshold
  11514. * ----------------|---------------------
  11515. * 2g | ((v_tap_thres_u8 + 1) * 62.5)mg
  11516. * 4g | ((v_tap_thres_u8 + 1) * 125)mg
  11517. * 8g | ((v_tap_thres_u8 + 1) * 250)mg
  11518. * 16g | ((v_tap_thres_u8 + 1) * 500)mg
  11519. *
  11520. * @return results of bus communication function
  11521. * @retval 0 -> Success
  11522. * @retval -1 -> Error
  11523. *
  11524. *
  11525. */
  11526. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_tap_thres(
  11527. u8 v_tap_thres_u8)
  11528. {
  11529. /* variable used to return the status of communication result*/
  11530. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11531. u8 v_data_u8 = BMI160_INIT_VALUE;
  11532. /* check the p_bmi160 structure for NULL pointer assignment*/
  11533. if (p_bmi160 == BMI160_NULL) {
  11534. return E_BMI160_NULL_PTR;
  11535. } else {
  11536. /* write tap threshold*/
  11537. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11538. (p_bmi160->dev_addr,
  11539. BMI160_USER_INTR_TAP_1_INTR_TAP_THRES__REG,
  11540. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11541. if (com_rslt == SUCCESS) {
  11542. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  11543. BMI160_USER_INTR_TAP_1_INTR_TAP_THRES,
  11544. v_tap_thres_u8);
  11545. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  11546. (p_bmi160->dev_addr,
  11547. BMI160_USER_INTR_TAP_1_INTR_TAP_THRES__REG,
  11548. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11549. /*Accel and Gyro power mode check*/
  11550. if (bmi160_power_mode_status_u8_g !=
  11551. BMI160_NORMAL_MODE)
  11552. /*interface idle time delay */
  11553. p_bmi160->delay_msec(
  11554. BMI160_GEN_READ_WRITE_DELAY);
  11555. }
  11556. }
  11557. return com_rslt;
  11558. }
  11559. /*!
  11560. * @brief This API reads the threshold for orientation interrupt
  11561. * from the register 0x65 bit 0 and 1
  11562. *
  11563. * @param v_orient_mode_u8 : The value of threshold for orientation
  11564. * value | Behaviour
  11565. * ----------|-------------------
  11566. * 0x00 | symmetrical
  11567. * 0x01 | high-asymmetrical
  11568. * 0x02 | low-asymmetrical
  11569. * 0x03 | symmetrical
  11570. *
  11571. *
  11572. *
  11573. * @return results of bus communication function
  11574. * @retval 0 -> Success
  11575. * @retval -1 -> Error
  11576. *
  11577. *
  11578. */
  11579. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_orient_mode(
  11580. u8 *v_orient_mode_u8)
  11581. {
  11582. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11583. u8 v_data_u8 = BMI160_INIT_VALUE;
  11584. /* check the p_bmi160 structure for NULL pointer assignment*/
  11585. if (p_bmi160 == BMI160_NULL) {
  11586. return E_BMI160_NULL_PTR;
  11587. } else {
  11588. /* read orientation threshold*/
  11589. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11590. (p_bmi160->dev_addr,
  11591. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_MODE__REG,
  11592. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11593. *v_orient_mode_u8 = BMI160_GET_BITSLICE
  11594. (v_data_u8,
  11595. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_MODE);
  11596. }
  11597. return com_rslt;
  11598. }
  11599. /*!
  11600. * @brief This API writes the threshold for orientation interrupt
  11601. * from the register 0x65 bit 0 and 1
  11602. *
  11603. * @param v_orient_mode_u8 : The value of threshold for orientation
  11604. * value | Behaviour
  11605. * ----------|-------------------
  11606. * 0x00 | symmetrical
  11607. * 0x01 | high-asymmetrical
  11608. * 0x02 | low-asymmetrical
  11609. * 0x03 | symmetrical
  11610. *
  11611. *
  11612. *
  11613. * @return results of bus communication function
  11614. * @retval 0 -> Success
  11615. * @retval -1 -> Error
  11616. *
  11617. *
  11618. */
  11619. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_orient_mode(
  11620. u8 v_orient_mode_u8)
  11621. {
  11622. /* variable used to return the status of communication result*/
  11623. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11624. u8 v_data_u8 = BMI160_INIT_VALUE;
  11625. /* check the p_bmi160 structure for NULL pointer assignment*/
  11626. if (p_bmi160 == BMI160_NULL) {
  11627. return E_BMI160_NULL_PTR;
  11628. } else {
  11629. if (v_orient_mode_u8 <= BMI160_MAX_ORIENT_MODE) {
  11630. /* write orientation threshold*/
  11631. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11632. (p_bmi160->dev_addr,
  11633. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_MODE__REG,
  11634. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11635. if (com_rslt == SUCCESS) {
  11636. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  11637. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_MODE,
  11638. v_orient_mode_u8);
  11639. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  11640. (p_bmi160->dev_addr,
  11641. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_MODE__REG,
  11642. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11643. /*Accel and Gyro power mode check*/
  11644. if (bmi160_power_mode_status_u8_g !=
  11645. BMI160_NORMAL_MODE)
  11646. /*interface idle time delay */
  11647. p_bmi160->delay_msec(
  11648. BMI160_GEN_READ_WRITE_DELAY);
  11649. }
  11650. } else {
  11651. com_rslt = E_BMI160_OUT_OF_RANGE;
  11652. }
  11653. }
  11654. return com_rslt;
  11655. }
  11656. /*!
  11657. * @brief This API reads the orientation blocking mode
  11658. * that is used for the generation of the orientation interrupt.
  11659. * from the register 0x65 bit 2 and 3
  11660. *
  11661. * @param v_orient_blocking_u8 : The value of orient blocking mode
  11662. * value | Behaviour
  11663. * ----------|-------------------
  11664. * 0x00 | No blocking
  11665. * 0x01 | Theta blocking or acceleration in any axis > 1.5g
  11666. * 0x02 | Theta blocking or acceleration slope in any axis >
  11667. * - | 0.2g or acceleration in any axis > 1.5g
  11668. * 0x03 | Theta blocking or acceleration slope in any axis >
  11669. * - | 0.4g or acceleration in any axis >
  11670. * - | 1.5g and value of orient is not stable
  11671. * - | for at least 100 ms
  11672. *
  11673. *
  11674. *
  11675. * @return results of bus communication function
  11676. * @retval 0 -> Success
  11677. * @retval -1 -> Error
  11678. *
  11679. *
  11680. */
  11681. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_orient_blocking(
  11682. u8 *v_orient_blocking_u8)
  11683. {
  11684. /* variable used to return the status of communication result*/
  11685. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11686. u8 v_data_u8 = BMI160_INIT_VALUE;
  11687. /* check the p_bmi160 structure for NULL pointer assignment*/
  11688. if (p_bmi160 == BMI160_NULL) {
  11689. return E_BMI160_NULL_PTR;
  11690. } else {
  11691. /* read orient blocking mode*/
  11692. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11693. (p_bmi160->dev_addr,
  11694. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING__REG,
  11695. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11696. *v_orient_blocking_u8 = BMI160_GET_BITSLICE
  11697. (v_data_u8,
  11698. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING);
  11699. }
  11700. return com_rslt;
  11701. }
  11702. /*!
  11703. * @brief This API writes the orientation blocking mode
  11704. * that is used for the generation of the orientation interrupt.
  11705. * in the register 0x65 bit 2 and 3
  11706. *
  11707. * @param v_orient_blocking_u8 : The value of orient blocking mode
  11708. * value | Behaviour
  11709. * ----------|-------------------
  11710. * 0x00 | No blocking
  11711. * 0x01 | Theta blocking or acceleration in any axis > 1.5g
  11712. * 0x02 | Theta blocking or acceleration slope in any axis >
  11713. * - | 0.2g or acceleration in any axis > 1.5g
  11714. * 0x03 | Theta blocking or acceleration slope in any axis >
  11715. * - | 0.4g or acceleration in any axis >
  11716. * - | 1.5g and value of orient is not stable
  11717. * - | for at least 100 ms
  11718. *
  11719. *
  11720. *
  11721. * @return results of bus communication function
  11722. * @retval 0 -> Success
  11723. * @retval -1 -> Error
  11724. *
  11725. *
  11726. */
  11727. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_orient_blocking(
  11728. u8 v_orient_blocking_u8)
  11729. {
  11730. /* variable used to return the status of communication result*/
  11731. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11732. u8 v_data_u8 = BMI160_INIT_VALUE;
  11733. /* check the p_bmi160 structure for NULL pointer assignment*/
  11734. if (p_bmi160 == BMI160_NULL) {
  11735. return E_BMI160_NULL_PTR;
  11736. } else {
  11737. if (v_orient_blocking_u8 <= BMI160_MAX_ORIENT_BLOCKING) {
  11738. /* write orient blocking mode*/
  11739. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11740. (p_bmi160->dev_addr,
  11741. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING__REG,
  11742. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11743. if (com_rslt == SUCCESS) {
  11744. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  11745. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING,
  11746. v_orient_blocking_u8);
  11747. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  11748. (p_bmi160->dev_addr,
  11749. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING__REG,
  11750. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11751. /*Accel and Gyro power mode check*/
  11752. if (bmi160_power_mode_status_u8_g !=
  11753. BMI160_NORMAL_MODE)
  11754. /*interface idle time delay */
  11755. p_bmi160->delay_msec(
  11756. BMI160_GEN_READ_WRITE_DELAY);
  11757. }
  11758. } else {
  11759. com_rslt = E_BMI160_OUT_OF_RANGE;
  11760. }
  11761. }
  11762. return com_rslt;
  11763. }
  11764. /*!
  11765. * @brief This API reads the orientation interrupt
  11766. * hysteresis, from the register 0x64 bit 4 to 7
  11767. *
  11768. *
  11769. *
  11770. * @param v_orient_hyst_u8 : The value of orient hysteresis
  11771. *
  11772. * @note 1 LSB corresponds to 62.5 mg,
  11773. * irrespective of the selected Accel range
  11774. *
  11775. *
  11776. * @return results of bus communication function
  11777. * @retval 0 -> Success
  11778. * @retval -1 -> Error
  11779. *
  11780. *
  11781. */
  11782. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_orient_hyst(
  11783. u8 *v_orient_hyst_u8)
  11784. {
  11785. /* variable used to return the status of communication result*/
  11786. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11787. u8 v_data_u8 = BMI160_INIT_VALUE;
  11788. /* check the p_bmi160 structure for NULL pointer assignment*/
  11789. if (p_bmi160 == BMI160_NULL) {
  11790. return E_BMI160_NULL_PTR;
  11791. } else {
  11792. /* read orient hysteresis*/
  11793. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11794. (p_bmi160->dev_addr,
  11795. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_HYST__REG,
  11796. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11797. *v_orient_hyst_u8 = BMI160_GET_BITSLICE
  11798. (v_data_u8,
  11799. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_HYST);
  11800. }
  11801. return com_rslt;
  11802. }
  11803. /*!
  11804. * @brief This API writes the orientation interrupt
  11805. * hysteresis, in the register 0x64 bit 4 to 7
  11806. *
  11807. *
  11808. *
  11809. * @param v_orient_hyst_u8 : The value of orient hysteresis
  11810. *
  11811. * @note 1 LSB corresponds to 62.5 mg,
  11812. * irrespective of the selected Accel range
  11813. *
  11814. *
  11815. * @return results of bus communication function
  11816. * @retval 0 -> Success
  11817. * @retval -1 -> Error
  11818. *
  11819. *
  11820. */
  11821. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_orient_hyst(
  11822. u8 v_orient_hyst_u8)
  11823. {
  11824. /* variable used to return the status of communication result*/
  11825. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11826. u8 v_data_u8 = BMI160_INIT_VALUE;
  11827. /* check the p_bmi160 structure for NULL pointer assignment*/
  11828. if (p_bmi160 == BMI160_NULL) {
  11829. return E_BMI160_NULL_PTR;
  11830. } else {
  11831. /* write orient hysteresis*/
  11832. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11833. (p_bmi160->dev_addr,
  11834. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_HYST__REG,
  11835. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11836. if (com_rslt == SUCCESS) {
  11837. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  11838. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_HYST,
  11839. v_orient_hyst_u8);
  11840. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  11841. (p_bmi160->dev_addr,
  11842. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_HYST__REG,
  11843. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11844. /*Accel and Gyro power mode check*/
  11845. if (bmi160_power_mode_status_u8_g !=
  11846. BMI160_NORMAL_MODE)
  11847. /*interface idle time delay */
  11848. p_bmi160->delay_msec(
  11849. BMI160_GEN_READ_WRITE_DELAY);
  11850. }
  11851. }
  11852. return com_rslt;
  11853. }
  11854. /*!
  11855. * @brief This API reads the orientation
  11856. * blocking angle (0 to 44.8) from the register 0x66 bit 0 to 5
  11857. *
  11858. * @param v_orient_theta_u8 : The value of Orient blocking angle
  11859. *
  11860. *
  11861. *
  11862. * @return results of bus communication function
  11863. * @retval 0 -> Success
  11864. * @retval -1 -> Error
  11865. *
  11866. *
  11867. */
  11868. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_orient_theta(
  11869. u8 *v_orient_theta_u8)
  11870. {
  11871. /* variable used to return the status of communication result*/
  11872. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11873. u8 v_data_u8 = BMI160_INIT_VALUE;
  11874. /* check the p_bmi160 structure for NULL pointer assignment*/
  11875. if (p_bmi160 == BMI160_NULL) {
  11876. return E_BMI160_NULL_PTR;
  11877. } else {
  11878. /* read Orient blocking angle*/
  11879. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11880. (p_bmi160->dev_addr,
  11881. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_THETA__REG,
  11882. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11883. *v_orient_theta_u8 = BMI160_GET_BITSLICE
  11884. (v_data_u8,
  11885. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_THETA);
  11886. }
  11887. return com_rslt;
  11888. }
  11889. /*!
  11890. * @brief This API writes orientation
  11891. * blocking angle (0 to 44.8) in the register 0x66 bit 0 to 5
  11892. *
  11893. * @param v_orient_theta_u8 : The value of Orient blocking angle
  11894. *
  11895. *
  11896. *
  11897. * @return results of bus communication function
  11898. * @retval 0 -> Success
  11899. * @retval -1 -> Error
  11900. *
  11901. *
  11902. */
  11903. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_orient_theta(
  11904. u8 v_orient_theta_u8)
  11905. {
  11906. /* variable used to return the status of communication result*/
  11907. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11908. u8 v_data_u8 = BMI160_INIT_VALUE;
  11909. /* check the p_bmi160 structure for NULL pointer assignment*/
  11910. if (p_bmi160 == BMI160_NULL) {
  11911. return E_BMI160_NULL_PTR;
  11912. } else {
  11913. if (v_orient_theta_u8 <= BMI160_MAX_ORIENT_THETA) {
  11914. /* write Orient blocking angle*/
  11915. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11916. (p_bmi160->dev_addr,
  11917. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_THETA__REG,
  11918. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11919. if (com_rslt == SUCCESS) {
  11920. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  11921. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_THETA,
  11922. v_orient_theta_u8);
  11923. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  11924. (p_bmi160->dev_addr,
  11925. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_THETA__REG,
  11926. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11927. /*Accel and Gyro power mode check*/
  11928. if (bmi160_power_mode_status_u8_g !=
  11929. BMI160_NORMAL_MODE)
  11930. /*interface idle time delay */
  11931. p_bmi160->delay_msec(
  11932. BMI160_GEN_READ_WRITE_DELAY);
  11933. }
  11934. } else {
  11935. com_rslt = E_BMI160_OUT_OF_RANGE;
  11936. }
  11937. }
  11938. return com_rslt;
  11939. }
  11940. /*!
  11941. * @brief This API reads the orientation change
  11942. * of up/down bit from the register 0x66 bit 6
  11943. *
  11944. * @param v_orient_ud_u8 : The value of orient change of up/down
  11945. * value | Behaviour
  11946. * ----------|-------------------
  11947. * 0x00 | Is ignored
  11948. * 0x01 | Generates orientation interrupt
  11949. *
  11950. *
  11951. * @return results of bus communication function
  11952. * @retval 0 -> Success
  11953. * @retval -1 -> Error
  11954. *
  11955. *
  11956. */
  11957. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_orient_ud_enable(
  11958. u8 *v_orient_ud_u8)
  11959. {
  11960. /* variable used to return the status of communication result*/
  11961. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11962. u8 v_data_u8 = BMI160_INIT_VALUE;
  11963. /* check the p_bmi160 structure for NULL pointer assignment*/
  11964. if (p_bmi160 == BMI160_NULL) {
  11965. return E_BMI160_NULL_PTR;
  11966. } else {
  11967. /* read orient up/down enable*/
  11968. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11969. (p_bmi160->dev_addr,
  11970. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE__REG,
  11971. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  11972. *v_orient_ud_u8 = BMI160_GET_BITSLICE
  11973. (v_data_u8,
  11974. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE);
  11975. }
  11976. return com_rslt;
  11977. }
  11978. /*!
  11979. * @brief This API writes orientation change
  11980. * of up/down bit in the register 0x66 bit 6
  11981. *
  11982. * @param v_orient_ud_u8 : The value of orient change of up/down
  11983. * value | Behaviour
  11984. * ----------|-------------------
  11985. * 0x00 | Is ignored
  11986. * 0x01 | Generates orientation interrupt
  11987. *
  11988. *
  11989. * @return results of bus communication function
  11990. * @retval 0 -> Success
  11991. * @retval -1 -> Error
  11992. *
  11993. *
  11994. */
  11995. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_orient_ud_enable(
  11996. u8 v_orient_ud_u8)
  11997. {
  11998. /* variable used to return the status of communication result*/
  11999. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12000. u8 v_data_u8 = BMI160_INIT_VALUE;
  12001. /* check the p_bmi160 structure for NULL pointer assignment*/
  12002. if (p_bmi160 == BMI160_NULL) {
  12003. return E_BMI160_NULL_PTR;
  12004. } else {
  12005. if (v_orient_ud_u8 <= BMI160_MAX_VALUE_ORIENT_UD) {
  12006. /* write orient up/down enable */
  12007. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  12008. (p_bmi160->dev_addr,
  12009. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE__REG,
  12010. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12011. if (com_rslt == SUCCESS) {
  12012. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  12013. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE,
  12014. v_orient_ud_u8);
  12015. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  12016. (p_bmi160->dev_addr,
  12017. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE__REG,
  12018. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12019. /*Accel and Gyro power mode check*/
  12020. if (bmi160_power_mode_status_u8_g !=
  12021. BMI160_NORMAL_MODE)
  12022. /*interface idle time delay */
  12023. p_bmi160->delay_msec(
  12024. BMI160_GEN_READ_WRITE_DELAY);
  12025. }
  12026. } else {
  12027. com_rslt = E_BMI160_OUT_OF_RANGE;
  12028. }
  12029. }
  12030. return com_rslt;
  12031. }
  12032. /*!
  12033. * @brief This API reads orientation axes changes
  12034. * from the register 0x66 bit 7
  12035. *
  12036. * @param v_orient_axes_u8 : The value of orient axes assignment
  12037. * value | Behaviour | Name
  12038. * ----------|--------------------|------
  12039. * 0x00 | x = x, y = y, z = z|orient_ax_noex
  12040. * 0x01 | x = y, y = z, z = x|orient_ax_ex
  12041. *
  12042. *
  12043. * @return results of bus communication function
  12044. * @retval 0 -> Success
  12045. * @retval -1 -> Error
  12046. *
  12047. *
  12048. */
  12049. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_orient_axes_enable(
  12050. u8 *v_orient_axes_u8)
  12051. {
  12052. /* variable used to return the status of communication result*/
  12053. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12054. u8 v_data_u8 = BMI160_INIT_VALUE;
  12055. /* check the p_bmi160 structure for NULL pointer assignment*/
  12056. if (p_bmi160 == BMI160_NULL) {
  12057. return E_BMI160_NULL_PTR;
  12058. } else {
  12059. /* read orientation axes changes */
  12060. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  12061. (p_bmi160->dev_addr,
  12062. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX__REG,
  12063. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12064. *v_orient_axes_u8 = BMI160_GET_BITSLICE
  12065. (v_data_u8,
  12066. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX);
  12067. }
  12068. return com_rslt;
  12069. }
  12070. /*!
  12071. * @brief This API writes orientation axes changes
  12072. * in the register 0x66 bit 7
  12073. *
  12074. * @param v_orient_axes_u8 : The value of orient axes assignment
  12075. * value | Behaviour | Name
  12076. * ----------|--------------------|------
  12077. * 0x00 | x = x, y = y, z = z|orient_ax_noex
  12078. * 0x01 | x = y, y = z, z = x|orient_ax_ex
  12079. *
  12080. *
  12081. * @return results of bus communication function
  12082. * @retval 0 -> Success
  12083. * @retval -1 -> Error
  12084. *
  12085. *
  12086. */
  12087. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_orient_axes_enable(
  12088. u8 v_orient_axes_u8)
  12089. {
  12090. /* variable used to return the status of communication result*/
  12091. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12092. u8 v_data_u8 = BMI160_INIT_VALUE;
  12093. /* check the p_bmi160 structure for NULL pointer assignment*/
  12094. if (p_bmi160 == BMI160_NULL) {
  12095. return E_BMI160_NULL_PTR;
  12096. } else {
  12097. if (v_orient_axes_u8 <= BMI160_MAX_VALUE_ORIENT_AXES) {
  12098. /*write orientation axes changes */
  12099. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  12100. (p_bmi160->dev_addr,
  12101. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX__REG,
  12102. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12103. if (com_rslt == SUCCESS) {
  12104. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  12105. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX,
  12106. v_orient_axes_u8);
  12107. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  12108. (p_bmi160->dev_addr,
  12109. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX__REG,
  12110. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12111. /*Accel and Gyro power mode check*/
  12112. if (bmi160_power_mode_status_u8_g !=
  12113. BMI160_NORMAL_MODE)
  12114. /*interface idle time delay */
  12115. p_bmi160->delay_msec(
  12116. BMI160_GEN_READ_WRITE_DELAY);
  12117. }
  12118. } else {
  12119. com_rslt = E_BMI160_OUT_OF_RANGE;
  12120. }
  12121. }
  12122. return com_rslt;
  12123. }
  12124. /*!
  12125. * @brief This API reads Flat angle (0 to 44.8) for flat interrupt
  12126. * from the register 0x67 bit 0 to 5
  12127. *
  12128. * @param v_flat_theta_u8 : The value of flat angle
  12129. *
  12130. *
  12131. *
  12132. * @return results of bus communication function
  12133. * @retval 0 -> Success
  12134. * @retval -1 -> Error
  12135. *
  12136. *
  12137. */
  12138. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_flat_theta(
  12139. u8 *v_flat_theta_u8)
  12140. {
  12141. /* variable used to return the status of communication result*/
  12142. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12143. u8 v_data_u8 = BMI160_INIT_VALUE;
  12144. /* check the p_bmi160 structure for NULL pointer assignment*/
  12145. if (p_bmi160 == BMI160_NULL) {
  12146. return E_BMI160_NULL_PTR;
  12147. } else {
  12148. /* read Flat angle*/
  12149. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  12150. (p_bmi160->dev_addr,
  12151. BMI160_USER_INTR_FLAT_0_INTR_FLAT_THETA__REG,
  12152. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12153. *v_flat_theta_u8 = BMI160_GET_BITSLICE(v_data_u8,
  12154. BMI160_USER_INTR_FLAT_0_INTR_FLAT_THETA);
  12155. }
  12156. return com_rslt;
  12157. }
  12158. /*!
  12159. * @brief This API writes Flat angle (0 to 44.8) for flat interrupt
  12160. * in the register 0x67 bit 0 to 5
  12161. *
  12162. * @param v_flat_theta_u8 : The value of flat angle
  12163. *
  12164. *
  12165. *
  12166. * @return results of bus communication function
  12167. * @retval 0 -> Success
  12168. * @retval -1 -> Error
  12169. *
  12170. *
  12171. */
  12172. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_flat_theta(
  12173. u8 v_flat_theta_u8)
  12174. {
  12175. /* variable used to return the status of communication result*/
  12176. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12177. u8 v_data_u8 = BMI160_INIT_VALUE;
  12178. /* check the p_bmi160 structure for NULL pointer assignment*/
  12179. if (p_bmi160 == BMI160_NULL) {
  12180. return E_BMI160_NULL_PTR;
  12181. } else {
  12182. if (v_flat_theta_u8 <= BMI160_MAX_FLAT_THETA) {
  12183. /* write Flat angle */
  12184. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  12185. (p_bmi160->dev_addr,
  12186. BMI160_USER_INTR_FLAT_0_INTR_FLAT_THETA__REG,
  12187. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12188. if (com_rslt == SUCCESS) {
  12189. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  12190. BMI160_USER_INTR_FLAT_0_INTR_FLAT_THETA,
  12191. v_flat_theta_u8);
  12192. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  12193. (p_bmi160->dev_addr,
  12194. BMI160_USER_INTR_FLAT_0_INTR_FLAT_THETA__REG,
  12195. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12196. /*Accel and Gyro power mode check*/
  12197. if (bmi160_power_mode_status_u8_g !=
  12198. BMI160_NORMAL_MODE)
  12199. /*interface idle time delay */
  12200. p_bmi160->delay_msec(
  12201. BMI160_GEN_READ_WRITE_DELAY);
  12202. }
  12203. } else {
  12204. com_rslt = E_BMI160_OUT_OF_RANGE;
  12205. }
  12206. }
  12207. return com_rslt;
  12208. }
  12209. /*!
  12210. * @brief This API reads Flat interrupt hold time;
  12211. * from the register 0x68 bit 4 and 5
  12212. *
  12213. * @param v_flat_hold_u8 : The value of flat hold time
  12214. * value | Behaviour
  12215. * ----------|-------------------
  12216. * 0x00 | 0ms
  12217. * 0x01 | 512ms
  12218. * 0x01 | 1024ms
  12219. * 0x01 | 2048ms
  12220. *
  12221. *
  12222. * @return results of bus communication function
  12223. * @retval 0 -> Success
  12224. * @retval -1 -> Error
  12225. *
  12226. *
  12227. */
  12228. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_flat_hold(
  12229. u8 *v_flat_hold_u8)
  12230. {
  12231. /* variable used to return the status of communication result*/
  12232. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12233. u8 v_data_u8 = BMI160_INIT_VALUE;
  12234. /* check the p_bmi160 structure for NULL pointer assignment*/
  12235. if (p_bmi160 == BMI160_NULL) {
  12236. return E_BMI160_NULL_PTR;
  12237. } else {
  12238. /* read flat hold time*/
  12239. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  12240. p_bmi160->dev_addr,
  12241. BMI160_USER_INTR_FLAT_1_INTR_FLAT_HOLD__REG,
  12242. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12243. *v_flat_hold_u8 = BMI160_GET_BITSLICE(v_data_u8,
  12244. BMI160_USER_INTR_FLAT_1_INTR_FLAT_HOLD);
  12245. }
  12246. return com_rslt;
  12247. }
  12248. /*!
  12249. * @brief This API writes flat interrupt hold time in
  12250. * the register 0x68 bit 4 and 5
  12251. *
  12252. * @param v_flat_hold_u8 : The value of flat hold time
  12253. * value | Behaviour
  12254. * ----------|-------------------
  12255. * 0x00 | 0ms
  12256. * 0x01 | 512ms
  12257. * 0x01 | 1024ms
  12258. * 0x01 | 2048ms
  12259. *
  12260. *
  12261. * @return results of bus communication function
  12262. * @retval 0 -> Success
  12263. * @retval -1 -> Error
  12264. *
  12265. *
  12266. */
  12267. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_flat_hold(
  12268. u8 v_flat_hold_u8)
  12269. {
  12270. /* variable used to return the status of communication result*/
  12271. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12272. u8 v_data_u8 = BMI160_INIT_VALUE;
  12273. /* check the p_bmi160 structure for NULL pointer assignment*/
  12274. if (p_bmi160 == BMI160_NULL) {
  12275. return E_BMI160_NULL_PTR;
  12276. } else {
  12277. if (v_flat_hold_u8 <= BMI160_MAX_FLAT_HOLD) {
  12278. /* write flat hold time*/
  12279. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  12280. p_bmi160->dev_addr,
  12281. BMI160_USER_INTR_FLAT_1_INTR_FLAT_HOLD__REG,
  12282. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12283. if (com_rslt == SUCCESS) {
  12284. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  12285. BMI160_USER_INTR_FLAT_1_INTR_FLAT_HOLD,
  12286. v_flat_hold_u8);
  12287. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  12288. (p_bmi160->dev_addr,
  12289. BMI160_USER_INTR_FLAT_1_INTR_FLAT_HOLD__REG,
  12290. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12291. /*Accel and Gyro power mode check*/
  12292. if (bmi160_power_mode_status_u8_g !=
  12293. BMI160_NORMAL_MODE)
  12294. /*interface idle time delay */
  12295. p_bmi160->delay_msec(
  12296. BMI160_GEN_READ_WRITE_DELAY);
  12297. }
  12298. } else {
  12299. com_rslt = E_BMI160_OUT_OF_RANGE;
  12300. }
  12301. }
  12302. return com_rslt;
  12303. }
  12304. /*!
  12305. * @brief This API reads flat interrupt hysteresis
  12306. * from the register 0x68 bit 0 to 3
  12307. *
  12308. * @param v_flat_hyst_u8 : The value of flat hysteresis
  12309. *
  12310. *
  12311. *
  12312. * @return results of bus communication function
  12313. * @retval 0 -> Success
  12314. * @retval -1 -> Error
  12315. *
  12316. *
  12317. */
  12318. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_flat_hyst(
  12319. u8 *v_flat_hyst_u8)
  12320. {
  12321. /* variable used to return the status of communication result*/
  12322. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12323. u8 v_data_u8 = BMI160_INIT_VALUE;
  12324. /* check the p_bmi160 structure for NULL pointer assignment*/
  12325. if (p_bmi160 == BMI160_NULL) {
  12326. return E_BMI160_NULL_PTR;
  12327. } else {
  12328. /* read the flat hysteresis*/
  12329. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  12330. p_bmi160->dev_addr,
  12331. BMI160_USER_INTR_FLAT_1_INTR_FLAT_HYST__REG,
  12332. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12333. *v_flat_hyst_u8 = BMI160_GET_BITSLICE(
  12334. v_data_u8,
  12335. BMI160_USER_INTR_FLAT_1_INTR_FLAT_HYST);
  12336. }
  12337. return com_rslt;
  12338. }
  12339. /*!
  12340. * @brief This API writes flat interrupt hysteresis
  12341. * in the register 0x68 bit 0 to 3
  12342. *
  12343. * @param v_flat_hyst_u8 : The value of flat hysteresis
  12344. *
  12345. *
  12346. *
  12347. * @return results of bus communication function
  12348. * @retval 0 -> Success
  12349. * @retval -1 -> Error
  12350. *
  12351. *
  12352. */
  12353. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_flat_hyst(
  12354. u8 v_flat_hyst_u8)
  12355. {
  12356. /* variable used to return the status of communication result*/
  12357. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12358. u8 v_data_u8 = BMI160_INIT_VALUE;
  12359. /* check the p_bmi160 structure for NULL pointer assignment*/
  12360. if (p_bmi160 == BMI160_NULL) {
  12361. return E_BMI160_NULL_PTR;
  12362. } else {
  12363. if (v_flat_hyst_u8 <= BMI160_MAX_FLAT_HYST) {
  12364. /* read the flat hysteresis*/
  12365. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  12366. (p_bmi160->dev_addr,
  12367. BMI160_USER_INTR_FLAT_1_INTR_FLAT_HYST__REG,
  12368. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12369. if (com_rslt == SUCCESS) {
  12370. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  12371. BMI160_USER_INTR_FLAT_1_INTR_FLAT_HYST,
  12372. v_flat_hyst_u8);
  12373. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  12374. (p_bmi160->dev_addr,
  12375. BMI160_USER_INTR_FLAT_1_INTR_FLAT_HYST__REG,
  12376. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12377. /*Accel and Gyro power mode check*/
  12378. if (bmi160_power_mode_status_u8_g !=
  12379. BMI160_NORMAL_MODE)
  12380. /*interface idle time delay */
  12381. p_bmi160->delay_msec(
  12382. BMI160_GEN_READ_WRITE_DELAY);
  12383. }
  12384. } else {
  12385. com_rslt = E_BMI160_OUT_OF_RANGE;
  12386. }
  12387. }
  12388. return com_rslt;
  12389. }
  12390. /*!
  12391. * @brief This API reads Accel offset compensation
  12392. * target value for z-axis from the register 0x69 bit 0 and 1
  12393. *
  12394. * @param v_foc_accel_z_u8 : the value of Accel offset compensation z axis
  12395. * value | Behaviour
  12396. * ----------|-------------------
  12397. * 0x00 | disable
  12398. * 0x01 | +1g
  12399. * 0x01 | -1g
  12400. * 0x01 | 0g
  12401. *
  12402. * @return results of bus communication function
  12403. * @retval 0 -> Success
  12404. * @retval -1 -> Error
  12405. *
  12406. *
  12407. */
  12408. BMI160_RETURN_FUNCTION_TYPE bmi160_get_foc_accel_z(u8 *v_foc_accel_z_u8)
  12409. {
  12410. /* variable used to return the status of communication result*/
  12411. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12412. u8 v_data_u8 = BMI160_INIT_VALUE;
  12413. /* check the p_bmi160 structure for NULL pointer assignment*/
  12414. if (p_bmi160 == BMI160_NULL) {
  12415. return E_BMI160_NULL_PTR;
  12416. } else {
  12417. /* read the Accel offset compensation for z axis*/
  12418. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  12419. p_bmi160->dev_addr,
  12420. BMI160_USER_FOC_ACCEL_Z__REG,
  12421. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12422. *v_foc_accel_z_u8 = BMI160_GET_BITSLICE(v_data_u8,
  12423. BMI160_USER_FOC_ACCEL_Z);
  12424. }
  12425. return com_rslt;
  12426. }
  12427. /*!
  12428. * @brief This API writes Accel offset compensation
  12429. * target value for z-axis in the register 0x69 bit 0 and 1
  12430. *
  12431. * @param v_foc_accel_z_u8 : the value of Accel offset compensation z axis
  12432. * value | Behaviour
  12433. * ----------|-------------------
  12434. * 0x00 | disable
  12435. * 0x01 | +1g
  12436. * 0x01 | -1g
  12437. * 0x01 | 0g
  12438. *
  12439. * @return results of bus communication function
  12440. * @retval 0 -> Success
  12441. * @retval -1 -> Error
  12442. *
  12443. *
  12444. */
  12445. BMI160_RETURN_FUNCTION_TYPE bmi160_set_foc_accel_z(
  12446. u8 v_foc_accel_z_u8)
  12447. {
  12448. /* variable used to return the status of communication result*/
  12449. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12450. u8 v_data_u8 = BMI160_INIT_VALUE;
  12451. /* check the p_bmi160 structure for NULL pointer assignment*/
  12452. if (p_bmi160 == BMI160_NULL) {
  12453. return E_BMI160_NULL_PTR;
  12454. } else {
  12455. /* write the Accel offset compensation for z axis*/
  12456. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  12457. (p_bmi160->dev_addr,
  12458. BMI160_USER_FOC_ACCEL_Z__REG,
  12459. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12460. if (com_rslt == SUCCESS) {
  12461. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  12462. BMI160_USER_FOC_ACCEL_Z,
  12463. v_foc_accel_z_u8);
  12464. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  12465. (p_bmi160->dev_addr,
  12466. BMI160_USER_FOC_ACCEL_Z__REG,
  12467. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12468. }
  12469. }
  12470. return com_rslt;
  12471. }
  12472. /*!
  12473. * @brief This API reads Accel offset compensation
  12474. * target value for y-axis
  12475. * from the register 0x69 bit 2 and 3
  12476. *
  12477. * @param v_foc_accel_y_u8 : the value of Accel offset compensation y axis
  12478. * value | Behaviour
  12479. * ----------|-------------------
  12480. * 0x00 | disable
  12481. * 0x01 | +1g
  12482. * 0x01 | -1g
  12483. * 0x01 | 0g
  12484. *
  12485. *
  12486. *
  12487. * @return results of bus communication function
  12488. * @retval 0 -> Success
  12489. * @retval -1 -> Error
  12490. *
  12491. *
  12492. */
  12493. BMI160_RETURN_FUNCTION_TYPE bmi160_get_foc_accel_y(u8 *v_foc_accel_y_u8)
  12494. {
  12495. /* variable used to return the status of communication result*/
  12496. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12497. u8 v_data_u8 = BMI160_INIT_VALUE;
  12498. /* check the p_bmi160 structure for NULL pointer assignment*/
  12499. if (p_bmi160 == BMI160_NULL) {
  12500. return E_BMI160_NULL_PTR;
  12501. } else {
  12502. /* read the Accel offset compensation for y axis*/
  12503. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  12504. (p_bmi160->dev_addr,
  12505. BMI160_USER_FOC_ACCEL_Y__REG,
  12506. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12507. *v_foc_accel_y_u8 = BMI160_GET_BITSLICE(v_data_u8,
  12508. BMI160_USER_FOC_ACCEL_Y);
  12509. }
  12510. return com_rslt;
  12511. }
  12512. /*!
  12513. * @brief This API writes Accel offset compensation
  12514. * target value for y-axis in the register 0x69 bit 2 and 3
  12515. *
  12516. * @param v_foc_accel_y_u8 : the value of Accel offset compensation y axis
  12517. * value | Behaviour
  12518. * ----------|-------------------
  12519. * 0x00 | disable
  12520. * 0x01 | +1g
  12521. * 0x02 | -1g
  12522. * 0x03 | 0g
  12523. *
  12524. *
  12525. *
  12526. * @return results of bus communication function
  12527. * @retval 0 -> Success
  12528. * @retval -1 -> Error
  12529. *
  12530. *
  12531. */
  12532. BMI160_RETURN_FUNCTION_TYPE bmi160_set_foc_accel_y(u8 v_foc_accel_y_u8)
  12533. {
  12534. /* variable used to return the status of communication result*/
  12535. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12536. u8 v_data_u8 = BMI160_INIT_VALUE;
  12537. /* check the p_bmi160 structure for NULL pointer assignment*/
  12538. if (p_bmi160 == BMI160_NULL) {
  12539. return E_BMI160_NULL_PTR;
  12540. } else {
  12541. if (v_foc_accel_y_u8 <= BMI160_MAX_ACCEL_FOC) {
  12542. /* write the Accel offset compensation for y axis*/
  12543. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  12544. (p_bmi160->dev_addr,
  12545. BMI160_USER_FOC_ACCEL_Y__REG,
  12546. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12547. if (com_rslt == SUCCESS) {
  12548. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  12549. BMI160_USER_FOC_ACCEL_Y,
  12550. v_foc_accel_y_u8);
  12551. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  12552. (p_bmi160->dev_addr,
  12553. BMI160_USER_FOC_ACCEL_Y__REG,
  12554. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12555. }
  12556. } else {
  12557. com_rslt = E_BMI160_OUT_OF_RANGE;
  12558. }
  12559. }
  12560. return com_rslt;
  12561. }
  12562. /*!
  12563. * @brief This API reads Accel offset compensation
  12564. * target value for x-axis from the register 0x69 bit 4 and 5
  12565. *
  12566. * @param v_foc_accel_x_u8 : the value of Accel offset compensation x axis
  12567. * value | Behaviour
  12568. * ----------|-------------------
  12569. * 0x00 | disable
  12570. * 0x01 | +1g
  12571. * 0x02 | -1g
  12572. * 0x03 | 0g
  12573. *
  12574. *
  12575. *
  12576. * @return results of bus communication function
  12577. * @retval 0 -> Success
  12578. * @retval -1 -> Error
  12579. *
  12580. *
  12581. */
  12582. BMI160_RETURN_FUNCTION_TYPE bmi160_get_foc_accel_x(u8 *v_foc_accel_x_u8)
  12583. {
  12584. /* variable used to return the status of communication result*/
  12585. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12586. u8 v_data_u8 = BMI160_INIT_VALUE;
  12587. /* check the p_bmi160 structure for NULL pointer assignment*/
  12588. if (p_bmi160 == BMI160_NULL) {
  12589. return E_BMI160_NULL_PTR;
  12590. } else {
  12591. /* read the Accel offset compensation for x axis*/
  12592. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  12593. p_bmi160->dev_addr,
  12594. BMI160_USER_FOC_ACCEL_X__REG,
  12595. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12596. *v_foc_accel_x_u8 = BMI160_GET_BITSLICE(v_data_u8,
  12597. BMI160_USER_FOC_ACCEL_X);
  12598. }
  12599. return com_rslt;
  12600. }
  12601. /*!
  12602. * @brief This API writes Accel offset compensation
  12603. * target value for x-axis in the register 0x69 bit 4 and 5
  12604. *
  12605. * @param v_foc_accel_x_u8 : the value of Accel offset compensation x axis
  12606. * value | Behaviour
  12607. * ----------|-------------------
  12608. * 0x00 | disable
  12609. * 0x01 | +1g
  12610. * 0x01 | -1g
  12611. * 0x01 | 0g
  12612. *
  12613. *
  12614. *
  12615. * @return results of bus communication function
  12616. * @retval 0 -> Success
  12617. * @retval -1 -> Error
  12618. *
  12619. *
  12620. */
  12621. BMI160_RETURN_FUNCTION_TYPE bmi160_set_foc_accel_x(u8 v_foc_accel_x_u8)
  12622. {
  12623. /* variable used to return the status of communication result*/
  12624. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12625. u8 v_data_u8 = BMI160_INIT_VALUE;
  12626. /* check the p_bmi160 structure for NULL pointer assignment*/
  12627. if (p_bmi160 == BMI160_NULL) {
  12628. return E_BMI160_NULL_PTR;
  12629. } else {
  12630. if (v_foc_accel_x_u8 <= BMI160_MAX_ACCEL_FOC) {
  12631. /* write the Accel offset compensation for x axis*/
  12632. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  12633. p_bmi160->dev_addr,
  12634. BMI160_USER_FOC_ACCEL_X__REG,
  12635. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12636. if (com_rslt == SUCCESS) {
  12637. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  12638. BMI160_USER_FOC_ACCEL_X,
  12639. v_foc_accel_x_u8);
  12640. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  12641. p_bmi160->dev_addr,
  12642. BMI160_USER_FOC_ACCEL_X__REG,
  12643. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12644. }
  12645. } else {
  12646. com_rslt = E_BMI160_OUT_OF_RANGE;
  12647. }
  12648. }
  12649. return com_rslt;
  12650. }
  12651. /*!
  12652. * @brief This API writes Accel fast offset compensation
  12653. * from the register 0x69 bit 0 to 5
  12654. * @brief This API writes each axis individually
  12655. * FOC_X_AXIS - bit 4 and 5
  12656. * FOC_Y_AXIS - bit 2 and 3
  12657. * FOC_Z_AXIS - bit 0 and 1
  12658. *
  12659. * @param v_foc_accel_u8: The value of Accel offset compensation
  12660. * value | Behaviour
  12661. * ----------|-------------------
  12662. * 0x00 | disable
  12663. * 0x01 | +1g
  12664. * 0x01 | -1g
  12665. * 0x01 | 0g
  12666. *
  12667. * @param v_axis_u8: The value of Accel offset axis selection
  12668. * value | axis
  12669. * ----------|-------------------
  12670. * 0 | FOC_X_AXIS
  12671. * 1 | FOC_Y_AXIS
  12672. * 2 | FOC_Z_AXIS
  12673. *
  12674. * @param v_accel_offset_s8: The Accel offset value
  12675. *
  12676. * @return results of bus communication function
  12677. * @retval 0 -> Success
  12678. * @retval -1 -> Error
  12679. *
  12680. *
  12681. */
  12682. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_foc_trigger(u8 v_axis_u8,
  12683. u8 v_foc_accel_u8, s8 *v_accel_offset_s8)
  12684. {
  12685. /* variable used to return the status of communication result*/
  12686. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12687. u8 v_data_u8 = BMI160_INIT_VALUE;
  12688. s8 v_status_s8 = SUCCESS;
  12689. u8 v_timeout_u8 = BMI160_INIT_VALUE;
  12690. s8 v_foc_accel_offset_x_s8 = BMI160_INIT_VALUE;
  12691. s8 v_foc_accel_offset_y_s8 = BMI160_INIT_VALUE;
  12692. s8 v_foc_accel_offset_z_s8 = BMI160_INIT_VALUE;
  12693. u8 focstatus = BMI160_INIT_VALUE;
  12694. /* check the p_bmi160 structure for NULL pointer assignment*/
  12695. if (p_bmi160 == BMI160_NULL) {
  12696. return E_BMI160_NULL_PTR;
  12697. } else {
  12698. v_status_s8 = bmi160_set_accel_offset_enable(
  12699. ACCEL_OFFSET_ENABLE);
  12700. if (v_status_s8 == SUCCESS) {
  12701. switch (v_axis_u8) {
  12702. case FOC_X_AXIS:
  12703. com_rslt =
  12704. p_bmi160->BMI160_BUS_READ_FUNC(
  12705. p_bmi160->dev_addr,
  12706. BMI160_USER_FOC_ACCEL_X__REG,
  12707. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12708. if (com_rslt == SUCCESS) {
  12709. v_data_u8 =
  12710. BMI160_SET_BITSLICE(v_data_u8,
  12711. BMI160_USER_FOC_ACCEL_X,
  12712. v_foc_accel_u8);
  12713. com_rslt +=
  12714. p_bmi160->BMI160_BUS_WRITE_FUNC(
  12715. p_bmi160->dev_addr,
  12716. BMI160_USER_FOC_ACCEL_X__REG,
  12717. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12718. }
  12719. /* trigger the FOC */
  12720. com_rslt +=
  12721. bmi160_set_command_register(
  12722. START_FOC_ACCEL_GYRO);
  12723. com_rslt +=
  12724. bmi160_get_foc_rdy(&focstatus);
  12725. if ((com_rslt != SUCCESS) ||
  12726. (focstatus != BMI160_FOC_STAT_HIGH)) {
  12727. while ((com_rslt != SUCCESS) ||
  12728. (focstatus != BMI160_FOC_STAT_HIGH
  12729. && v_timeout_u8 <
  12730. BMI160_MAXIMUM_TIMEOUT)) {
  12731. p_bmi160->delay_msec(
  12732. BMI160_DELAY_SETTLING_TIME);
  12733. com_rslt = bmi160_get_foc_rdy(
  12734. &focstatus);
  12735. v_timeout_u8++;
  12736. }
  12737. }
  12738. if ((com_rslt == SUCCESS) &&
  12739. (focstatus == BMI160_FOC_STAT_HIGH)) {
  12740. com_rslt +=
  12741. bmi160_get_accel_offset_compensation_xaxis(
  12742. &v_foc_accel_offset_x_s8);
  12743. *v_accel_offset_s8 =
  12744. v_foc_accel_offset_x_s8;
  12745. }
  12746. break;
  12747. case FOC_Y_AXIS:
  12748. com_rslt =
  12749. p_bmi160->BMI160_BUS_READ_FUNC(
  12750. p_bmi160->dev_addr,
  12751. BMI160_USER_FOC_ACCEL_Y__REG,
  12752. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12753. if (com_rslt == SUCCESS) {
  12754. v_data_u8 =
  12755. BMI160_SET_BITSLICE(v_data_u8,
  12756. BMI160_USER_FOC_ACCEL_Y,
  12757. v_foc_accel_u8);
  12758. com_rslt +=
  12759. p_bmi160->BMI160_BUS_WRITE_FUNC(
  12760. p_bmi160->dev_addr,
  12761. BMI160_USER_FOC_ACCEL_Y__REG,
  12762. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12763. }
  12764. /* trigger the FOC */
  12765. com_rslt +=
  12766. bmi160_set_command_register(
  12767. START_FOC_ACCEL_GYRO);
  12768. com_rslt +=
  12769. bmi160_get_foc_rdy(&focstatus);
  12770. if ((com_rslt != SUCCESS) ||
  12771. (focstatus != BMI160_FOC_STAT_HIGH)) {
  12772. while ((com_rslt != SUCCESS) ||
  12773. (focstatus != BMI160_FOC_STAT_HIGH
  12774. && v_timeout_u8 <
  12775. BMI160_MAXIMUM_TIMEOUT)) {
  12776. p_bmi160->delay_msec(
  12777. BMI160_DELAY_SETTLING_TIME);
  12778. com_rslt = bmi160_get_foc_rdy(
  12779. &focstatus);
  12780. v_timeout_u8++;
  12781. }
  12782. }
  12783. if ((com_rslt == SUCCESS) &&
  12784. (focstatus == BMI160_FOC_STAT_HIGH)) {
  12785. com_rslt +=
  12786. bmi160_get_accel_offset_compensation_yaxis(
  12787. &v_foc_accel_offset_y_s8);
  12788. *v_accel_offset_s8 =
  12789. v_foc_accel_offset_y_s8;
  12790. }
  12791. break;
  12792. case FOC_Z_AXIS:
  12793. com_rslt =
  12794. p_bmi160->BMI160_BUS_READ_FUNC(
  12795. p_bmi160->dev_addr,
  12796. BMI160_USER_FOC_ACCEL_Z__REG,
  12797. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12798. if (com_rslt == SUCCESS) {
  12799. v_data_u8 =
  12800. BMI160_SET_BITSLICE(v_data_u8,
  12801. BMI160_USER_FOC_ACCEL_Z,
  12802. v_foc_accel_u8);
  12803. com_rslt +=
  12804. p_bmi160->BMI160_BUS_WRITE_FUNC(
  12805. p_bmi160->dev_addr,
  12806. BMI160_USER_FOC_ACCEL_Z__REG,
  12807. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12808. }
  12809. /* trigger the FOC */
  12810. com_rslt +=
  12811. bmi160_set_command_register(
  12812. START_FOC_ACCEL_GYRO);
  12813. com_rslt +=
  12814. bmi160_get_foc_rdy(&focstatus);
  12815. if ((com_rslt != SUCCESS) ||
  12816. (focstatus != BMI160_FOC_STAT_HIGH)) {
  12817. while ((com_rslt != SUCCESS) ||
  12818. (focstatus != BMI160_FOC_STAT_HIGH
  12819. && v_timeout_u8 <
  12820. BMI160_MAXIMUM_TIMEOUT)) {
  12821. p_bmi160->delay_msec(
  12822. BMI160_DELAY_SETTLING_TIME);
  12823. com_rslt = bmi160_get_foc_rdy(
  12824. &focstatus);
  12825. v_timeout_u8++;
  12826. }
  12827. }
  12828. if ((com_rslt == SUCCESS) &&
  12829. (focstatus == BMI160_FOC_STAT_HIGH)) {
  12830. com_rslt +=
  12831. bmi160_get_accel_offset_compensation_zaxis(
  12832. &v_foc_accel_offset_z_s8);
  12833. *v_accel_offset_s8 =
  12834. v_foc_accel_offset_z_s8;
  12835. }
  12836. break;
  12837. default:
  12838. break;
  12839. }
  12840. } else {
  12841. com_rslt = ERROR;
  12842. }
  12843. }
  12844. return com_rslt;
  12845. }
  12846. /*!
  12847. * @brief This API writes fast Accel offset compensation
  12848. * for all axis in the register 0x69 bit 0 to 5
  12849. * FOC_X_AXIS - bit 4 and 5
  12850. * FOC_Y_AXIS - bit 2 and 3
  12851. * FOC_Z_AXIS - bit 0 and 1
  12852. *
  12853. * @param v_foc_accel_x_u8: The value of Accel offset x compensation
  12854. * value | Behaviour
  12855. * ----------|-------------------
  12856. * 0x00 | disable
  12857. * 0x01 | +1g
  12858. * 0x01 | -1g
  12859. * 0x01 | 0g
  12860. *
  12861. * @param v_foc_accel_y_u8: The value of Accel offset y compensation
  12862. * value | Behaviour
  12863. * ----------|-------------------
  12864. * 0x00 | disable
  12865. * 0x01 | +1g
  12866. * 0x01 | -1g
  12867. * 0x01 | 0g
  12868. *
  12869. * @param v_foc_accel_z_u8: The value of Accel offset z compensation
  12870. * value | Behaviour
  12871. * ----------|-------------------
  12872. * 0x00 | disable
  12873. * 0x01 | +1g
  12874. * 0x01 | -1g
  12875. * 0x01 | 0g
  12876. *
  12877. * @param v_accel_off_x_s8: The value of Accel offset x axis
  12878. * @param v_accel_off_y_s8: The value of Accel offset y axis
  12879. * @param v_accel_off_z_s8: The value of Accel offset z axis
  12880. *
  12881. *
  12882. * @return results of bus communication function
  12883. * @retval 0 -> Success
  12884. * @retval -1 -> Error
  12885. *
  12886. */
  12887. BMI160_RETURN_FUNCTION_TYPE bmi160_accel_foc_trigger_xyz(u8 v_foc_accel_x_u8,
  12888. u8 v_foc_accel_y_u8, u8 v_foc_accel_z_u8, s8 *v_accel_off_x_s8,
  12889. s8 *v_accel_off_y_s8, s8 *v_accel_off_z_s8)
  12890. {
  12891. /* variable used to return the status of communication result*/
  12892. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12893. u8 focx = BMI160_INIT_VALUE;
  12894. u8 focy = BMI160_INIT_VALUE;
  12895. u8 focz = BMI160_INIT_VALUE;
  12896. s8 v_foc_accel_offset_x_s8 = BMI160_INIT_VALUE;
  12897. s8 v_foc_accel_offset_y_s8 = BMI160_INIT_VALUE;
  12898. s8 v_foc_accel_offset_z_s8 = BMI160_INIT_VALUE;
  12899. u8 v_status_s8 = SUCCESS;
  12900. u8 v_timeout_u8 = BMI160_INIT_VALUE;
  12901. u8 focstatus = BMI160_INIT_VALUE;
  12902. /* check the p_bmi160 structure for NULL pointer assignment*/
  12903. if (p_bmi160 == BMI160_NULL) {
  12904. return E_BMI160_NULL_PTR;
  12905. } else {
  12906. v_status_s8 = bmi160_set_accel_offset_enable(
  12907. ACCEL_OFFSET_ENABLE);
  12908. if (v_status_s8 == SUCCESS) {
  12909. /* foc x axis*/
  12910. com_rslt =
  12911. p_bmi160->BMI160_BUS_READ_FUNC(
  12912. p_bmi160->dev_addr,
  12913. BMI160_USER_FOC_ACCEL_X__REG,
  12914. &focx, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12915. if (com_rslt == SUCCESS) {
  12916. focx = BMI160_SET_BITSLICE(focx,
  12917. BMI160_USER_FOC_ACCEL_X,
  12918. v_foc_accel_x_u8);
  12919. com_rslt +=
  12920. p_bmi160->BMI160_BUS_WRITE_FUNC(
  12921. p_bmi160->dev_addr,
  12922. BMI160_USER_FOC_ACCEL_X__REG,
  12923. &focx, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12924. }
  12925. /* foc y axis*/
  12926. com_rslt +=
  12927. p_bmi160->BMI160_BUS_READ_FUNC(
  12928. p_bmi160->dev_addr,
  12929. BMI160_USER_FOC_ACCEL_Y__REG,
  12930. &focy, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12931. if (com_rslt == SUCCESS) {
  12932. focy = BMI160_SET_BITSLICE(focy,
  12933. BMI160_USER_FOC_ACCEL_Y,
  12934. v_foc_accel_y_u8);
  12935. com_rslt +=
  12936. p_bmi160->BMI160_BUS_WRITE_FUNC(
  12937. p_bmi160->dev_addr,
  12938. BMI160_USER_FOC_ACCEL_Y__REG,
  12939. &focy, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12940. }
  12941. /* foc z axis*/
  12942. com_rslt +=
  12943. p_bmi160->BMI160_BUS_READ_FUNC(
  12944. p_bmi160->dev_addr,
  12945. BMI160_USER_FOC_ACCEL_Z__REG,
  12946. &focz, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12947. if (com_rslt == SUCCESS) {
  12948. focz = BMI160_SET_BITSLICE(focz,
  12949. BMI160_USER_FOC_ACCEL_Z,
  12950. v_foc_accel_z_u8);
  12951. com_rslt +=
  12952. p_bmi160->BMI160_BUS_WRITE_FUNC(
  12953. p_bmi160->dev_addr,
  12954. BMI160_USER_FOC_ACCEL_Z__REG,
  12955. &focz, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  12956. }
  12957. /* trigger the FOC */
  12958. com_rslt += bmi160_set_command_register(
  12959. START_FOC_ACCEL_GYRO);
  12960. com_rslt += bmi160_get_foc_rdy(
  12961. &focstatus);
  12962. if ((com_rslt != SUCCESS) ||
  12963. (focstatus != BMI160_FOC_STAT_HIGH)) {
  12964. while ((com_rslt != SUCCESS) ||
  12965. (focstatus != BMI160_FOC_STAT_HIGH
  12966. && v_timeout_u8 <
  12967. BMI160_MAXIMUM_TIMEOUT)) {
  12968. p_bmi160->delay_msec(
  12969. BMI160_DELAY_SETTLING_TIME);
  12970. com_rslt = bmi160_get_foc_rdy(
  12971. &focstatus);
  12972. v_timeout_u8++;
  12973. }
  12974. }
  12975. if ((com_rslt == SUCCESS) &&
  12976. (focstatus == BMI160_GEN_READ_WRITE_DATA_LENGTH)) {
  12977. com_rslt +=
  12978. bmi160_get_accel_offset_compensation_xaxis(
  12979. &v_foc_accel_offset_x_s8);
  12980. *v_accel_off_x_s8 =
  12981. v_foc_accel_offset_x_s8;
  12982. com_rslt +=
  12983. bmi160_get_accel_offset_compensation_yaxis(
  12984. &v_foc_accel_offset_y_s8);
  12985. *v_accel_off_y_s8 =
  12986. v_foc_accel_offset_y_s8;
  12987. com_rslt +=
  12988. bmi160_get_accel_offset_compensation_zaxis(
  12989. &v_foc_accel_offset_z_s8);
  12990. *v_accel_off_z_s8 =
  12991. v_foc_accel_offset_z_s8;
  12992. }
  12993. } else {
  12994. com_rslt = ERROR;
  12995. }
  12996. }
  12997. return com_rslt;
  12998. }
  12999. /*!
  13000. * @brief This API reads the gyro fast offset enable
  13001. * from the register 0x69 bit 6
  13002. *
  13003. * @param v_foc_gyro_u8 : The value of gyro fast offset enable
  13004. * value | Description
  13005. * ----------|-------------
  13006. * 0 | fast offset compensation disabled
  13007. * 1 | fast offset compensation enabled
  13008. *
  13009. *
  13010. *
  13011. * @return results of bus communication function
  13012. * @retval 0 -> Success
  13013. * @retval -1 -> Error
  13014. *
  13015. *
  13016. */
  13017. BMI160_RETURN_FUNCTION_TYPE bmi160_get_foc_gyro_enable(
  13018. u8 *v_foc_gyro_u8)
  13019. {
  13020. /* used to return the status of bus communication */
  13021. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13022. u8 v_data_u8 = BMI160_INIT_VALUE;
  13023. /* check the p_bmi160 structure for NULL pointer assignment*/
  13024. if (p_bmi160 == BMI160_NULL) {
  13025. return E_BMI160_NULL_PTR;
  13026. } else {
  13027. /* read the gyro fast offset enable*/
  13028. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13029. p_bmi160->dev_addr,
  13030. BMI160_USER_FOC_GYRO_ENABLE__REG,
  13031. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13032. *v_foc_gyro_u8 = BMI160_GET_BITSLICE(v_data_u8,
  13033. BMI160_USER_FOC_GYRO_ENABLE);
  13034. }
  13035. return com_rslt;
  13036. }
  13037. /*!
  13038. * @brief This API writes the gyro fast offset enable
  13039. * from the register 0x69 bit 6
  13040. *
  13041. * @param v_foc_gyro_u8 : The value of gyro fast offset enable
  13042. * value | Description
  13043. * ----------|-------------
  13044. * 0 | fast offset compensation disabled
  13045. * 1 | fast offset compensation enabled
  13046. *
  13047. * @param v_gyro_off_x_s16 : The value of gyro fast offset x axis data
  13048. * @param v_gyro_off_y_s16 : The value of gyro fast offset y axis data
  13049. * @param v_gyro_off_z_s16 : The value of gyro fast offset z axis data
  13050. *
  13051. * @return results of bus communication function
  13052. * @retval 0 -> Success
  13053. * @retval -1 -> Error
  13054. *
  13055. *
  13056. */
  13057. BMI160_RETURN_FUNCTION_TYPE bmi160_set_foc_gyro_enable(
  13058. u8 v_foc_gyro_u8, s16 *v_gyro_off_x_s16,
  13059. s16 *v_gyro_off_y_s16, s16 *v_gyro_off_z_s16)
  13060. {
  13061. /* variable used to return the status of communication result*/
  13062. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13063. u8 v_data_u8 = BMI160_INIT_VALUE;
  13064. u8 v_status_s8 = SUCCESS;
  13065. u8 v_timeout_u8 = BMI160_INIT_VALUE;
  13066. s16 offsetx = BMI160_INIT_VALUE;
  13067. s16 offsety = BMI160_INIT_VALUE;
  13068. s16 offsetz = BMI160_INIT_VALUE;
  13069. u8 focstatus = BMI160_INIT_VALUE;
  13070. /* check the p_bmi160 structure for NULL pointer assignment*/
  13071. if (p_bmi160 == BMI160_NULL) {
  13072. return E_BMI160_NULL_PTR;
  13073. } else {
  13074. v_status_s8 = bmi160_set_gyro_offset_enable(
  13075. GYRO_OFFSET_ENABLE);
  13076. if (v_status_s8 == SUCCESS) {
  13077. com_rslt =
  13078. p_bmi160->BMI160_BUS_READ_FUNC
  13079. (p_bmi160->dev_addr,
  13080. BMI160_USER_FOC_GYRO_ENABLE__REG,
  13081. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13082. if (com_rslt == SUCCESS) {
  13083. v_data_u8 =
  13084. BMI160_SET_BITSLICE(v_data_u8,
  13085. BMI160_USER_FOC_GYRO_ENABLE,
  13086. v_foc_gyro_u8);
  13087. com_rslt +=
  13088. p_bmi160->BMI160_BUS_WRITE_FUNC
  13089. (p_bmi160->dev_addr,
  13090. BMI160_USER_FOC_GYRO_ENABLE__REG,
  13091. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13092. }
  13093. /* trigger the FOC */
  13094. com_rslt += bmi160_set_command_register
  13095. (START_FOC_ACCEL_GYRO);
  13096. com_rslt += bmi160_get_foc_rdy(&focstatus);
  13097. if ((com_rslt != SUCCESS) ||
  13098. (focstatus != BMI160_FOC_STAT_HIGH)) {
  13099. while ((com_rslt != SUCCESS) ||
  13100. (focstatus != BMI160_FOC_STAT_HIGH
  13101. && v_timeout_u8 <
  13102. BMI160_MAXIMUM_TIMEOUT)) {
  13103. p_bmi160->delay_msec(
  13104. BMI160_DELAY_SETTLING_TIME);
  13105. com_rslt = bmi160_get_foc_rdy(
  13106. &focstatus);
  13107. v_timeout_u8++;
  13108. }
  13109. }
  13110. if ((com_rslt == SUCCESS) &&
  13111. (focstatus == BMI160_FOC_STAT_HIGH)) {
  13112. com_rslt +=
  13113. bmi160_get_gyro_offset_compensation_xaxis
  13114. (&offsetx);
  13115. *v_gyro_off_x_s16 = offsetx;
  13116. com_rslt +=
  13117. bmi160_get_gyro_offset_compensation_yaxis
  13118. (&offsety);
  13119. *v_gyro_off_y_s16 = offsety;
  13120. com_rslt +=
  13121. bmi160_get_gyro_offset_compensation_zaxis(
  13122. &offsetz);
  13123. *v_gyro_off_z_s16 = offsetz;
  13124. }
  13125. } else {
  13126. com_rslt = ERROR;
  13127. }
  13128. }
  13129. return com_rslt;
  13130. }
  13131. /*!
  13132. * @brief This API reads SPI
  13133. * Interface Mode for primary and OIS interface
  13134. * from the register 0x6B bit 0
  13135. *
  13136. * @param v_spi3_u8 : The value of SPI mode selection
  13137. * Value | Description
  13138. * --------|-------------
  13139. * 0 | SPI 4-wire mode
  13140. * 1 | SPI 3-wire mode
  13141. *
  13142. *
  13143. * @return results of bus communication function
  13144. * @retval 0 -> Success
  13145. * @retval -1 -> Error
  13146. *
  13147. *
  13148. */
  13149. BMI160_RETURN_FUNCTION_TYPE bmi160_get_spi3(
  13150. u8 *v_spi3_u8)
  13151. {
  13152. /* variable used to return the status of communication result*/
  13153. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13154. u8 v_data_u8 = BMI160_INIT_VALUE;
  13155. /* check the p_bmi160 structure for NULL pointer assignment*/
  13156. if (p_bmi160 == BMI160_NULL) {
  13157. return E_BMI160_NULL_PTR;
  13158. } else {
  13159. /* read SPI mode*/
  13160. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13161. p_bmi160->dev_addr,
  13162. BMI160_USER_IF_CONFIG_SPI3__REG,
  13163. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13164. *v_spi3_u8 = BMI160_GET_BITSLICE(v_data_u8,
  13165. BMI160_USER_IF_CONFIG_SPI3);
  13166. }
  13167. return com_rslt;
  13168. }
  13169. /*!
  13170. * @brief This API configures SPI
  13171. * Interface Mode for primary and OIS interface
  13172. * in the register 0x6B bit 0
  13173. *
  13174. * @param v_spi3_u8 : The value of SPI mode selection
  13175. * Value | Description
  13176. * --------|-------------
  13177. * 0 | SPI 4-wire mode
  13178. * 1 | SPI 3-wire mode
  13179. *
  13180. *
  13181. * @return results of bus communication function
  13182. * @retval 0 -> Success
  13183. * @retval -1 -> Error
  13184. *
  13185. *
  13186. */
  13187. BMI160_RETURN_FUNCTION_TYPE bmi160_set_spi3(
  13188. u8 v_spi3_u8)
  13189. {
  13190. /* variable used to return the status of communication result*/
  13191. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13192. u8 v_data_u8 = BMI160_INIT_VALUE;
  13193. /* check the p_bmi160 structure for NULL pointer assignment*/
  13194. if (p_bmi160 == BMI160_NULL) {
  13195. return E_BMI160_NULL_PTR;
  13196. } else {
  13197. if (v_spi3_u8 <= BMI160_MAX_VALUE_SPI3) {
  13198. /* write SPI mode*/
  13199. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13200. p_bmi160->dev_addr,
  13201. BMI160_USER_IF_CONFIG_SPI3__REG,
  13202. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13203. if (com_rslt == SUCCESS) {
  13204. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  13205. BMI160_USER_IF_CONFIG_SPI3,
  13206. v_spi3_u8);
  13207. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  13208. p_bmi160->dev_addr,
  13209. BMI160_USER_IF_CONFIG_SPI3__REG,
  13210. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13211. /*Accel and Gyro power mode check*/
  13212. if (bmi160_power_mode_status_u8_g !=
  13213. BMI160_NORMAL_MODE)
  13214. /*interface idle time delay */
  13215. p_bmi160->delay_msec(
  13216. BMI160_GEN_READ_WRITE_DELAY);
  13217. }
  13218. } else {
  13219. com_rslt = E_BMI160_OUT_OF_RANGE;
  13220. }
  13221. }
  13222. return com_rslt;
  13223. }
  13224. /*!
  13225. * @brief This API reads I2C Watchdog timer
  13226. * from the register 0x70 bit 1
  13227. *
  13228. * @param v_i2c_wdt_u8 : The value of I2C watch dog timer
  13229. * Value | Description
  13230. * --------|-------------
  13231. * 0 | I2C watchdog v_timeout_u8 after 1 ms
  13232. * 1 | I2C watchdog v_timeout_u8 after 50 ms
  13233. *
  13234. *
  13235. * @return results of bus communication function
  13236. * @retval 0 -> Success
  13237. * @retval -1 -> Error
  13238. *
  13239. *
  13240. */
  13241. BMI160_RETURN_FUNCTION_TYPE bmi160_get_i2c_wdt_select(
  13242. u8 *v_i2c_wdt_u8)
  13243. {
  13244. /* variable used to return the status of communication result*/
  13245. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13246. u8 v_data_u8 = BMI160_INIT_VALUE;
  13247. /* check the p_bmi160 structure for NULL pointer assignment*/
  13248. if (p_bmi160 == BMI160_NULL) {
  13249. return E_BMI160_NULL_PTR;
  13250. } else {
  13251. /* read I2C watch dog timer */
  13252. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13253. p_bmi160->dev_addr,
  13254. BMI160_USER_IF_CONFIG_I2C_WDT_SELECT__REG,
  13255. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13256. *v_i2c_wdt_u8 = BMI160_GET_BITSLICE(v_data_u8,
  13257. BMI160_USER_IF_CONFIG_I2C_WDT_SELECT);
  13258. }
  13259. return com_rslt;
  13260. }
  13261. /*!
  13262. * @brief This API writes the I2C Watchdog timer
  13263. * in the register 0x70 bit 1
  13264. *
  13265. * @param v_i2c_wdt_u8 : The value of I2C watch dog timer
  13266. * Value | Description
  13267. * --------|-------------
  13268. * 0 | I2C watchdog v_timeout_u8 after 1 ms
  13269. * 1 | I2C watchdog v_timeout_u8 after 50 ms
  13270. *
  13271. *
  13272. * @return results of bus communication function
  13273. * @retval 0 -> Success
  13274. * @retval -1 -> Error
  13275. *
  13276. *
  13277. */
  13278. BMI160_RETURN_FUNCTION_TYPE bmi160_set_i2c_wdt_select(
  13279. u8 v_i2c_wdt_u8)
  13280. {
  13281. /* variable used to return the status of communication result*/
  13282. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13283. u8 v_data_u8 = BMI160_INIT_VALUE;
  13284. /* check the p_bmi160 structure for NULL pointer assignment*/
  13285. if (p_bmi160 == BMI160_NULL) {
  13286. return E_BMI160_NULL_PTR;
  13287. } else {
  13288. if (v_i2c_wdt_u8 <= BMI160_MAX_VALUE_I2C_WDT) {
  13289. /* write I2C watch dog timer */
  13290. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13291. p_bmi160->dev_addr,
  13292. BMI160_USER_IF_CONFIG_I2C_WDT_SELECT__REG,
  13293. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13294. if (com_rslt == SUCCESS) {
  13295. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  13296. BMI160_USER_IF_CONFIG_I2C_WDT_SELECT,
  13297. v_i2c_wdt_u8);
  13298. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  13299. p_bmi160->dev_addr,
  13300. BMI160_USER_IF_CONFIG_I2C_WDT_SELECT__REG,
  13301. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13302. /*Accel and Gyro power mode check*/
  13303. if (bmi160_power_mode_status_u8_g !=
  13304. BMI160_NORMAL_MODE)
  13305. /*interface idle time delay */
  13306. p_bmi160->delay_msec(
  13307. BMI160_GEN_READ_WRITE_DELAY);
  13308. }
  13309. } else {
  13310. com_rslt = E_BMI160_OUT_OF_RANGE;
  13311. }
  13312. }
  13313. return com_rslt;
  13314. }
  13315. /*!
  13316. * @brief This API reads the status of I2C watchdog enable
  13317. * from the register 0x70 bit 2
  13318. *
  13319. * @param v_i2c_wdt_u8 : The value of I2C watchdog enable
  13320. * Value | Description
  13321. * --------|-------------
  13322. * 0 | DISABLE
  13323. * 1 | ENABLE
  13324. *
  13325. * @return results of bus communication function
  13326. * @retval 0 -> Success
  13327. * @retval -1 -> Error
  13328. *
  13329. *
  13330. */
  13331. BMI160_RETURN_FUNCTION_TYPE bmi160_get_i2c_wdt_enable(
  13332. u8 *v_i2c_wdt_u8)
  13333. {
  13334. /* variable used to return the status of communication result*/
  13335. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13336. u8 v_data_u8 = BMI160_INIT_VALUE;
  13337. /* check the p_bmi160 structure for NULL pointer assignment*/
  13338. if (p_bmi160 == BMI160_NULL) {
  13339. return E_BMI160_NULL_PTR;
  13340. } else {
  13341. /* read i2c watch dog enable */
  13342. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13343. p_bmi160->dev_addr,
  13344. BMI160_USER_IF_CONFIG_I2C_WDT_ENABLE__REG,
  13345. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13346. *v_i2c_wdt_u8 = BMI160_GET_BITSLICE(v_data_u8,
  13347. BMI160_USER_IF_CONFIG_I2C_WDT_ENABLE);
  13348. }
  13349. return com_rslt;
  13350. }
  13351. /*!
  13352. * @brief This API enables the I2C watchdog
  13353. * in the register 0x70 bit 2
  13354. *
  13355. * @param v_i2c_wdt_u8 : The value of I2C watchdog enable
  13356. * Value | Description
  13357. * --------|-------------
  13358. * 0 | DISABLE
  13359. * 1 | ENABLE
  13360. *
  13361. * @return results of bus communication function
  13362. * @retval 0 -> Success
  13363. * @retval -1 -> Error
  13364. *
  13365. *
  13366. */
  13367. BMI160_RETURN_FUNCTION_TYPE bmi160_set_i2c_wdt_enable(
  13368. u8 v_i2c_wdt_u8)
  13369. {
  13370. /* variable used to return the status of communication result*/
  13371. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13372. u8 v_data_u8 = BMI160_INIT_VALUE;
  13373. /* check the p_bmi160 structure for NULL pointer assignment*/
  13374. if (p_bmi160 == BMI160_NULL) {
  13375. return E_BMI160_NULL_PTR;
  13376. } else {
  13377. if (v_i2c_wdt_u8 <= BMI160_MAX_VALUE_I2C_WDT) {
  13378. /* write i2c watch dog enable */
  13379. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13380. p_bmi160->dev_addr,
  13381. BMI160_USER_IF_CONFIG_I2C_WDT_ENABLE__REG,
  13382. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13383. if (com_rslt == SUCCESS) {
  13384. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  13385. BMI160_USER_IF_CONFIG_I2C_WDT_ENABLE,
  13386. v_i2c_wdt_u8);
  13387. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  13388. p_bmi160->dev_addr,
  13389. BMI160_USER_IF_CONFIG_I2C_WDT_ENABLE__REG,
  13390. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13391. /*Accel and Gyro power mode check*/
  13392. if (bmi160_power_mode_status_u8_g !=
  13393. BMI160_NORMAL_MODE)
  13394. /*interface idle time delay */
  13395. p_bmi160->delay_msec(
  13396. BMI160_GEN_READ_WRITE_DELAY);
  13397. }
  13398. } else {
  13399. com_rslt = E_BMI160_OUT_OF_RANGE;
  13400. }
  13401. }
  13402. return com_rslt;
  13403. }
  13404. /*!
  13405. * @brief This API reads the I2C interface configuration(if) mode
  13406. * from the register 0x6B bit 4 and 5
  13407. *
  13408. * @param v_if_mode_u8 : The value of interface configuration mode
  13409. * Value | Description
  13410. * --------|-------------
  13411. * 0x00 | Primary interface:autoconfig / secondary interface:off
  13412. * 0x01 | Primary interface:I2C / secondary interface:OIS
  13413. * 0x02 | Primary interface:autoconfig/secondary interface:Mag
  13414. * 0x03 | Reserved
  13415. *
  13416. *
  13417. * @return results of bus communication function
  13418. * @retval 0 -> Success
  13419. * @retval -1 -> Error
  13420. *
  13421. *
  13422. */
  13423. BMI160_RETURN_FUNCTION_TYPE bmi160_get_if_mode(
  13424. u8 *v_if_mode_u8)
  13425. {
  13426. /* variable used to return the status of communication result*/
  13427. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13428. u8 v_data_u8 = BMI160_INIT_VALUE;
  13429. /* check the p_bmi160 structure for NULL pointer assignment*/
  13430. if (p_bmi160 == BMI160_NULL) {
  13431. return E_BMI160_NULL_PTR;
  13432. } else {
  13433. /* read if mode*/
  13434. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13435. p_bmi160->dev_addr,
  13436. BMI160_USER_IF_CONFIG_IF_MODE__REG,
  13437. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13438. *v_if_mode_u8 = BMI160_GET_BITSLICE(v_data_u8,
  13439. BMI160_USER_IF_CONFIG_IF_MODE);
  13440. }
  13441. return com_rslt;
  13442. }
  13443. /*!
  13444. * @brief This API writes the I2C interface configuration(if) mode
  13445. * in the register 0x6B bit 4 and 5
  13446. *
  13447. * @param v_if_mode_u8 : The value of interface configuration mode
  13448. * Value | Description
  13449. * --------|-------------
  13450. * 0x00 | Primary interface:autoconfig / secondary interface:off
  13451. * 0x01 | Primary interface:I2C / secondary interface:OIS
  13452. * 0x02 | Primary interface:autoconfig/secondary interface:Mag
  13453. * 0x03 | Reserved
  13454. *
  13455. *
  13456. * @return results of bus communication function
  13457. * @retval 0 -> Success
  13458. * @retval -1 -> Error
  13459. *
  13460. *
  13461. */
  13462. BMI160_RETURN_FUNCTION_TYPE bmi160_set_if_mode(
  13463. u8 v_if_mode_u8)
  13464. {
  13465. /* variable used to return the status of communication result*/
  13466. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13467. u8 v_data_u8 = BMI160_INIT_VALUE;
  13468. /* check the p_bmi160 structure for NULL pointer assignment*/
  13469. if (p_bmi160 == BMI160_NULL) {
  13470. return E_BMI160_NULL_PTR;
  13471. } else {
  13472. if (v_if_mode_u8 <= BMI160_MAX_IF_MODE) {
  13473. /* write if mode*/
  13474. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13475. p_bmi160->dev_addr,
  13476. BMI160_USER_IF_CONFIG_IF_MODE__REG,
  13477. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13478. if (com_rslt == SUCCESS) {
  13479. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  13480. BMI160_USER_IF_CONFIG_IF_MODE,
  13481. v_if_mode_u8);
  13482. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  13483. p_bmi160->dev_addr,
  13484. BMI160_USER_IF_CONFIG_IF_MODE__REG,
  13485. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13486. /*Accel and Gyro power mode check*/
  13487. if (bmi160_power_mode_status_u8_g !=
  13488. BMI160_NORMAL_MODE)
  13489. /*interface idle time delay */
  13490. p_bmi160->delay_msec(
  13491. BMI160_GEN_READ_WRITE_DELAY);
  13492. }
  13493. } else {
  13494. com_rslt = E_BMI160_OUT_OF_RANGE;
  13495. }
  13496. }
  13497. return com_rslt;
  13498. }
  13499. /*!
  13500. * @brief This API reads the gyro sleep trigger
  13501. * from the register 0x6C bit 0 to 2
  13502. *
  13503. * @param v_gyro_sleep_trigger_u8 : The value of gyro sleep trigger
  13504. * Value | Description
  13505. * --------|-------------
  13506. * 0x00 | nomotion: no / Not INT1 pin: no / INT2 pin: no
  13507. * 0x01 | nomotion: no / Not INT1 pin: no / INT2 pin: yes
  13508. * 0x02 | nomotion: no / Not INT1 pin: yes / INT2 pin: no
  13509. * 0x03 | nomotion: no / Not INT1 pin: yes / INT2 pin: yes
  13510. * 0x04 | nomotion: yes / Not INT1 pin: no / INT2 pin: no
  13511. * 0x05 | anymotion: yes / Not INT1 pin: no / INT2 pin: yes
  13512. * 0x06 | anymotion: yes / Not INT1 pin: yes / INT2 pin: no
  13513. * 0x07 | anymotion: yes / Not INT1 pin: yes / INT2 pin: yes
  13514. *
  13515. *
  13516. *
  13517. * @return results of bus communication function
  13518. * @retval 0 -> Success
  13519. * @retval -1 -> Error
  13520. *
  13521. *
  13522. */
  13523. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_sleep_trigger(
  13524. u8 *v_gyro_sleep_trigger_u8)
  13525. {
  13526. /* variable used to return the status of communication result*/
  13527. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13528. u8 v_data_u8 = BMI160_INIT_VALUE;
  13529. /* check the p_bmi160 structure for NULL pointer assignment*/
  13530. if (p_bmi160 == BMI160_NULL) {
  13531. return E_BMI160_NULL_PTR;
  13532. } else {
  13533. /* read gyro sleep trigger */
  13534. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13535. p_bmi160->dev_addr,
  13536. BMI160_USER_GYRO_SLEEP_TRIGGER__REG,
  13537. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13538. *v_gyro_sleep_trigger_u8 =
  13539. BMI160_GET_BITSLICE(v_data_u8,
  13540. BMI160_USER_GYRO_SLEEP_TRIGGER);
  13541. }
  13542. return com_rslt;
  13543. }
  13544. /*!
  13545. * @brief This API writes the gyro sleep trigger
  13546. * in the register 0x6C bit 0 to 2
  13547. *
  13548. * @param v_gyro_sleep_trigger_u8 : The value of gyro sleep trigger
  13549. * Value | Description
  13550. * --------|-------------
  13551. * 0x00 | nomotion: no / Not INT1 pin: no / INT2 pin: no
  13552. * 0x01 | nomotion: no / Not INT1 pin: no / INT2 pin: yes
  13553. * 0x02 | nomotion: no / Not INT1 pin: yes / INT2 pin: no
  13554. * 0x03 | nomotion: no / Not INT1 pin: yes / INT2 pin: yes
  13555. * 0x04 | nomotion: yes / Not INT1 pin: no / INT2 pin: no
  13556. * 0x05 | anymotion: yes / Not INT1 pin: no / INT2 pin: yes
  13557. * 0x06 | anymotion: yes / Not INT1 pin: yes / INT2 pin: no
  13558. * 0x07 | anymotion: yes / Not INT1 pin: yes / INT2 pin: yes
  13559. *
  13560. *
  13561. *
  13562. * @return results of bus communication function
  13563. * @retval 0 -> Success
  13564. * @retval -1 -> Error
  13565. *
  13566. *
  13567. */
  13568. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_sleep_trigger(
  13569. u8 v_gyro_sleep_trigger_u8)
  13570. {
  13571. /* variable used to return the status of communication result*/
  13572. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13573. u8 v_data_u8 = BMI160_INIT_VALUE;
  13574. /* check the p_bmi160 structure for NULL pointer assignment*/
  13575. if (p_bmi160 == BMI160_NULL) {
  13576. return E_BMI160_NULL_PTR;
  13577. } else {
  13578. if (v_gyro_sleep_trigger_u8 <= BMI160_MAX_GYRO_SLEEP_TRIGGER) {
  13579. /* write gyro sleep trigger */
  13580. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13581. p_bmi160->dev_addr,
  13582. BMI160_USER_GYRO_SLEEP_TRIGGER__REG,
  13583. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13584. if (com_rslt == SUCCESS) {
  13585. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  13586. BMI160_USER_GYRO_SLEEP_TRIGGER,
  13587. v_gyro_sleep_trigger_u8);
  13588. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  13589. p_bmi160->dev_addr,
  13590. BMI160_USER_GYRO_SLEEP_TRIGGER__REG,
  13591. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13592. /*Accel and Gyro power mode check*/
  13593. if (bmi160_power_mode_status_u8_g !=
  13594. BMI160_NORMAL_MODE)
  13595. /*interface idle time delay */
  13596. p_bmi160->delay_msec(
  13597. BMI160_GEN_READ_WRITE_DELAY);
  13598. }
  13599. } else {
  13600. com_rslt = E_BMI160_OUT_OF_RANGE;
  13601. }
  13602. }
  13603. return com_rslt;
  13604. }
  13605. /*!
  13606. * @brief This API reads gyro wakeup trigger
  13607. * from the register 0x6C bit 3 and 4
  13608. *
  13609. * @param v_gyro_wakeup_trigger_u8 : The value of gyro wakeup trigger
  13610. * Value | Description
  13611. * --------|-------------
  13612. * 0x00 | anymotion: no / INT1 pin: no
  13613. * 0x01 | anymotion: no / INT1 pin: yes
  13614. * 0x02 | anymotion: yes / INT1 pin: no
  13615. * 0x03 | anymotion: yes / INT1 pin: yes
  13616. *
  13617. *
  13618. * @return results of bus communication function
  13619. * @retval 0 -> Success
  13620. * @retval -1 -> Error
  13621. *
  13622. *
  13623. */
  13624. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_wakeup_trigger(
  13625. u8 *v_gyro_wakeup_trigger_u8)
  13626. {
  13627. /* variable used to return the status of communication result*/
  13628. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13629. u8 v_data_u8 = BMI160_INIT_VALUE;
  13630. /* check the p_bmi160 structure for NULL pointer assignment*/
  13631. if (p_bmi160 == BMI160_NULL) {
  13632. return E_BMI160_NULL_PTR;
  13633. } else {
  13634. /* read gyro wakeup trigger */
  13635. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13636. p_bmi160->dev_addr,
  13637. BMI160_USER_GYRO_WAKEUP_TRIGGER__REG,
  13638. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13639. *v_gyro_wakeup_trigger_u8 = BMI160_GET_BITSLICE(
  13640. v_data_u8,
  13641. BMI160_USER_GYRO_WAKEUP_TRIGGER);
  13642. }
  13643. return com_rslt;
  13644. }
  13645. /*!
  13646. * @brief This API writes gyro wakeup trigger
  13647. * in the register 0x6C bit 3 and 4
  13648. *
  13649. * @param v_gyro_wakeup_trigger_u8 : The value of gyro wakeup trigger
  13650. * Value | Description
  13651. * --------|-------------
  13652. * 0x00 | anymotion: no / INT1 pin: no
  13653. * 0x01 | anymotion: no / INT1 pin: yes
  13654. * 0x02 | anymotion: yes / INT1 pin: no
  13655. * 0x03 | anymotion: yes / INT1 pin: yes
  13656. *
  13657. *
  13658. * @return results of bus communication function
  13659. * @retval 0 -> Success
  13660. * @retval -1 -> Error
  13661. *
  13662. *
  13663. */
  13664. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_wakeup_trigger(
  13665. u8 v_gyro_wakeup_trigger_u8)
  13666. {
  13667. /* variable used to return the status of communication result*/
  13668. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13669. u8 v_data_u8 = BMI160_INIT_VALUE;
  13670. /* check the p_bmi160 structure for NULL pointer assignment*/
  13671. if (p_bmi160 == BMI160_NULL) {
  13672. return E_BMI160_NULL_PTR;
  13673. } else {
  13674. if (v_gyro_wakeup_trigger_u8
  13675. <= BMI160_MAX_GYRO_WAKEUP_TRIGGER) {
  13676. /* write gyro wakeup trigger */
  13677. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13678. p_bmi160->dev_addr,
  13679. BMI160_USER_GYRO_WAKEUP_TRIGGER__REG,
  13680. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13681. if (com_rslt == SUCCESS) {
  13682. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  13683. BMI160_USER_GYRO_WAKEUP_TRIGGER,
  13684. v_gyro_wakeup_trigger_u8);
  13685. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  13686. p_bmi160->dev_addr,
  13687. BMI160_USER_GYRO_WAKEUP_TRIGGER__REG,
  13688. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13689. /*Accel and Gyro power mode check*/
  13690. if (bmi160_power_mode_status_u8_g !=
  13691. BMI160_NORMAL_MODE)
  13692. /*interface idle time delay */
  13693. p_bmi160->delay_msec(
  13694. BMI160_GEN_READ_WRITE_DELAY);
  13695. }
  13696. } else {
  13697. com_rslt = E_BMI160_OUT_OF_RANGE;
  13698. }
  13699. }
  13700. return com_rslt;
  13701. }
  13702. /*!
  13703. * @brief This API reads target state for gyro sleep mode
  13704. * from the register 0x6C bit 5
  13705. *
  13706. * @param v_gyro_sleep_state_u8 : The value of gyro sleep mode
  13707. * Value | Description
  13708. * --------|-------------
  13709. * 0x00 | Sleep transition to fast wake up state
  13710. * 0x01 | Sleep transition to suspend state
  13711. *
  13712. *
  13713. * @return results of bus communication function
  13714. * @retval 0 -> Success
  13715. * @retval -1 -> Error
  13716. *
  13717. *
  13718. */
  13719. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_sleep_state(
  13720. u8 *v_gyro_sleep_state_u8)
  13721. {
  13722. /* variable used to return the status of communication result*/
  13723. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13724. u8 v_data_u8 = BMI160_INIT_VALUE;
  13725. /* check the p_bmi160 structure for NULL pointer assignment*/
  13726. if (p_bmi160 == BMI160_NULL) {
  13727. return E_BMI160_NULL_PTR;
  13728. } else {
  13729. /* read gyro sleep state*/
  13730. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13731. p_bmi160->dev_addr,
  13732. BMI160_USER_GYRO_SLEEP_STATE__REG,
  13733. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13734. *v_gyro_sleep_state_u8 = BMI160_GET_BITSLICE(
  13735. v_data_u8,
  13736. BMI160_USER_GYRO_SLEEP_STATE);
  13737. }
  13738. return com_rslt;
  13739. }
  13740. /*!
  13741. * @brief This API writes target state for gyro sleep mode
  13742. * in the register 0x6C bit 5
  13743. *
  13744. * @param v_gyro_sleep_state_u8 : The value of gyro sleep mode
  13745. * Value | Description
  13746. * --------|-------------
  13747. * 0x00 | Sleep transition to fast wake up state
  13748. * 0x01 | Sleep transition to suspend state
  13749. *
  13750. *
  13751. * @return results of bus communication function
  13752. * @retval 0 -> Success
  13753. * @retval -1 -> Error
  13754. *
  13755. *
  13756. */
  13757. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_sleep_state(
  13758. u8 v_gyro_sleep_state_u8)
  13759. {
  13760. /* variable used to return the status of communication result*/
  13761. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13762. u8 v_data_u8 = BMI160_INIT_VALUE;
  13763. /* check the p_bmi160 structure for NULL pointer assignment*/
  13764. if (p_bmi160 == BMI160_NULL) {
  13765. return E_BMI160_NULL_PTR;
  13766. } else {
  13767. if (v_gyro_sleep_state_u8 <= BMI160_MAX_VALUE_SLEEP_STATE) {
  13768. /* write gyro sleep state*/
  13769. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13770. p_bmi160->dev_addr,
  13771. BMI160_USER_GYRO_SLEEP_STATE__REG,
  13772. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13773. if (com_rslt == SUCCESS) {
  13774. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  13775. BMI160_USER_GYRO_SLEEP_STATE,
  13776. v_gyro_sleep_state_u8);
  13777. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  13778. p_bmi160->dev_addr,
  13779. BMI160_USER_GYRO_SLEEP_STATE__REG,
  13780. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13781. /*Accel and Gyro power mode check*/
  13782. if (bmi160_power_mode_status_u8_g !=
  13783. BMI160_NORMAL_MODE)
  13784. /*interface idle time delay */
  13785. p_bmi160->delay_msec(
  13786. BMI160_GEN_READ_WRITE_DELAY);
  13787. }
  13788. } else {
  13789. com_rslt = E_BMI160_OUT_OF_RANGE;
  13790. }
  13791. }
  13792. return com_rslt;
  13793. }
  13794. /*!
  13795. * @brief This API reads gyro wakeup interrupt
  13796. * from the register 0x6C bit 6
  13797. *
  13798. * @param v_gyro_wakeup_intr_u8 : The value of gyro wakeup interrupt
  13799. * Value | Description
  13800. * --------|-------------
  13801. * 0x00 | DISABLE
  13802. * 0x01 | ENABLE
  13803. *
  13804. *
  13805. * @return results of bus communication function
  13806. * @retval 0 -> Success
  13807. * @retval -1 -> Error
  13808. *
  13809. *
  13810. */
  13811. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_wakeup_intr(
  13812. u8 *v_gyro_wakeup_intr_u8)
  13813. {
  13814. /* variable used to return the status of communication result*/
  13815. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13816. u8 v_data_u8 = BMI160_INIT_VALUE;
  13817. /* check the p_bmi160 structure for NULL pointer assignment*/
  13818. if (p_bmi160 == BMI160_NULL) {
  13819. return E_BMI160_NULL_PTR;
  13820. } else {
  13821. /* read gyro wakeup interrupt */
  13822. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13823. p_bmi160->dev_addr,
  13824. BMI160_USER_GYRO_WAKEUP_INTR__REG,
  13825. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13826. *v_gyro_wakeup_intr_u8 = BMI160_GET_BITSLICE(
  13827. v_data_u8,
  13828. BMI160_USER_GYRO_WAKEUP_INTR);
  13829. }
  13830. return com_rslt;
  13831. }
  13832. /*!
  13833. * @brief This API writes gyro wakeup interrupt
  13834. * in the register 0x6C bit 6
  13835. *
  13836. * @param v_gyro_wakeup_intr_u8 : The value of gyro wakeup interrupt
  13837. * Value | Description
  13838. * --------|-------------
  13839. * 0x00 | DISABLE
  13840. * 0x01 | ENABLE
  13841. *
  13842. *
  13843. * @return results of bus communication function
  13844. * @retval 0 -> Success
  13845. * @retval -1 -> Error
  13846. *
  13847. *
  13848. */
  13849. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_wakeup_intr(
  13850. u8 v_gyro_wakeup_intr_u8)
  13851. {
  13852. /* variable used to return the status of communication result*/
  13853. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13854. u8 v_data_u8 = BMI160_INIT_VALUE;
  13855. /* check the p_bmi160 structure for NULL pointer assignment*/
  13856. if (p_bmi160 == BMI160_NULL) {
  13857. return E_BMI160_NULL_PTR;
  13858. } else {
  13859. if (v_gyro_wakeup_intr_u8 <= BMI160_MAX_VALUE_WAKEUP_INTR) {
  13860. /* write gyro wakeup interrupt */
  13861. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13862. p_bmi160->dev_addr,
  13863. BMI160_USER_GYRO_WAKEUP_INTR__REG,
  13864. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13865. if (com_rslt == SUCCESS) {
  13866. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  13867. BMI160_USER_GYRO_WAKEUP_INTR,
  13868. v_gyro_wakeup_intr_u8);
  13869. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  13870. p_bmi160->dev_addr,
  13871. BMI160_USER_GYRO_WAKEUP_INTR__REG,
  13872. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13873. /*Accel and Gyro power mode check*/
  13874. if (bmi160_power_mode_status_u8_g !=
  13875. BMI160_NORMAL_MODE)
  13876. /*interface idle time delay */
  13877. p_bmi160->delay_msec(
  13878. BMI160_GEN_READ_WRITE_DELAY);
  13879. }
  13880. } else {
  13881. com_rslt = E_BMI160_OUT_OF_RANGE;
  13882. }
  13883. }
  13884. return com_rslt;
  13885. }
  13886. /*!
  13887. * @brief This API reads Accel selftest axis selected for self-test
  13888. * functionality.
  13889. *
  13890. * @param v_accel_selftest_axis_u8 :
  13891. * The value of Accel self test axis selection
  13892. * Value | Description
  13893. * --------|-------------
  13894. * 0x00 | disabled
  13895. * 0x01 | x-axis
  13896. * 0x02 | y-axis
  13897. * 0x03 | z-axis
  13898. *
  13899. *
  13900. * @return results of bus communication function
  13901. * @retval 0 -> Success
  13902. * @retval -1 -> Error
  13903. *
  13904. *
  13905. */
  13906. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_selftest_axis(
  13907. u8 *v_accel_selftest_axis_u8)
  13908. {
  13909. /* variable used to return the status of communication result*/
  13910. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13911. u8 v_data_u8 = BMI160_INIT_VALUE;
  13912. /* check the p_bmi160 structure for NULL pointer assignment*/
  13913. if (p_bmi160 == BMI160_NULL) {
  13914. return E_BMI160_NULL_PTR;
  13915. } else {
  13916. /* read Accel self test axis*/
  13917. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13918. p_bmi160->dev_addr,
  13919. BMI160_USER_ACCEL_SELFTEST_AXIS__REG,
  13920. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13921. *v_accel_selftest_axis_u8 = BMI160_GET_BITSLICE(
  13922. v_data_u8,
  13923. BMI160_USER_ACCEL_SELFTEST_AXIS);
  13924. }
  13925. return com_rslt;
  13926. }
  13927. /*!
  13928. * @brief This API writes Accel self test axis for self-test
  13929. * functionality.
  13930. *
  13931. * @param v_accel_selftest_axis_u8 :
  13932. * The value of Accel self test axis selection
  13933. * Value | Description
  13934. * --------|-------------
  13935. * 0x00 | disabled
  13936. * 0x01 | x-axis
  13937. * 0x02 | y-axis
  13938. * 0x03 | z-axis
  13939. *
  13940. *
  13941. * @return results of bus communication function
  13942. * @retval 0 -> Success
  13943. * @retval -1 -> Error
  13944. *
  13945. *
  13946. */
  13947. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_selftest_axis(
  13948. u8 v_accel_selftest_axis_u8)
  13949. {
  13950. /* variable used to return the status of communication result*/
  13951. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13952. u8 v_data_u8 = BMI160_INIT_VALUE;
  13953. /* check the p_bmi160 structure for NULL pointer assignment*/
  13954. if (p_bmi160 == BMI160_NULL) {
  13955. return E_BMI160_NULL_PTR;
  13956. } else {
  13957. if (v_accel_selftest_axis_u8
  13958. <= BMI160_MAX_ACCEL_SELFTEST_AXIS) {
  13959. /* write Accel self test axis*/
  13960. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13961. p_bmi160->dev_addr,
  13962. BMI160_USER_ACCEL_SELFTEST_AXIS__REG,
  13963. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13964. if (com_rslt == SUCCESS) {
  13965. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  13966. BMI160_USER_ACCEL_SELFTEST_AXIS,
  13967. v_accel_selftest_axis_u8);
  13968. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  13969. p_bmi160->dev_addr,
  13970. BMI160_USER_ACCEL_SELFTEST_AXIS__REG,
  13971. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  13972. /*Accel and Gyro power mode check*/
  13973. if (bmi160_power_mode_status_u8_g !=
  13974. BMI160_NORMAL_MODE)
  13975. /*interface idle time delay */
  13976. p_bmi160->delay_msec(
  13977. BMI160_GEN_READ_WRITE_DELAY);
  13978. }
  13979. } else {
  13980. com_rslt = E_BMI160_OUT_OF_RANGE;
  13981. }
  13982. }
  13983. return com_rslt;
  13984. }
  13985. /*!
  13986. * @brief This API reads Accel self test axis sign
  13987. * from the register 0x6D bit 2
  13988. *
  13989. * @param v_accel_selftest_sign_u8: The value of Accel self test axis sign
  13990. * Value | Description
  13991. * --------|-------------
  13992. * 0x00 | negative
  13993. * 0x01 | positive
  13994. *
  13995. *
  13996. * @return results of bus communication function
  13997. * @retval 0 -> Success
  13998. * @retval -1 -> Error
  13999. *
  14000. *
  14001. */
  14002. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_selftest_sign(
  14003. u8 *v_accel_selftest_sign_u8)
  14004. {
  14005. /* variable used to return the status of communication result*/
  14006. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14007. u8 v_data_u8 = BMI160_INIT_VALUE;
  14008. /* check the p_bmi160 structure for NULL pointer assignment*/
  14009. if (p_bmi160 == BMI160_NULL) {
  14010. return E_BMI160_NULL_PTR;
  14011. } else {
  14012. /* read Accel self test axis sign*/
  14013. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14014. p_bmi160->dev_addr,
  14015. BMI160_USER_ACCEL_SELFTEST_SIGN__REG,
  14016. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14017. *v_accel_selftest_sign_u8 = BMI160_GET_BITSLICE(
  14018. v_data_u8,
  14019. BMI160_USER_ACCEL_SELFTEST_SIGN);
  14020. }
  14021. return com_rslt;
  14022. }
  14023. /*!
  14024. * @brief This API writes Accel self test axis sign
  14025. * in the register 0x6D bit 2
  14026. *
  14027. * @param v_accel_selftest_sign_u8: The value of Accel self test axis sign
  14028. * Value | Description
  14029. * --------|-------------
  14030. * 0x00 | negative
  14031. * 0x01 | positive
  14032. *
  14033. *
  14034. * @return results of bus communication function
  14035. * @retval 0 -> Success
  14036. * @retval -1 -> Error
  14037. *
  14038. *
  14039. */
  14040. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_selftest_sign(
  14041. u8 v_accel_selftest_sign_u8)
  14042. {
  14043. /* variable used to return the status of communication result*/
  14044. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14045. u8 v_data_u8 = BMI160_INIT_VALUE;
  14046. /* check the p_bmi160 structure for NULL pointer assignment*/
  14047. if (p_bmi160 == BMI160_NULL) {
  14048. return E_BMI160_NULL_PTR;
  14049. } else {
  14050. if (v_accel_selftest_sign_u8 <=
  14051. BMI160_MAX_VALUE_SELFTEST_SIGN) {
  14052. /* write Accel self test axis sign*/
  14053. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14054. p_bmi160->dev_addr,
  14055. BMI160_USER_ACCEL_SELFTEST_SIGN__REG,
  14056. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14057. if (com_rslt == SUCCESS) {
  14058. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  14059. BMI160_USER_ACCEL_SELFTEST_SIGN,
  14060. v_accel_selftest_sign_u8);
  14061. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  14062. p_bmi160->dev_addr,
  14063. BMI160_USER_ACCEL_SELFTEST_SIGN__REG,
  14064. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14065. /*Accel and Gyro power mode check*/
  14066. if (bmi160_power_mode_status_u8_g !=
  14067. BMI160_NORMAL_MODE)
  14068. /*interface idle time delay */
  14069. p_bmi160->delay_msec(
  14070. BMI160_GEN_READ_WRITE_DELAY);
  14071. }
  14072. } else {
  14073. com_rslt = E_BMI160_OUT_OF_RANGE;
  14074. }
  14075. }
  14076. return com_rslt;
  14077. }
  14078. /*!
  14079. * @brief This API reads Accel self test amplitude
  14080. * from the register 0x6D bit 3
  14081. *
  14082. *
  14083. * @param v_accel_selftest_amp_u8 : The value of Accel self test amplitude
  14084. * Value | Description
  14085. * --------|-------------
  14086. * 0x00 | LOW
  14087. * 0x01 | HIGH
  14088. *
  14089. *
  14090. * @return results of bus communication function
  14091. * @retval 0 -> Success
  14092. * @retval -1 -> Error
  14093. *
  14094. *
  14095. */
  14096. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_selftest_amp(
  14097. u8 *v_accel_selftest_amp_u8)
  14098. {
  14099. /* variable used to return the status of communication result*/
  14100. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14101. u8 v_data_u8 = BMI160_INIT_VALUE;
  14102. /* check the p_bmi160 structure for NULL pointer assignment*/
  14103. if (p_bmi160 == BMI160_NULL) {
  14104. return E_BMI160_NULL_PTR;
  14105. } else {
  14106. /* read self test amplitude*/
  14107. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14108. p_bmi160->dev_addr,
  14109. BMI160_USER_SELFTEST_AMP__REG,
  14110. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14111. *v_accel_selftest_amp_u8 = BMI160_GET_BITSLICE(
  14112. v_data_u8,
  14113. BMI160_USER_SELFTEST_AMP);
  14114. }
  14115. return com_rslt;
  14116. }
  14117. /*!
  14118. * @brief This API writes Accel self test amplitude
  14119. * in the register 0x6D bit 3
  14120. *
  14121. *
  14122. * @param v_accel_selftest_amp_u8 : The value of Accel self test amplitude
  14123. * Value | Description
  14124. * --------|-------------
  14125. * 0x00 | LOW
  14126. * 0x01 | HIGH
  14127. *
  14128. *
  14129. * @return results of bus communication function
  14130. * @retval 0 -> Success
  14131. * @retval -1 -> Error
  14132. *
  14133. *
  14134. */
  14135. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_selftest_amp(
  14136. u8 v_accel_selftest_amp_u8)
  14137. {
  14138. /* variable used to return the status of communication result*/
  14139. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14140. u8 v_data_u8 = BMI160_INIT_VALUE;
  14141. /* check the p_bmi160 structure for NULL pointer assignment*/
  14142. if (p_bmi160 == BMI160_NULL) {
  14143. return E_BMI160_NULL_PTR;
  14144. } else {
  14145. if (v_accel_selftest_amp_u8 <=
  14146. BMI160_MAX_VALUE_SELFTEST_AMP) {
  14147. /* write self test amplitude*/
  14148. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14149. p_bmi160->dev_addr,
  14150. BMI160_USER_SELFTEST_AMP__REG,
  14151. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14152. if (com_rslt == SUCCESS) {
  14153. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  14154. BMI160_USER_SELFTEST_AMP,
  14155. v_accel_selftest_amp_u8);
  14156. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  14157. p_bmi160->dev_addr,
  14158. BMI160_USER_SELFTEST_AMP__REG,
  14159. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14160. /*Accel and Gyro power mode check*/
  14161. if (bmi160_power_mode_status_u8_g !=
  14162. BMI160_NORMAL_MODE)
  14163. /*interface idle time delay */
  14164. p_bmi160->delay_msec(
  14165. BMI160_GEN_READ_WRITE_DELAY);
  14166. }
  14167. } else {
  14168. com_rslt = E_BMI160_OUT_OF_RANGE;
  14169. }
  14170. }
  14171. return com_rslt;
  14172. }
  14173. /*!
  14174. * @brief This API reads the gyro self test trigger
  14175. *
  14176. * @param v_gyro_selftest_start_u8: The value of gyro self test start
  14177. *
  14178. * @return results of bus communication function
  14179. * @retval 0 -> Success
  14180. * @retval -1 -> Error
  14181. *
  14182. *
  14183. */
  14184. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_selftest_start(
  14185. u8 *v_gyro_selftest_start_u8)
  14186. {
  14187. /* variable used to return the status of communication result*/
  14188. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14189. u8 v_data_u8 = BMI160_INIT_VALUE;
  14190. /* check the p_bmi160 structure for NULL pointer assignment*/
  14191. if (p_bmi160 == BMI160_NULL) {
  14192. return E_BMI160_NULL_PTR;
  14193. } else {
  14194. /* read gyro self test start */
  14195. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14196. p_bmi160->dev_addr,
  14197. BMI160_USER_GYRO_SELFTEST_START__REG,
  14198. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14199. *v_gyro_selftest_start_u8 = BMI160_GET_BITSLICE(
  14200. v_data_u8,
  14201. BMI160_USER_GYRO_SELFTEST_START);
  14202. }
  14203. return com_rslt;
  14204. }
  14205. /*!
  14206. * @brief This API writes the gyro self test trigger
  14207. *
  14208. * @param v_gyro_selftest_start_u8: The value of gyro self test start
  14209. *
  14210. * @return results of bus communication function
  14211. * @retval 0 -> Success
  14212. * @retval -1 -> Error
  14213. *
  14214. *
  14215. */
  14216. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_selftest_start(
  14217. u8 v_gyro_selftest_start_u8)
  14218. {
  14219. /* variable used to return the status of communication result*/
  14220. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14221. u8 v_data_u8 = BMI160_INIT_VALUE;
  14222. /* check the p_bmi160 structure for NULL pointer assignment*/
  14223. if (p_bmi160 == BMI160_NULL) {
  14224. return E_BMI160_NULL_PTR;
  14225. } else {
  14226. if (v_gyro_selftest_start_u8 <=
  14227. BMI160_MAX_VALUE_SELFTEST_START) {
  14228. /* write gyro self test start */
  14229. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14230. p_bmi160->dev_addr,
  14231. BMI160_USER_GYRO_SELFTEST_START__REG,
  14232. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14233. if (com_rslt == SUCCESS) {
  14234. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  14235. BMI160_USER_GYRO_SELFTEST_START,
  14236. v_gyro_selftest_start_u8);
  14237. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  14238. p_bmi160->dev_addr,
  14239. BMI160_USER_GYRO_SELFTEST_START__REG,
  14240. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14241. /*Accel and Gyro power mode check*/
  14242. if (bmi160_power_mode_status_u8_g !=
  14243. BMI160_NORMAL_MODE)
  14244. /*interface idle time delay */
  14245. p_bmi160->delay_msec(
  14246. BMI160_GEN_READ_WRITE_DELAY);
  14247. }
  14248. } else {
  14249. com_rslt = E_BMI160_OUT_OF_RANGE;
  14250. }
  14251. }
  14252. return com_rslt;
  14253. }
  14254. /*!
  14255. * @brief This API reads the primary interface selection I2C or SPI
  14256. * from the register 0x70 bit 0
  14257. *
  14258. * @param v_spi_enable_u8: The value of Interface selection
  14259. * Value | Description
  14260. * --------|-------------
  14261. * 0x00 | I2C Enable
  14262. * 0x01 | I2C DISABLE
  14263. *
  14264. *
  14265. * @return results of bus communication function
  14266. * @retval 0 -> Success
  14267. * @retval -1 -> Error
  14268. *
  14269. *
  14270. */
  14271. BMI160_RETURN_FUNCTION_TYPE bmi160_get_spi_enable(u8 *v_spi_enable_u8)
  14272. {
  14273. /* variable used to return the status of communication result*/
  14274. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14275. u8 v_data_u8 = BMI160_INIT_VALUE;
  14276. /* check the p_bmi160 structure for NULL pointer assignment*/
  14277. if (p_bmi160 == BMI160_NULL) {
  14278. return E_BMI160_NULL_PTR;
  14279. } else {
  14280. /* read interface section*/
  14281. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14282. p_bmi160->dev_addr,
  14283. BMI160_USER_NV_CONFIG_SPI_ENABLE__REG,
  14284. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14285. *v_spi_enable_u8 = BMI160_GET_BITSLICE(v_data_u8,
  14286. BMI160_USER_NV_CONFIG_SPI_ENABLE);
  14287. }
  14288. return com_rslt;
  14289. }
  14290. /*!
  14291. * @brief This API writes primary interface selection I2C or SPI
  14292. * in the register 0x70 bit 0
  14293. *
  14294. * @param v_spi_enable_u8: The value of Interface selection
  14295. * Value | Description
  14296. * --------|-------------
  14297. * 0x00 | I2C Enable
  14298. * 0x01 | I2C DISABLE
  14299. *
  14300. *
  14301. * @return results of bus communication function
  14302. * @retval 0 -> Success
  14303. * @retval -1 -> Error
  14304. *
  14305. *
  14306. */
  14307. BMI160_RETURN_FUNCTION_TYPE bmi160_set_spi_enable(u8 v_spi_enable_u8)
  14308. {
  14309. /* variable used to return the status of communication result*/
  14310. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14311. u8 v_data_u8 = BMI160_INIT_VALUE;
  14312. /* check the p_bmi160 structure for NULL pointer assignment*/
  14313. if (p_bmi160 == BMI160_NULL) {
  14314. return E_BMI160_NULL_PTR;
  14315. } else {
  14316. /* write interface section*/
  14317. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14318. p_bmi160->dev_addr,
  14319. BMI160_USER_NV_CONFIG_SPI_ENABLE__REG,
  14320. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14321. if (com_rslt == SUCCESS) {
  14322. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  14323. BMI160_USER_NV_CONFIG_SPI_ENABLE,
  14324. v_spi_enable_u8);
  14325. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  14326. (p_bmi160->dev_addr,
  14327. BMI160_USER_NV_CONFIG_SPI_ENABLE__REG,
  14328. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14329. /*Accel and Gyro power mode check*/
  14330. if (bmi160_power_mode_status_u8_g !=
  14331. BMI160_NORMAL_MODE)
  14332. /*interface idle time delay */
  14333. p_bmi160->delay_msec(
  14334. BMI160_GEN_READ_WRITE_DELAY);
  14335. }
  14336. }
  14337. return com_rslt;
  14338. }
  14339. /*!
  14340. * @brief This API reads the Accel manual offset compensation of x axis
  14341. * from the register 0x71 bit 0 to 7
  14342. *
  14343. *
  14344. *
  14345. * @param v_accel_off_x_s8:
  14346. * The value of Accel manual offset compensation of x axis
  14347. *
  14348. *
  14349. *
  14350. * @return results of bus communication function
  14351. * @retval 0 -> Success
  14352. * @retval -1 -> Error
  14353. *
  14354. *
  14355. */
  14356. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_offset_compensation_xaxis(
  14357. s8 *v_accel_off_x_s8)
  14358. {
  14359. /* variable used to return the status of communication result*/
  14360. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14361. u8 v_data_u8 = BMI160_INIT_VALUE;
  14362. /* check the p_bmi160 structure for NULL pointer assignment*/
  14363. if (p_bmi160 == BMI160_NULL) {
  14364. return E_BMI160_NULL_PTR;
  14365. } else {
  14366. /* read Accel manual offset compensation of x axis*/
  14367. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14368. p_bmi160->dev_addr,
  14369. BMI160_USER_OFFSET_0_ACCEL_OFF_X__REG,
  14370. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14371. *v_accel_off_x_s8 = BMI160_GET_BITSLICE(v_data_u8,
  14372. BMI160_USER_OFFSET_0_ACCEL_OFF_X);
  14373. }
  14374. return com_rslt;
  14375. }
  14376. /*!
  14377. * @brief This API writes the Accel manual offset compensation of x axis
  14378. * in the register 0x71 bit 0 to 7
  14379. *
  14380. *
  14381. *
  14382. * @param v_accel_off_x_s8:
  14383. * The value of Accel manual offset compensation of x axis
  14384. *
  14385. *
  14386. *
  14387. * @return results of bus communication function
  14388. * @retval 0 -> Success
  14389. * @retval -1 -> Error
  14390. *
  14391. *
  14392. */
  14393. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_offset_compensation_xaxis(
  14394. s8 v_accel_off_x_s8)
  14395. {
  14396. /* variable used to return the status of communication result*/
  14397. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14398. u8 v_data_u8 = BMI160_INIT_VALUE;
  14399. u8 v_status_s8 = SUCCESS;
  14400. /* check the p_bmi160 structure for NULL pointer assignment*/
  14401. if (p_bmi160 == BMI160_NULL) {
  14402. return E_BMI160_NULL_PTR;
  14403. } else {
  14404. /* enable Accel offset */
  14405. v_status_s8 = bmi160_set_accel_offset_enable(
  14406. ACCEL_OFFSET_ENABLE);
  14407. if (v_status_s8 == SUCCESS) {
  14408. /* write Accel manual offset compensation of x axis*/
  14409. com_rslt =
  14410. p_bmi160->BMI160_BUS_READ_FUNC(
  14411. p_bmi160->dev_addr,
  14412. BMI160_USER_OFFSET_0_ACCEL_OFF_X__REG,
  14413. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14414. if (com_rslt == SUCCESS) {
  14415. v_data_u8 =
  14416. BMI160_SET_BITSLICE(
  14417. v_data_u8,
  14418. BMI160_USER_OFFSET_0_ACCEL_OFF_X,
  14419. v_accel_off_x_s8);
  14420. com_rslt +=
  14421. p_bmi160->BMI160_BUS_WRITE_FUNC(
  14422. p_bmi160->dev_addr,
  14423. BMI160_USER_OFFSET_0_ACCEL_OFF_X__REG,
  14424. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14425. /*Accel and Gyro power mode check*/
  14426. if (bmi160_power_mode_status_u8_g !=
  14427. BMI160_NORMAL_MODE)
  14428. /*interface idle time delay */
  14429. p_bmi160->delay_msec(
  14430. BMI160_GEN_READ_WRITE_DELAY);
  14431. }
  14432. } else {
  14433. com_rslt = ERROR;
  14434. }
  14435. }
  14436. return com_rslt;
  14437. }
  14438. /*!
  14439. * @brief This API reads the Accel manual offset compensation of y axis
  14440. * from the register 0x72 bit 0 to 7
  14441. *
  14442. *
  14443. *
  14444. * @param v_accel_off_y_s8:
  14445. * The value of Accel manual offset compensation of y axis
  14446. *
  14447. *
  14448. *
  14449. * @return results of bus communication function
  14450. * @retval 0 -> Success
  14451. * @retval -1 -> Error
  14452. *
  14453. *
  14454. */
  14455. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_offset_compensation_yaxis(
  14456. s8 *v_accel_off_y_s8)
  14457. {
  14458. /* variable used to return the status of communication result*/
  14459. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14460. u8 v_data_u8 = BMI160_INIT_VALUE;
  14461. /* check the p_bmi160 structure for NULL pointer assignment*/
  14462. if (p_bmi160 == BMI160_NULL) {
  14463. return E_BMI160_NULL_PTR;
  14464. } else {
  14465. /* read Accel manual offset compensation of y axis*/
  14466. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14467. p_bmi160->dev_addr,
  14468. BMI160_USER_OFFSET_1_ACCEL_OFF_Y__REG,
  14469. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14470. *v_accel_off_y_s8 = BMI160_GET_BITSLICE(v_data_u8,
  14471. BMI160_USER_OFFSET_1_ACCEL_OFF_Y);
  14472. }
  14473. return com_rslt;
  14474. }
  14475. /*!
  14476. * @brief This API writes the Accel manual offset compensation of y axis
  14477. * in the register 0x72 bit 0 to 7
  14478. *
  14479. *
  14480. *
  14481. * @param v_accel_off_y_s8:
  14482. * The value of Accel manual offset compensation of y axis
  14483. *
  14484. *
  14485. *
  14486. * @return results of bus communication function
  14487. * @retval 0 -> Success
  14488. * @retval -1 -> Error
  14489. *
  14490. *
  14491. */
  14492. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_offset_compensation_yaxis(
  14493. s8 v_accel_off_y_s8)
  14494. {
  14495. /* variable used to return the status of communication result*/
  14496. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14497. u8 v_data_u8 = BMI160_INIT_VALUE;
  14498. u8 v_status_s8 = SUCCESS;
  14499. /* check the p_bmi160 structure for NULL pointer assignment*/
  14500. if (p_bmi160 == BMI160_NULL) {
  14501. return E_BMI160_NULL_PTR;
  14502. } else {
  14503. /* enable Accel offset */
  14504. v_status_s8 = bmi160_set_accel_offset_enable(
  14505. ACCEL_OFFSET_ENABLE);
  14506. if (v_status_s8 == SUCCESS) {
  14507. /* write Accel manual offset compensation of y axis*/
  14508. com_rslt =
  14509. p_bmi160->BMI160_BUS_READ_FUNC(
  14510. p_bmi160->dev_addr,
  14511. BMI160_USER_OFFSET_1_ACCEL_OFF_Y__REG,
  14512. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14513. if (com_rslt == SUCCESS) {
  14514. v_data_u8 =
  14515. BMI160_SET_BITSLICE(
  14516. v_data_u8,
  14517. BMI160_USER_OFFSET_1_ACCEL_OFF_Y,
  14518. v_accel_off_y_s8);
  14519. com_rslt +=
  14520. p_bmi160->BMI160_BUS_WRITE_FUNC(
  14521. p_bmi160->dev_addr,
  14522. BMI160_USER_OFFSET_1_ACCEL_OFF_Y__REG,
  14523. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14524. /*Accel and Gyro power mode check*/
  14525. if (bmi160_power_mode_status_u8_g !=
  14526. BMI160_NORMAL_MODE)
  14527. /*interface idle time delay */
  14528. p_bmi160->delay_msec(
  14529. BMI160_GEN_READ_WRITE_DELAY);
  14530. }
  14531. } else {
  14532. com_rslt = ERROR;
  14533. }
  14534. }
  14535. return com_rslt;
  14536. }
  14537. /*!
  14538. * @brief This API reads the Accel manual offset compensation of z axis
  14539. * from the register 0x73 bit 0 to 7
  14540. *
  14541. *
  14542. *
  14543. * @param v_accel_off_z_s8:
  14544. * The value of Accel manual offset compensation of z axis
  14545. *
  14546. *
  14547. *
  14548. * @return results of bus communication function
  14549. * @retval 0 -> Success
  14550. * @retval -1 -> Error
  14551. *
  14552. *
  14553. */
  14554. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_offset_compensation_zaxis(
  14555. s8 *v_accel_off_z_s8)
  14556. {
  14557. /* variable used to return the status of communication result*/
  14558. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14559. u8 v_data_u8 = BMI160_INIT_VALUE;
  14560. /* check the p_bmi160 structure for NULL pointer assignment*/
  14561. if (p_bmi160 == BMI160_NULL) {
  14562. return E_BMI160_NULL_PTR;
  14563. } else {
  14564. /* read Accel manual offset compensation of z axis*/
  14565. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14566. p_bmi160->dev_addr,
  14567. BMI160_USER_OFFSET_2_ACCEL_OFF_Z__REG,
  14568. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14569. *v_accel_off_z_s8 = BMI160_GET_BITSLICE(v_data_u8,
  14570. BMI160_USER_OFFSET_2_ACCEL_OFF_Z);
  14571. }
  14572. return com_rslt;
  14573. }
  14574. /*!
  14575. * @brief This API writes the Accel manual offset compensation of z axis
  14576. * in the register 0x73 bit 0 to 7
  14577. *
  14578. *
  14579. *
  14580. * @param v_accel_off_z_s8:
  14581. * The value of Accel manual offset compensation of z axis
  14582. *
  14583. *
  14584. *
  14585. * @return results of bus communication function
  14586. * @retval 0 -> Success
  14587. * @retval -1 -> Error
  14588. *
  14589. *
  14590. */
  14591. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_offset_compensation_zaxis(
  14592. s8 v_accel_off_z_s8)
  14593. {
  14594. /* variable used to return the status of communication result*/
  14595. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14596. u8 v_data_u8 = BMI160_INIT_VALUE;
  14597. u8 v_status_s8 = SUCCESS;
  14598. /* check the p_bmi160 structure for NULL pointer assignment*/
  14599. if (p_bmi160 == BMI160_NULL) {
  14600. return E_BMI160_NULL_PTR;
  14601. } else {
  14602. /* enable Accel offset */
  14603. v_status_s8 = bmi160_set_accel_offset_enable(
  14604. ACCEL_OFFSET_ENABLE);
  14605. if (v_status_s8 == SUCCESS) {
  14606. /* write Accel manual offset
  14607. compensation of z axis*/
  14608. com_rslt =
  14609. p_bmi160->BMI160_BUS_READ_FUNC(
  14610. p_bmi160->dev_addr,
  14611. BMI160_USER_OFFSET_2_ACCEL_OFF_Z__REG,
  14612. &v_data_u8,
  14613. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14614. if (com_rslt == SUCCESS) {
  14615. v_data_u8 =
  14616. BMI160_SET_BITSLICE(v_data_u8,
  14617. BMI160_USER_OFFSET_2_ACCEL_OFF_Z,
  14618. v_accel_off_z_s8);
  14619. com_rslt +=
  14620. p_bmi160->BMI160_BUS_WRITE_FUNC(
  14621. p_bmi160->dev_addr,
  14622. BMI160_USER_OFFSET_2_ACCEL_OFF_Z__REG,
  14623. &v_data_u8,
  14624. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14625. /*Check for the power mode of Accel
  14626. and gyro not in normal mode */
  14627. if (bmi160_power_mode_status_u8_g !=
  14628. BMI160_NORMAL_MODE)
  14629. /*interface idle time delay */
  14630. p_bmi160->delay_msec(
  14631. BMI160_GEN_READ_WRITE_DELAY);
  14632. }
  14633. } else {
  14634. com_rslt = ERROR;
  14635. }
  14636. }
  14637. return com_rslt;
  14638. }
  14639. /*!
  14640. * @brief This API reads the gyro manual offset compensation of x axis
  14641. * from the register 0x74 bit 0 to 7 and 0x77 bit 0 and 1
  14642. *
  14643. *
  14644. *
  14645. * @param v_gyro_off_x_s16:
  14646. * The value of gyro manual offset compensation of x axis
  14647. *
  14648. *
  14649. *
  14650. * @return results of bus communication function
  14651. * @retval 0 -> Success
  14652. * @retval -1 -> Error
  14653. *
  14654. *
  14655. */
  14656. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_offset_compensation_xaxis(
  14657. s16 *v_gyro_off_x_s16)
  14658. {
  14659. /* variable used to return the status of communication result*/
  14660. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14661. u8 v_data1_u8r = BMI160_INIT_VALUE;
  14662. u8 v_data2_u8r = BMI160_INIT_VALUE;
  14663. s16 v_data3_u8r, v_data4_u8r = BMI160_INIT_VALUE;
  14664. /* check the p_bmi160 structure for NULL pointer assignment*/
  14665. if (p_bmi160 == BMI160_NULL) {
  14666. return E_BMI160_NULL_PTR;
  14667. } else {
  14668. /* read gyro offset x*/
  14669. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14670. p_bmi160->dev_addr,
  14671. BMI160_USER_OFFSET_3_GYRO_OFF_X__REG,
  14672. &v_data1_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14673. v_data1_u8r = BMI160_GET_BITSLICE(v_data1_u8r,
  14674. BMI160_USER_OFFSET_3_GYRO_OFF_X);
  14675. com_rslt += p_bmi160->BMI160_BUS_READ_FUNC(
  14676. p_bmi160->dev_addr,
  14677. BMI160_USER_OFFSET_6_GYRO_OFF_X__REG,
  14678. &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14679. v_data2_u8r = BMI160_GET_BITSLICE(v_data2_u8r,
  14680. BMI160_USER_OFFSET_6_GYRO_OFF_X);
  14681. v_data3_u8r = v_data2_u8r
  14682. << BMI160_SHIFT_BIT_POSITION_BY_14_BITS;
  14683. v_data4_u8r = v_data1_u8r
  14684. << BMI160_SHIFT_BIT_POSITION_BY_06_BITS;
  14685. v_data3_u8r = v_data3_u8r | v_data4_u8r;
  14686. *v_gyro_off_x_s16 = v_data3_u8r
  14687. >> BMI160_SHIFT_BIT_POSITION_BY_06_BITS;
  14688. }
  14689. return com_rslt;
  14690. }
  14691. /*!
  14692. * @brief This API writes the gyro manual offset compensation of x axis
  14693. * in the register 0x74 bit 0 to 7 and 0x77 bit 0 and 1
  14694. *
  14695. *
  14696. *
  14697. * @param v_gyro_off_x_s16:
  14698. * The value of gyro manual offset compensation of x axis
  14699. *
  14700. *
  14701. *
  14702. * @return results of bus communication function
  14703. * @retval 0 -> Success
  14704. * @retval -1 -> Error
  14705. *
  14706. *
  14707. */
  14708. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_offset_compensation_xaxis(
  14709. s16 v_gyro_off_x_s16)
  14710. {
  14711. /* variable used to return the status of communication result*/
  14712. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14713. u8 v_data1_u8r, v_data2_u8r = BMI160_INIT_VALUE;
  14714. u16 v_data3_u8r = BMI160_INIT_VALUE;
  14715. u8 v_status_s8 = SUCCESS;
  14716. /* check the p_bmi160 structure for NULL pointer assignment*/
  14717. if (p_bmi160 == BMI160_NULL) {
  14718. return E_BMI160_NULL_PTR;
  14719. } else {
  14720. /* write gyro offset x*/
  14721. v_status_s8 = bmi160_set_gyro_offset_enable(
  14722. GYRO_OFFSET_ENABLE);
  14723. if (v_status_s8 == SUCCESS) {
  14724. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14725. p_bmi160->dev_addr,
  14726. BMI160_USER_OFFSET_3_GYRO_OFF_X__REG,
  14727. &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14728. if (com_rslt == SUCCESS) {
  14729. v_data1_u8r =
  14730. ((s8) (v_gyro_off_x_s16 &
  14731. BMI160_GYRO_MANUAL_OFFSET_0_7));
  14732. v_data2_u8r = BMI160_SET_BITSLICE(
  14733. v_data2_u8r,
  14734. BMI160_USER_OFFSET_3_GYRO_OFF_X,
  14735. v_data1_u8r);
  14736. /* write 0x74 bit 0 to 7*/
  14737. com_rslt +=
  14738. p_bmi160->BMI160_BUS_WRITE_FUNC(
  14739. p_bmi160->dev_addr,
  14740. BMI160_USER_OFFSET_3_GYRO_OFF_X__REG,
  14741. &v_data2_u8r,
  14742. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14743. /*Accel and Gyro power mode check*/
  14744. if (bmi160_power_mode_status_u8_g !=
  14745. BMI160_NORMAL_MODE)
  14746. /*interface idle time delay */
  14747. p_bmi160->delay_msec(
  14748. BMI160_GEN_READ_WRITE_DELAY);
  14749. }
  14750. com_rslt += p_bmi160->BMI160_BUS_READ_FUNC(
  14751. p_bmi160->dev_addr,
  14752. BMI160_USER_OFFSET_6_GYRO_OFF_X__REG,
  14753. &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14754. if (com_rslt == SUCCESS) {
  14755. v_data3_u8r =
  14756. (u16) (v_gyro_off_x_s16 &
  14757. BMI160_GYRO_MANUAL_OFFSET_8_9);
  14758. v_data1_u8r = (u8)(v_data3_u8r
  14759. >> BMI160_SHIFT_BIT_POSITION_BY_08_BITS);
  14760. v_data2_u8r = BMI160_SET_BITSLICE(
  14761. v_data2_u8r,
  14762. BMI160_USER_OFFSET_6_GYRO_OFF_X,
  14763. v_data1_u8r);
  14764. /* write 0x77 bit 0 and 1*/
  14765. com_rslt +=
  14766. p_bmi160->BMI160_BUS_WRITE_FUNC(
  14767. p_bmi160->dev_addr,
  14768. BMI160_USER_OFFSET_6_GYRO_OFF_X__REG,
  14769. &v_data2_u8r,
  14770. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14771. /*Accel and Gyro power mode check*/
  14772. if (bmi160_power_mode_status_u8_g !=
  14773. BMI160_NORMAL_MODE)
  14774. /*interface idle time delay */
  14775. p_bmi160->delay_msec(
  14776. BMI160_GEN_READ_WRITE_DELAY);
  14777. }
  14778. } else {
  14779. return ERROR;
  14780. }
  14781. }
  14782. return com_rslt;
  14783. }
  14784. /*!
  14785. * @brief This API reads the gyro manual offset compensation of y axis
  14786. * from the register 0x75 bit 0 to 7 and 0x77 bit 2 and 3
  14787. *
  14788. *
  14789. *
  14790. * @param v_gyro_off_y_s16:
  14791. * The value of gyro manual offset compensation of y axis
  14792. *
  14793. *
  14794. *
  14795. * @return results of bus communication function
  14796. * @retval 0 -> Success
  14797. * @retval -1 -> Error
  14798. *
  14799. *
  14800. */
  14801. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_offset_compensation_yaxis(
  14802. s16 *v_gyro_off_y_s16)
  14803. {
  14804. /* variable used to return the status of communication result*/
  14805. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14806. u8 v_data1_u8r = BMI160_INIT_VALUE;
  14807. u8 v_data2_u8r = BMI160_INIT_VALUE;
  14808. s16 v_data3_u8r, v_data4_u8r = BMI160_INIT_VALUE;
  14809. /* check the p_bmi160 structure for NULL pointer assignment*/
  14810. if (p_bmi160 == BMI160_NULL) {
  14811. return E_BMI160_NULL_PTR;
  14812. } else {
  14813. /* read gyro offset y*/
  14814. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14815. p_bmi160->dev_addr,
  14816. BMI160_USER_OFFSET_4_GYRO_OFF_Y__REG,
  14817. &v_data1_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14818. v_data1_u8r = BMI160_GET_BITSLICE(v_data1_u8r,
  14819. BMI160_USER_OFFSET_4_GYRO_OFF_Y);
  14820. com_rslt += p_bmi160->BMI160_BUS_READ_FUNC
  14821. (p_bmi160->dev_addr,
  14822. BMI160_USER_OFFSET_6_GYRO_OFF_Y__REG,
  14823. &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14824. v_data2_u8r = BMI160_GET_BITSLICE(v_data2_u8r,
  14825. BMI160_USER_OFFSET_6_GYRO_OFF_Y);
  14826. v_data3_u8r = v_data2_u8r
  14827. << BMI160_SHIFT_BIT_POSITION_BY_14_BITS;
  14828. v_data4_u8r = v_data1_u8r
  14829. << BMI160_SHIFT_BIT_POSITION_BY_06_BITS;
  14830. v_data3_u8r = v_data3_u8r | v_data4_u8r;
  14831. *v_gyro_off_y_s16 = v_data3_u8r
  14832. >> BMI160_SHIFT_BIT_POSITION_BY_06_BITS;
  14833. }
  14834. return com_rslt;
  14835. }
  14836. /*!
  14837. * @brief This API writes gyro manual offset compensation of y axis
  14838. * in the register 0x75 bit 0 to 7 and 0x77 bit 2 and 3
  14839. *
  14840. *
  14841. *
  14842. * @param v_gyro_off_y_s16:
  14843. * The value of gyro manual offset compensation of y axis
  14844. *
  14845. *
  14846. *
  14847. * @return results of bus communication function
  14848. * @retval 0 -> Success
  14849. * @retval -1 -> Error
  14850. *
  14851. *
  14852. */
  14853. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_offset_compensation_yaxis(
  14854. s16 v_gyro_off_y_s16)
  14855. {
  14856. /* variable used to return the status of communication result*/
  14857. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14858. u8 v_data1_u8r, v_data2_u8r = BMI160_INIT_VALUE;
  14859. u16 v_data3_u8r = BMI160_INIT_VALUE;
  14860. u8 v_status_s8 = SUCCESS;
  14861. /* check the p_bmi160 structure for NULL pointer assignment*/
  14862. if (p_bmi160 == BMI160_NULL) {
  14863. return E_BMI160_NULL_PTR;
  14864. } else {
  14865. /* enable gyro offset bit */
  14866. v_status_s8 = bmi160_set_gyro_offset_enable(
  14867. GYRO_OFFSET_ENABLE);
  14868. /* write gyro offset y*/
  14869. if (v_status_s8 == SUCCESS) {
  14870. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  14871. (p_bmi160->dev_addr,
  14872. BMI160_USER_OFFSET_4_GYRO_OFF_Y__REG,
  14873. &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14874. if (com_rslt == SUCCESS) {
  14875. v_data1_u8r =
  14876. ((s8) (v_gyro_off_y_s16 &
  14877. BMI160_GYRO_MANUAL_OFFSET_0_7));
  14878. v_data2_u8r = BMI160_SET_BITSLICE(
  14879. v_data2_u8r,
  14880. BMI160_USER_OFFSET_4_GYRO_OFF_Y,
  14881. v_data1_u8r);
  14882. /* write 0x75 bit 0 to 7*/
  14883. com_rslt +=
  14884. p_bmi160->BMI160_BUS_WRITE_FUNC
  14885. (p_bmi160->dev_addr,
  14886. BMI160_USER_OFFSET_4_GYRO_OFF_Y__REG,
  14887. &v_data2_u8r,
  14888. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14889. /*Accel and Gyro power mode check*/
  14890. if (bmi160_power_mode_status_u8_g !=
  14891. BMI160_NORMAL_MODE)
  14892. /*interface idle time delay */
  14893. p_bmi160->delay_msec(
  14894. BMI160_GEN_READ_WRITE_DELAY);
  14895. }
  14896. com_rslt += p_bmi160->BMI160_BUS_READ_FUNC
  14897. (p_bmi160->dev_addr,
  14898. BMI160_USER_OFFSET_6_GYRO_OFF_Y__REG,
  14899. &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14900. if (com_rslt == SUCCESS) {
  14901. v_data3_u8r =
  14902. (u16) (v_gyro_off_y_s16 &
  14903. BMI160_GYRO_MANUAL_OFFSET_8_9);
  14904. v_data1_u8r = (u8)(v_data3_u8r
  14905. >> BMI160_SHIFT_BIT_POSITION_BY_08_BITS);
  14906. v_data2_u8r = BMI160_SET_BITSLICE(
  14907. v_data2_u8r,
  14908. BMI160_USER_OFFSET_6_GYRO_OFF_Y,
  14909. v_data1_u8r);
  14910. /* write 0x77 bit 2 and 3*/
  14911. com_rslt +=
  14912. p_bmi160->BMI160_BUS_WRITE_FUNC
  14913. (p_bmi160->dev_addr,
  14914. BMI160_USER_OFFSET_6_GYRO_OFF_Y__REG,
  14915. &v_data2_u8r,
  14916. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14917. /*Accel and Gyro power mode check*/
  14918. if (bmi160_power_mode_status_u8_g !=
  14919. BMI160_NORMAL_MODE)
  14920. /*interface idle time delay */
  14921. p_bmi160->delay_msec(
  14922. BMI160_GEN_READ_WRITE_DELAY);
  14923. }
  14924. } else {
  14925. return ERROR;
  14926. }
  14927. }
  14928. return com_rslt;
  14929. }
  14930. /*!
  14931. * @brief This API reads the gyro manual offset compensation of z axis
  14932. * from the register 0x76 bit 0 to 7 and 0x77 bit 4 and 5
  14933. *
  14934. *
  14935. *
  14936. * @param v_gyro_off_z_s16:
  14937. * The value of gyro manual offset compensation of z axis
  14938. *
  14939. *
  14940. *
  14941. * @return results of bus communication function
  14942. * @retval 0 -> Success
  14943. * @retval -1 -> Error
  14944. *
  14945. *
  14946. */
  14947. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_offset_compensation_zaxis(
  14948. s16 *v_gyro_off_z_s16)
  14949. {
  14950. /* variable used to return the status of communication result*/
  14951. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14952. u8 v_data1_u8r = BMI160_INIT_VALUE;
  14953. u8 v_data2_u8r = BMI160_INIT_VALUE;
  14954. s16 v_data3_u8r, v_data4_u8r = BMI160_INIT_VALUE;
  14955. /* check the p_bmi160 structure for NULL pointer assignment*/
  14956. if (p_bmi160 == BMI160_NULL) {
  14957. return E_BMI160_NULL_PTR;
  14958. } else {
  14959. /* read gyro manual offset z axis*/
  14960. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  14961. (p_bmi160->dev_addr,
  14962. BMI160_USER_OFFSET_5_GYRO_OFF_Z__REG,
  14963. &v_data1_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14964. v_data1_u8r = BMI160_GET_BITSLICE
  14965. (v_data1_u8r,
  14966. BMI160_USER_OFFSET_5_GYRO_OFF_Z);
  14967. com_rslt +=
  14968. p_bmi160->BMI160_BUS_READ_FUNC
  14969. (p_bmi160->dev_addr,
  14970. BMI160_USER_OFFSET_6_GYRO_OFF_Z__REG,
  14971. &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  14972. v_data2_u8r = BMI160_GET_BITSLICE(
  14973. v_data2_u8r,
  14974. BMI160_USER_OFFSET_6_GYRO_OFF_Z);
  14975. v_data3_u8r = v_data2_u8r
  14976. << BMI160_SHIFT_BIT_POSITION_BY_14_BITS;
  14977. v_data4_u8r = v_data1_u8r
  14978. << BMI160_SHIFT_BIT_POSITION_BY_06_BITS;
  14979. v_data3_u8r = v_data3_u8r | v_data4_u8r;
  14980. *v_gyro_off_z_s16 = v_data3_u8r
  14981. >> BMI160_SHIFT_BIT_POSITION_BY_06_BITS;
  14982. }
  14983. return com_rslt;
  14984. }
  14985. /*!
  14986. * @brief This API writes gyro manual offset compensation of z axis
  14987. * in the register 0x76 bit 0 to 7 and 0x77 bit 4 and 5
  14988. *
  14989. *
  14990. *
  14991. * @param v_gyro_off_z_s16:
  14992. * The value of gyro manual offset compensation of z axis
  14993. *
  14994. *
  14995. *
  14996. * @return results of bus communication function
  14997. * @retval 0 -> Success
  14998. * @retval -1 -> Error
  14999. *
  15000. *
  15001. */
  15002. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_offset_compensation_zaxis(
  15003. s16 v_gyro_off_z_s16)
  15004. {
  15005. /* variable used to return the status of communication result*/
  15006. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15007. u8 v_data1_u8r, v_data2_u8r = BMI160_INIT_VALUE;
  15008. u16 v_data3_u8r = BMI160_INIT_VALUE;
  15009. u8 v_status_s8 = SUCCESS;
  15010. /* check the p_bmi160 structure for NULL pointer assignment*/
  15011. if (p_bmi160 == BMI160_NULL) {
  15012. return E_BMI160_NULL_PTR;
  15013. } else {
  15014. /* enable gyro offset*/
  15015. v_status_s8 = bmi160_set_gyro_offset_enable(
  15016. GYRO_OFFSET_ENABLE);
  15017. /* write gyro manual offset z axis*/
  15018. if (v_status_s8 == SUCCESS) {
  15019. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  15020. (p_bmi160->dev_addr,
  15021. BMI160_USER_OFFSET_5_GYRO_OFF_Z__REG,
  15022. &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15023. if (com_rslt == SUCCESS) {
  15024. v_data1_u8r =
  15025. ((u8) (v_gyro_off_z_s16 &
  15026. BMI160_GYRO_MANUAL_OFFSET_0_7));
  15027. v_data2_u8r = BMI160_SET_BITSLICE(
  15028. v_data2_u8r,
  15029. BMI160_USER_OFFSET_5_GYRO_OFF_Z,
  15030. v_data1_u8r);
  15031. /* write 0x76 bit 0 to 7*/
  15032. com_rslt +=
  15033. p_bmi160->BMI160_BUS_WRITE_FUNC
  15034. (p_bmi160->dev_addr,
  15035. BMI160_USER_OFFSET_5_GYRO_OFF_Z__REG,
  15036. &v_data2_u8r,
  15037. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15038. /*Accel and Gyro power mode check*/
  15039. if (bmi160_power_mode_status_u8_g !=
  15040. BMI160_NORMAL_MODE)
  15041. /*interface idle time delay */
  15042. p_bmi160->delay_msec(
  15043. BMI160_GEN_READ_WRITE_DELAY);
  15044. }
  15045. com_rslt += p_bmi160->BMI160_BUS_READ_FUNC
  15046. (p_bmi160->dev_addr,
  15047. BMI160_USER_OFFSET_6_GYRO_OFF_Z__REG,
  15048. &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15049. if (com_rslt == SUCCESS) {
  15050. v_data3_u8r =
  15051. (u16) (v_gyro_off_z_s16 &
  15052. BMI160_GYRO_MANUAL_OFFSET_8_9);
  15053. v_data1_u8r = (u8)(v_data3_u8r
  15054. >> BMI160_SHIFT_BIT_POSITION_BY_08_BITS);
  15055. v_data2_u8r = BMI160_SET_BITSLICE(
  15056. v_data2_u8r,
  15057. BMI160_USER_OFFSET_6_GYRO_OFF_Z,
  15058. v_data1_u8r);
  15059. /* write 0x77 bit 4 and 5*/
  15060. com_rslt +=
  15061. p_bmi160->BMI160_BUS_WRITE_FUNC
  15062. (p_bmi160->dev_addr,
  15063. BMI160_USER_OFFSET_6_GYRO_OFF_Z__REG,
  15064. &v_data2_u8r,
  15065. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15066. /*Accel and Gyro power mode check*/
  15067. if (bmi160_power_mode_status_u8_g !=
  15068. BMI160_NORMAL_MODE)
  15069. /*interface idle time delay */
  15070. p_bmi160->delay_msec(
  15071. BMI160_GEN_READ_WRITE_DELAY);
  15072. }
  15073. } else {
  15074. return ERROR;
  15075. }
  15076. }
  15077. return com_rslt;
  15078. }
  15079. /*!
  15080. * @brief This API reads the Accel offset enable bit
  15081. * from the register 0x77 bit 6
  15082. *
  15083. *
  15084. *
  15085. * @param v_accel_off_enable_u8: The value of Accel offset enable
  15086. * value | Description
  15087. * ----------|--------------
  15088. * 0x01 | ENABLE
  15089. * 0x00 | DISABLE
  15090. *
  15091. *
  15092. * @return results of bus communication function
  15093. * @retval 0 -> Success
  15094. * @retval -1 -> Error
  15095. *
  15096. *
  15097. */
  15098. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_offset_enable(
  15099. u8 *v_accel_off_enable_u8)
  15100. {
  15101. /* variable used to return the status of communication result*/
  15102. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15103. u8 v_data_u8 = BMI160_INIT_VALUE;
  15104. /* check the p_bmi160 structure for NULL pointer assignment*/
  15105. if (p_bmi160 == BMI160_NULL) {
  15106. return E_BMI160_NULL_PTR;
  15107. } else {
  15108. /* read Accel offset enable */
  15109. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  15110. (p_bmi160->dev_addr,
  15111. BMI160_USER_OFFSET_6_ACCEL_OFF_ENABLE__REG,
  15112. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15113. *v_accel_off_enable_u8 = BMI160_GET_BITSLICE(v_data_u8,
  15114. BMI160_USER_OFFSET_6_ACCEL_OFF_ENABLE);
  15115. }
  15116. return com_rslt;
  15117. }
  15118. /*!
  15119. * @brief This API writes the Accel offset enable bit
  15120. * in the register 0x77 bit 6
  15121. *
  15122. *
  15123. *
  15124. * @param v_accel_off_enable_u8: The value of Accel offset enable
  15125. * value | Description
  15126. * ----------|--------------
  15127. * 0x01 | ENABLE
  15128. * 0x00 | DISABLE
  15129. *
  15130. *
  15131. * @return results of bus communication function
  15132. * @retval 0 -> Success
  15133. * @retval -1 -> Error
  15134. *
  15135. *
  15136. */
  15137. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_offset_enable(
  15138. u8 v_accel_off_enable_u8)
  15139. {
  15140. /* variable used to return the status of communication result*/
  15141. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15142. u8 v_data_u8 = BMI160_INIT_VALUE;
  15143. /* check the p_bmi160 structure for NULL pointer assignment*/
  15144. if (p_bmi160 == BMI160_NULL) {
  15145. return E_BMI160_NULL_PTR;
  15146. } else {
  15147. /* write Accel offset enable */
  15148. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  15149. p_bmi160->dev_addr,
  15150. BMI160_USER_OFFSET_6_ACCEL_OFF_ENABLE__REG,
  15151. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15152. if (com_rslt == SUCCESS) {
  15153. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  15154. BMI160_USER_OFFSET_6_ACCEL_OFF_ENABLE,
  15155. v_accel_off_enable_u8);
  15156. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  15157. p_bmi160->dev_addr,
  15158. BMI160_USER_OFFSET_6_ACCEL_OFF_ENABLE__REG,
  15159. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15160. /*Accel and Gyro power mode check*/
  15161. if (bmi160_power_mode_status_u8_g !=
  15162. BMI160_NORMAL_MODE)
  15163. /*interface idle time delay */
  15164. p_bmi160->delay_msec(
  15165. BMI160_GEN_READ_WRITE_DELAY);
  15166. }
  15167. }
  15168. return com_rslt;
  15169. }
  15170. /*!
  15171. * @brief This API reads the Accel offset enable bit
  15172. * from the register 0x77 bit 7
  15173. *
  15174. *
  15175. *
  15176. * @param v_gyro_off_enable_u8: The value of gyro offset enable
  15177. * value | Description
  15178. * ----------|--------------
  15179. * 0x01 | ENABLE
  15180. * 0x00 | DISABLE
  15181. *
  15182. *
  15183. * @return results of bus communication function
  15184. * @retval 0 -> Success
  15185. * @retval -1 -> Error
  15186. *
  15187. *
  15188. */
  15189. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_offset_enable(
  15190. u8 *v_gyro_off_enable_u8)
  15191. {
  15192. /* variable used to return the status of communication result*/
  15193. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15194. u8 v_data_u8 = BMI160_INIT_VALUE;
  15195. /* check the p_bmi160 structure for NULL pointer assignment*/
  15196. if (p_bmi160 == BMI160_NULL) {
  15197. return E_BMI160_NULL_PTR;
  15198. } else {
  15199. /* read gyro offset*/
  15200. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  15201. p_bmi160->dev_addr,
  15202. BMI160_USER_OFFSET_6_GYRO_OFF_EN__REG,
  15203. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15204. *v_gyro_off_enable_u8 = BMI160_GET_BITSLICE(v_data_u8,
  15205. BMI160_USER_OFFSET_6_GYRO_OFF_EN);
  15206. }
  15207. return com_rslt;
  15208. }
  15209. /*!
  15210. * @brief This API writes the gyro offset enable bit
  15211. * in the register 0x77 bit 7
  15212. *
  15213. *
  15214. *
  15215. * @param v_gyro_off_enable_u8: The value of gyro offset enable
  15216. * value | Description
  15217. * ----------|--------------
  15218. * 0x01 | ENABLE
  15219. * 0x00 | DISABLE
  15220. *
  15221. *
  15222. * @return results of bus communication function
  15223. * @retval 0 -> Success
  15224. * @retval -1 -> Error
  15225. *
  15226. *
  15227. */
  15228. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_offset_enable(
  15229. u8 v_gyro_off_enable_u8)
  15230. {
  15231. /* variable used to return the status of communication result*/
  15232. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15233. u8 v_data_u8 = BMI160_INIT_VALUE;
  15234. /* check the p_bmi160 structure for NULL pointer assignment*/
  15235. if (p_bmi160 == BMI160_NULL) {
  15236. return E_BMI160_NULL_PTR;
  15237. } else {
  15238. /* write gyro offset*/
  15239. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  15240. p_bmi160->dev_addr,
  15241. BMI160_USER_OFFSET_6_GYRO_OFF_EN__REG,
  15242. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15243. if (com_rslt == SUCCESS) {
  15244. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  15245. BMI160_USER_OFFSET_6_GYRO_OFF_EN,
  15246. v_gyro_off_enable_u8);
  15247. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  15248. p_bmi160->dev_addr,
  15249. BMI160_USER_OFFSET_6_GYRO_OFF_EN__REG,
  15250. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15251. /*Accel and Gyro power mode check*/
  15252. if (bmi160_power_mode_status_u8_g !=
  15253. BMI160_NORMAL_MODE)
  15254. /*interface idle time delay */
  15255. p_bmi160->delay_msec(
  15256. BMI160_GEN_READ_WRITE_DELAY);
  15257. }
  15258. }
  15259. return com_rslt;
  15260. }
  15261. /*!
  15262. * @brief This API reads step counter output value
  15263. * from the register 0x78 and 0x79
  15264. *
  15265. *
  15266. *
  15267. *
  15268. * @param v_step_cnt_s16 : The value of step counter output
  15269. *
  15270. *
  15271. *
  15272. * @return results of bus communication function
  15273. * @retval 0 -> Success
  15274. * @retval -1 -> Error
  15275. *
  15276. *
  15277. */
  15278. BMI160_RETURN_FUNCTION_TYPE bmi160_read_step_count(s16 *v_step_cnt_s16)
  15279. {
  15280. /* variable used to return the status of communication result*/
  15281. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15282. /* array having the step counter LSB and MSB data
  15283. v_data_u8[0] - LSB
  15284. v_data_u8[1] - MSB*/
  15285. u8 a_data_u8r[BMI160_STEP_COUNT_DATA_SIZE] = {BMI160_INIT_VALUE,
  15286. BMI160_INIT_VALUE};
  15287. /* check the p_bmi160 structure for NULL pointer assignment*/
  15288. if (p_bmi160 == BMI160_NULL) {
  15289. return E_BMI160_NULL_PTR;
  15290. } else {
  15291. /* read step counter */
  15292. com_rslt =
  15293. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  15294. BMI160_USER_STEP_COUNT_LSB__REG,
  15295. a_data_u8r, BMI160_STEP_COUNTER_LENGTH);
  15296. *v_step_cnt_s16 = (s16)
  15297. ((((s32)((s8)a_data_u8r[BMI160_STEP_COUNT_MSB_BYTE]))
  15298. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  15299. | (a_data_u8r[BMI160_STEP_COUNT_LSB_BYTE]));
  15300. }
  15301. return com_rslt;
  15302. }
  15303. /*!
  15304. * @brief This API reads
  15305. * step counter configuration
  15306. * from the register 0x7A bit 0 to 7
  15307. * and also from the register 0x7B bit 0 to 2 and 4 to 7
  15308. *
  15309. *
  15310. * @param v_step_config_u16 : The value of step counter configuration
  15311. *
  15312. * @return results of bus communication function
  15313. * @retval 0 -> Success
  15314. * @retval -1 -> Error
  15315. *
  15316. *
  15317. */
  15318. BMI160_RETURN_FUNCTION_TYPE bmi160_get_step_config(
  15319. u16 *v_step_config_u16)
  15320. {
  15321. /* variable used to return the status of communication result*/
  15322. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15323. u8 v_data1_u8r = BMI160_INIT_VALUE;
  15324. u8 v_data2_u8r = BMI160_INIT_VALUE;
  15325. u16 v_data3_u8r = BMI160_INIT_VALUE;
  15326. /* Read the 0 to 7 bit*/
  15327. com_rslt =
  15328. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  15329. BMI160_USER_STEP_CONFIG_ZERO__REG,
  15330. &v_data1_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15331. /* Read the 8 to 10 bit*/
  15332. com_rslt +=
  15333. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  15334. BMI160_USER_STEP_CONFIG_ONE_CNF1__REG,
  15335. &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15336. v_data2_u8r = BMI160_GET_BITSLICE(v_data2_u8r,
  15337. BMI160_USER_STEP_CONFIG_ONE_CNF1);
  15338. v_data3_u8r = ((u16)((((u32)
  15339. ((u8)v_data2_u8r))
  15340. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) | (v_data1_u8r)));
  15341. /* Read the 11 to 14 bit*/
  15342. com_rslt +=
  15343. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  15344. BMI160_USER_STEP_CONFIG_ONE_CNF2__REG,
  15345. &v_data1_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15346. v_data1_u8r = BMI160_GET_BITSLICE(v_data1_u8r,
  15347. BMI160_USER_STEP_CONFIG_ONE_CNF2);
  15348. *v_step_config_u16 = ((u16)((((u32)
  15349. ((u8)v_data1_u8r))
  15350. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) | (v_data3_u8r)));
  15351. return com_rslt;
  15352. }
  15353. /*!
  15354. * @brief This API writes the
  15355. * step counter configuration
  15356. * in the register 0x7A bit 0 to 7
  15357. * and also in the register 0x7B bit 0 to 2 and 4 to 7
  15358. *
  15359. *
  15360. * @param v_step_config_u16 :
  15361. * the value of step configuration
  15362. *
  15363. * @return results of bus communication function
  15364. * @retval 0 -> Success
  15365. * @retval -1 -> Error
  15366. *
  15367. *
  15368. */
  15369. BMI160_RETURN_FUNCTION_TYPE bmi160_set_step_config(
  15370. u16 v_step_config_u16)
  15371. {
  15372. /* variable used to return the status of communication result*/
  15373. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15374. u8 v_data1_u8r = BMI160_INIT_VALUE;
  15375. u8 v_data2_u8r = BMI160_INIT_VALUE;
  15376. u16 v_data3_u16 = BMI160_INIT_VALUE;
  15377. /* write the 0 to 7 bit*/
  15378. v_data1_u8r = (u8)(v_step_config_u16 &
  15379. BMI160_STEP_CONFIG_0_7);
  15380. p_bmi160->BMI160_BUS_WRITE_FUNC
  15381. (p_bmi160->dev_addr,
  15382. BMI160_USER_STEP_CONFIG_ZERO__REG,
  15383. &v_data1_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15384. /*Accel and Gyro power mode check*/
  15385. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  15386. /*interface idle time delay */
  15387. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  15388. /* write the 8 to 10 bit*/
  15389. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  15390. (p_bmi160->dev_addr,
  15391. BMI160_USER_STEP_CONFIG_ONE_CNF1__REG,
  15392. &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15393. if (com_rslt == SUCCESS) {
  15394. v_data3_u16 = (u16) (v_step_config_u16 &
  15395. BMI160_STEP_CONFIG_8_10);
  15396. v_data1_u8r = (u8)(v_data3_u16
  15397. >> BMI160_SHIFT_BIT_POSITION_BY_08_BITS);
  15398. v_data2_u8r = BMI160_SET_BITSLICE(v_data2_u8r,
  15399. BMI160_USER_STEP_CONFIG_ONE_CNF1, v_data1_u8r);
  15400. p_bmi160->BMI160_BUS_WRITE_FUNC
  15401. (p_bmi160->dev_addr,
  15402. BMI160_USER_STEP_CONFIG_ONE_CNF1__REG,
  15403. &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15404. /*Accel and Gyro power mode check*/
  15405. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  15406. /*interface idle time delay */
  15407. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  15408. }
  15409. /* write the 11 to 14 bit*/
  15410. com_rslt += p_bmi160->BMI160_BUS_READ_FUNC
  15411. (p_bmi160->dev_addr,
  15412. BMI160_USER_STEP_CONFIG_ONE_CNF2__REG,
  15413. &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15414. if (com_rslt == SUCCESS) {
  15415. v_data3_u16 = (u16) (v_step_config_u16 &
  15416. BMI160_STEP_CONFIG_11_14);
  15417. v_data1_u8r = (u8)(v_data3_u16
  15418. >> BMI160_SHIFT_BIT_POSITION_BY_12_BITS);
  15419. v_data2_u8r = BMI160_SET_BITSLICE(v_data2_u8r,
  15420. BMI160_USER_STEP_CONFIG_ONE_CNF2, v_data1_u8r);
  15421. p_bmi160->BMI160_BUS_WRITE_FUNC
  15422. (p_bmi160->dev_addr,
  15423. BMI160_USER_STEP_CONFIG_ONE_CNF2__REG,
  15424. &v_data2_u8r, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15425. /*Accel and Gyro power mode check*/
  15426. if (bmi160_power_mode_status_u8_g != BMI160_NORMAL_MODE)
  15427. /*interface idle time delay */
  15428. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  15429. }
  15430. return com_rslt;
  15431. }
  15432. /*!
  15433. * @brief This API is used to get the step counter enable/disable status
  15434. * from the register 0x7B bit 3
  15435. *
  15436. *
  15437. * @param v_step_counter_u8 : The value of step counter enable
  15438. *
  15439. * @return results of bus communication function
  15440. * @retval 0 -> Success
  15441. * @retval -1 -> Error
  15442. *
  15443. *
  15444. */
  15445. BMI160_RETURN_FUNCTION_TYPE bmi160_get_step_counter_enable(
  15446. u8 *v_step_counter_u8)
  15447. {
  15448. /* variable used to return the status of communication result*/
  15449. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15450. u8 v_data_u8 = BMI160_INIT_VALUE;
  15451. /* check the p_bmi160 structure for NULL pointer assignment*/
  15452. if (p_bmi160 == BMI160_NULL) {
  15453. return E_BMI160_NULL_PTR;
  15454. } else {
  15455. /* read the step counter */
  15456. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  15457. p_bmi160->dev_addr,
  15458. BMI160_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE__REG,
  15459. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15460. *v_step_counter_u8 = BMI160_GET_BITSLICE(v_data_u8,
  15461. BMI160_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE);
  15462. }
  15463. return com_rslt;
  15464. }
  15465. /*!
  15466. * @brief This API is used to enable step counter
  15467. * by setting the register 0x7B bit 3
  15468. *
  15469. *
  15470. * @param v_step_counter_u8 : The value of step counter enable
  15471. *
  15472. * @return results of bus communication function
  15473. * @retval 0 -> Success
  15474. * @retval -1 -> Error
  15475. *
  15476. *
  15477. */
  15478. BMI160_RETURN_FUNCTION_TYPE bmi160_set_step_counter_enable(u8 v_step_counter_u8)
  15479. {
  15480. /* variable used to return the status of communication result*/
  15481. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15482. u8 v_data_u8 = BMI160_INIT_VALUE;
  15483. /* check the p_bmi160 structure for NULL pointer assignment*/
  15484. if (p_bmi160 == BMI160_NULL) {
  15485. return E_BMI160_NULL_PTR;
  15486. } else {
  15487. if (v_step_counter_u8 <= BMI160_MAX_GYRO_STEP_COUNTER) {
  15488. /* write the step counter */
  15489. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  15490. (p_bmi160->dev_addr,
  15491. BMI160_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE__REG,
  15492. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15493. if (com_rslt == SUCCESS) {
  15494. v_data_u8 =
  15495. BMI160_SET_BITSLICE(v_data_u8,
  15496. BMI160_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE,
  15497. v_step_counter_u8);
  15498. com_rslt +=
  15499. p_bmi160->BMI160_BUS_WRITE_FUNC
  15500. (p_bmi160->dev_addr,
  15501. BMI160_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE__REG,
  15502. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15503. /*Accel and Gyro power mode check*/
  15504. if (bmi160_power_mode_status_u8_g !=
  15505. BMI160_NORMAL_MODE)
  15506. /*interface idle time delay */
  15507. p_bmi160->delay_msec(
  15508. BMI160_GEN_READ_WRITE_DELAY);
  15509. }
  15510. } else {
  15511. com_rslt = E_BMI160_OUT_OF_RANGE;
  15512. }
  15513. }
  15514. return com_rslt;
  15515. }
  15516. /*!
  15517. * @brief This API is used to set step counter modes
  15518. *
  15519. *
  15520. * @param v_step_mode_u8 : The value of step counter mode
  15521. * value | mode
  15522. * ----------|-----------
  15523. * 0 | BMI160_STEP_NORMAL_MODE
  15524. * 1 | BMI160_STEP_SENSITIVE_MODE
  15525. * 2 | BMI160_STEP_ROBUST_MODE
  15526. *
  15527. * @return results of bus communication function
  15528. * @retval 0 -> Success
  15529. * @retval -1 -> Error
  15530. *
  15531. *
  15532. */
  15533. BMI160_RETURN_FUNCTION_TYPE bmi160_set_step_mode(u8 v_step_mode_u8)
  15534. {
  15535. /* variable used to return the status of communication result*/
  15536. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15537. switch (v_step_mode_u8) {
  15538. case BMI160_STEP_NORMAL_MODE:
  15539. com_rslt = bmi160_set_step_config(
  15540. STEP_CONFIG_NORMAL);
  15541. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  15542. break;
  15543. case BMI160_STEP_SENSITIVE_MODE:
  15544. com_rslt = bmi160_set_step_config(
  15545. STEP_CONFIG_SENSITIVE);
  15546. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  15547. break;
  15548. case BMI160_STEP_ROBUST_MODE:
  15549. com_rslt = bmi160_set_step_config(
  15550. STEP_CONFIG_ROBUST);
  15551. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  15552. break;
  15553. default:
  15554. com_rslt = E_BMI160_OUT_OF_RANGE;
  15555. break;
  15556. }
  15557. return com_rslt;
  15558. }
  15559. /*!
  15560. * @brief This API is used to trigger the signification motion
  15561. * interrupt
  15562. *
  15563. *
  15564. * @param v_significant_u8 : The value of interrupt selection
  15565. * value | interrupt
  15566. * ----------|-----------
  15567. * 0 | BMI160_MAP_INTR1
  15568. * 1 | BMI160_MAP_INTR2
  15569. *
  15570. * @return results of bus communication function
  15571. * @retval 0 -> Success
  15572. * @retval -1 -> Error
  15573. *
  15574. *
  15575. */
  15576. BMI160_RETURN_FUNCTION_TYPE bmi160_map_significant_motion_intr(
  15577. u8 v_significant_u8)
  15578. {
  15579. /* variable used to return the status of communication result*/
  15580. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15581. u8 v_sig_motion_u8 = BMI160_INIT_VALUE;
  15582. u8 v_data_u8 = BMI160_INIT_VALUE;
  15583. u8 v_any_motion_intr1_stat_u8 = BMI160_ENABLE_ANY_MOTION_INTR1;
  15584. u8 v_any_motion_intr2_stat_u8 = BMI160_ENABLE_ANY_MOTION_INTR2;
  15585. u8 v_any_motion_axis_stat_u8 = BMI160_ENABLE_ANY_MOTION_AXIS;
  15586. /* enable the significant motion interrupt */
  15587. com_rslt = bmi160_get_intr_significant_motion_select(&v_sig_motion_u8);
  15588. if (v_sig_motion_u8 != BMI160_SIG_MOTION_STAT_HIGH)
  15589. com_rslt += bmi160_set_intr_significant_motion_select(
  15590. BMI160_SIG_MOTION_INTR_ENABLE);
  15591. switch (v_significant_u8) {
  15592. case BMI160_MAP_INTR1:
  15593. /* interrupt */
  15594. com_rslt += bmi160_read_reg(
  15595. BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG,
  15596. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15597. v_data_u8 |= v_any_motion_intr1_stat_u8;
  15598. /* map the signification interrupt to any-motion interrupt1*/
  15599. com_rslt += bmi160_write_reg(
  15600. BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG,
  15601. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15602. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  15603. /* axis*/
  15604. com_rslt = bmi160_read_reg(BMI160_USER_INTR_ENABLE_0_ADDR,
  15605. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15606. v_data_u8 |= v_any_motion_axis_stat_u8;
  15607. com_rslt += bmi160_write_reg(
  15608. BMI160_USER_INTR_ENABLE_0_ADDR,
  15609. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15610. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  15611. break;
  15612. case BMI160_MAP_INTR2:
  15613. /* map the signification interrupt to any-motion interrupt2*/
  15614. com_rslt += bmi160_read_reg(
  15615. BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG,
  15616. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15617. v_data_u8 |= v_any_motion_intr2_stat_u8;
  15618. com_rslt += bmi160_write_reg(
  15619. BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG,
  15620. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15621. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  15622. /* axis*/
  15623. com_rslt = bmi160_read_reg(BMI160_USER_INTR_ENABLE_0_ADDR,
  15624. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15625. v_data_u8 |= v_any_motion_axis_stat_u8;
  15626. com_rslt += bmi160_write_reg(
  15627. BMI160_USER_INTR_ENABLE_0_ADDR,
  15628. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15629. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  15630. break;
  15631. default:
  15632. com_rslt = E_BMI160_OUT_OF_RANGE;
  15633. break;
  15634. }
  15635. return com_rslt;
  15636. }
  15637. /*!
  15638. * @brief This API is used to trigger the step detector
  15639. * interrupt
  15640. *
  15641. *
  15642. * @param v_step_detector_u8 : The value of interrupt selection
  15643. * value | interrupt
  15644. * ----------|-----------
  15645. * 0 | BMI160_MAP_INTR1
  15646. * 1 | BMI160_MAP_INTR2
  15647. *
  15648. * @return results of bus communication function
  15649. * @retval 0 -> Success
  15650. * @retval -1 -> Error
  15651. *
  15652. *
  15653. */
  15654. BMI160_RETURN_FUNCTION_TYPE bmi160_map_step_detector_intr(
  15655. u8 v_step_detector_u8)
  15656. {
  15657. /* variable used to return the status of communication result*/
  15658. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15659. u8 v_step_det_u8 = BMI160_INIT_VALUE;
  15660. u8 v_data_u8 = BMI160_INIT_VALUE;
  15661. u8 v_low_g_intr_u81_stat_u8 = BMI160_LOW_G_INTR_STAT;
  15662. u8 v_low_g_intr_u82_stat_u8 = BMI160_LOW_G_INTR_STAT;
  15663. /* read the v_status_s8 of step detector interrupt*/
  15664. com_rslt = bmi160_get_step_detector_enable(&v_step_det_u8);
  15665. if (v_step_det_u8 != BMI160_STEP_DET_STAT_HIGH)
  15666. com_rslt += bmi160_set_step_detector_enable(
  15667. BMI160_STEP_DETECT_INTR_ENABLE);
  15668. switch (v_step_detector_u8) {
  15669. case BMI160_MAP_INTR1:
  15670. com_rslt += bmi160_read_reg(
  15671. BMI160_USER_INTR_MAP_0_INTR1_LOW_G__REG,
  15672. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15673. v_data_u8 |= v_low_g_intr_u81_stat_u8;
  15674. /* map the step detector interrupt
  15675. to Low-g interrupt 1*/
  15676. com_rslt += bmi160_write_reg(
  15677. BMI160_USER_INTR_MAP_0_INTR1_LOW_G__REG,
  15678. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15679. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  15680. break;
  15681. case BMI160_MAP_INTR2:
  15682. /* map the step detector interrupt
  15683. to Low-g interrupt 2*/
  15684. com_rslt += bmi160_read_reg(
  15685. BMI160_USER_INTR_MAP_2_INTR2_LOW_G__REG,
  15686. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15687. v_data_u8 |= v_low_g_intr_u82_stat_u8;
  15688. com_rslt += bmi160_write_reg(
  15689. BMI160_USER_INTR_MAP_2_INTR2_LOW_G__REG,
  15690. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15691. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  15692. break;
  15693. default:
  15694. com_rslt = E_BMI160_OUT_OF_RANGE;
  15695. break;
  15696. }
  15697. return com_rslt;
  15698. }
  15699. /*!
  15700. * @brief This API is used to clear the step counter interrupt
  15701. *
  15702. *
  15703. * @param : None
  15704. *
  15705. *
  15706. * @return results of bus communication function
  15707. * @retval 0 -> Success
  15708. * @retval -1 -> Error
  15709. *
  15710. *
  15711. */
  15712. BMI160_RETURN_FUNCTION_TYPE bmi160_clear_step_counter(void)
  15713. {
  15714. /* variable used to return the status of communication result*/
  15715. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15716. /* clear the step counter*/
  15717. com_rslt = bmi160_set_command_register(RESET_STEP_COUNTER);
  15718. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  15719. return com_rslt;
  15720. }
  15721. /*!
  15722. * @brief This API writes the value to the register 0x7E bit 0 to 7
  15723. *
  15724. *
  15725. * @param v_command_reg_u8 : The value to write command register
  15726. * value | Description
  15727. * ---------|--------------------------------------------------------
  15728. * 0x00 | Reserved
  15729. * 0x03 | Starts fast offset calibration for the Accel and gyro
  15730. * 0x10 | Sets the PMU mode for the Accel to suspend
  15731. * 0x11 | Sets the PMU mode for the Accel to normal
  15732. * 0x12 | Sets the PMU mode for the Accel Lowpower
  15733. * 0x14 | Sets the PMU mode for the Gyro to suspend
  15734. * 0x15 | Sets the PMU mode for the Gyro to normal
  15735. * 0x16 | Reserved
  15736. * 0x17 | Sets the PMU mode for the Gyro to fast start-up
  15737. * 0x18 | Sets the PMU mode for the Mag to suspend
  15738. * 0x19 | Sets the PMU mode for the Mag to normal
  15739. * 0x1A | Sets the PMU mode for the Mag to Lowpower
  15740. * 0xB0 | Clears all data in the FIFO
  15741. * 0xB1 | Resets the interrupt engine
  15742. * 0xB2 | step_cnt_clr Clears the step counter
  15743. * 0xB6 | Triggers a reset
  15744. *
  15745. * @return results of bus communication function
  15746. * @retval 0 -> Success
  15747. * @retval -1 -> Error
  15748. *
  15749. *
  15750. */
  15751. BMI160_RETURN_FUNCTION_TYPE bmi160_set_command_register(u8 v_command_reg_u8)
  15752. {
  15753. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15754. /* check the p_bmi160 structure for NULL pointer assignment*/
  15755. if (p_bmi160 == BMI160_NULL) {
  15756. return E_BMI160_NULL_PTR;
  15757. } else {
  15758. /* write command register */
  15759. com_rslt = p_bmi160->BMI160_BUS_WRITE_FUNC(
  15760. p_bmi160->dev_addr,
  15761. BMI160_CMD_COMMANDS__REG,
  15762. &v_command_reg_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15763. /*interface idle time delay */
  15764. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  15765. /*power mode status of Accel and gyro is stored in the
  15766. global variable bmi160_power_mode_status_u8_g */
  15767. com_rslt += bmi160_read_reg(BMI160_USER_PMU_STAT_ADDR,
  15768. &bmi160_power_mode_status_u8_g,
  15769. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  15770. bmi160_power_mode_status_u8_g &=
  15771. BMI160_ACCEL_GYRO_PMU_MASK;
  15772. }
  15773. return com_rslt;
  15774. }
  15775. /*!
  15776. * @brief This function is used to read the compensated xyz axis data of
  15777. * mag secondary interface
  15778. * @note v_mag_x_s16: The value of Mag x data
  15779. * @note v_mag_y_s16: The value of Mag y data
  15780. * @note v_mag_z_s16: The value of Mag z data
  15781. * @note v_mag_r_s16: The value of Mag r data
  15782. * @param v_mag_second_if_u8: The value of Mag selection
  15783. *
  15784. * value | v_mag_second_if_u8
  15785. * ---------|----------------------
  15786. * 0 | BMM150
  15787. * 1 | AKM09911
  15788. * 2 | AKM09912
  15789. * 3 | YAS532
  15790. * 4 | YAS537
  15791. * @param mag_fifo_data: The value of compensated Mag xyz data
  15792. *
  15793. *
  15794. * @return
  15795. *
  15796. *
  15797. */
  15798. BMI160_RETURN_FUNCTION_TYPE bmi160_second_if_mag_compensate_xyz(
  15799. struct bmi160_mag_fifo_data_t mag_fifo_data,
  15800. u8 v_mag_second_if_u8)
  15801. {
  15802. s8 com_rslt = BMI160_INIT_VALUE;
  15803. s16 v_mag_x_s16 = BMI160_INIT_VALUE;
  15804. s16 v_mag_y_s16 = BMI160_INIT_VALUE;
  15805. s16 v_mag_z_s16 = BMI160_INIT_VALUE;
  15806. u16 v_mag_r_u16 = BMI160_INIT_VALUE;
  15807. #ifdef YAS537
  15808. u8 v_outflow_u8 = BMI160_INIT_VALUE;
  15809. u8 v_busy_u8 = BMI160_INIT_VALUE;
  15810. u8 v_coil_stat_u8 = BMI160_INIT_VALUE;
  15811. u16 v_temperature_u16 = BMI160_INIT_VALUE;
  15812. s32 a_h_s32[BMI160_YAS_H_DATA_SIZE] = {
  15813. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  15814. s32 a_s_s32[BMI160_YAS_S_DATA_SIZE] = {
  15815. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  15816. u16 xy1y2[3] = {
  15817. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  15818. #endif
  15819. #ifdef YAS532
  15820. u16 v_xy1y2_u16[3] = {
  15821. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  15822. u8 v_busy_yas532_u8 = BMI160_INIT_VALUE;
  15823. u16 v_temp_yas532_u16 = BMI160_INIT_VALUE;
  15824. u8 v_overflow_yas532_u8 = BMI160_INIT_VALUE;
  15825. #endif
  15826. switch (v_mag_second_if_u8) {
  15827. case BMI160_SEC_IF_BMM150:
  15828. /* x data*/
  15829. v_mag_x_s16 = (s16)((mag_fifo_data.mag_x_msb
  15830. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  15831. | (mag_fifo_data.mag_x_lsb));
  15832. v_mag_x_s16 = (s16)
  15833. (v_mag_x_s16 >> BMI160_SHIFT_BIT_POSITION_BY_03_BITS);
  15834. /* y data*/
  15835. v_mag_y_s16 = (s16)((mag_fifo_data.mag_y_msb
  15836. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  15837. | (mag_fifo_data.mag_y_lsb));
  15838. v_mag_y_s16 = (s16)
  15839. (v_mag_y_s16 >> BMI160_SHIFT_BIT_POSITION_BY_03_BITS);
  15840. /* z data*/
  15841. v_mag_z_s16 = (s16)((mag_fifo_data.mag_z_msb
  15842. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  15843. | (mag_fifo_data.mag_z_lsb));
  15844. v_mag_z_s16 = (s16)
  15845. (v_mag_z_s16 >> BMI160_SHIFT_BIT_POSITION_BY_01_BIT);
  15846. /* r data*/
  15847. v_mag_r_u16 = (u16)((mag_fifo_data.mag_r_y2_msb
  15848. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  15849. | (mag_fifo_data.mag_r_y2_lsb));
  15850. v_mag_r_u16 = (u16)
  15851. (v_mag_r_u16 >> BMI160_SHIFT_BIT_POSITION_BY_02_BITS);
  15852. /* Compensated Mag x data */
  15853. processed_data.x =
  15854. bmi160_bmm150_mag_compensate_X(v_mag_x_s16,
  15855. v_mag_r_u16);
  15856. /* Compensated Mag y data */
  15857. processed_data.y =
  15858. bmi160_bmm150_mag_compensate_Y(v_mag_y_s16,
  15859. v_mag_r_u16);
  15860. /* Compensated Mag z data */
  15861. processed_data.z =
  15862. bmi160_bmm150_mag_compensate_Z(v_mag_z_s16,
  15863. v_mag_r_u16);
  15864. break;
  15865. #ifdef AKM09911
  15866. case BMI160_SEC_IF_AKM09911:
  15867. /* x data*/
  15868. v_mag_x_s16 = (s16)((mag_fifo_data.mag_x_msb
  15869. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  15870. | (mag_fifo_data.mag_x_lsb));
  15871. /* y data*/
  15872. v_mag_y_s16 = (s16)((mag_fifo_data.mag_y_msb
  15873. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  15874. | (mag_fifo_data.mag_y_lsb));
  15875. /* z data*/
  15876. v_mag_z_s16 = (s16)((mag_fifo_data.mag_z_msb
  15877. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  15878. | (mag_fifo_data.mag_z_lsb));
  15879. /* Compensated for X data */
  15880. processed_data.x =
  15881. bmi160_bst_akm09911_compensate_X(v_mag_x_s16);
  15882. /* Compensated for Y data */
  15883. processed_data.y =
  15884. bmi160_bst_akm09911_compensate_Y(v_mag_y_s16);
  15885. /* Compensated for Z data */
  15886. processed_data.z =
  15887. bmi160_bst_akm09911_compensate_Z(v_mag_z_s16);
  15888. break;
  15889. #endif
  15890. #ifdef AKM09912
  15891. case BMI160_SEC_IF_AKM09912:
  15892. /* x data*/
  15893. v_mag_x_s16 = (s16)((mag_fifo_data.mag_x_msb
  15894. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  15895. | (mag_fifo_data.mag_x_lsb));
  15896. /* y data*/
  15897. v_mag_y_s16 = (s16)((mag_fifo_data.mag_y_msb
  15898. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  15899. | (mag_fifo_data.mag_y_lsb));
  15900. /* z data*/
  15901. v_mag_z_s16 = (s16)((mag_fifo_data.mag_z_msb
  15902. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  15903. | (mag_fifo_data.mag_z_lsb));
  15904. /* Compensated for X data */
  15905. processed_data.x =
  15906. bmi160_bst_akm09912_compensate_X(v_mag_x_s16);
  15907. /* Compensated for Y data */
  15908. processed_data.y =
  15909. bmi160_bst_akm09912_compensate_Y(v_mag_y_s16);
  15910. /* Compensated for Z data */
  15911. processed_data.z =
  15912. bmi160_bst_akm09912_compensate_Z(v_mag_z_s16);
  15913. break;
  15914. #endif
  15915. #ifdef YAS532
  15916. case BMI160_SEC_IF_YAS532:{
  15917. u8 i = BMI160_INIT_VALUE;
  15918. /* read the xyy1 data*/
  15919. v_busy_yas532_u8 =
  15920. ((mag_fifo_data.mag_x_lsb
  15921. >> BMI160_SHIFT_BIT_POSITION_BY_07_BITS) & 0x01);
  15922. v_temp_yas532_u16 =
  15923. (u16)((((s32)mag_fifo_data.mag_x_lsb
  15924. << BMI160_SHIFT_BIT_POSITION_BY_03_BITS)
  15925. & 0x3F8) | ((mag_fifo_data.mag_x_msb
  15926. >> BMI160_SHIFT_BIT_POSITION_BY_05_BITS) & 0x07));
  15927. v_xy1y2_u16[0] =
  15928. (u16)((((s32)mag_fifo_data.mag_y_lsb
  15929. << BMI160_SHIFT_BIT_POSITION_BY_06_BITS) & 0x1FC0)
  15930. | ((mag_fifo_data.mag_y_msb >>
  15931. BMI160_SHIFT_BIT_POSITION_BY_02_BITS) & 0x3F));
  15932. v_xy1y2_u16[1] =
  15933. (u16)((((s32)mag_fifo_data.mag_z_lsb
  15934. << BMI160_SHIFT_BIT_POSITION_BY_06_BITS)
  15935. & 0x1FC0)
  15936. | ((mag_fifo_data.mag_z_msb
  15937. >> BMI160_SHIFT_BIT_POSITION_BY_02_BITS) & 0x3F));
  15938. v_xy1y2_u16[2] =
  15939. (u16)((((s32)mag_fifo_data.mag_r_y2_lsb
  15940. << BMI160_SHIFT_BIT_POSITION_BY_06_BITS)
  15941. & 0x1FC0)
  15942. | ((mag_fifo_data.mag_r_y2_msb
  15943. >> BMI160_SHIFT_BIT_POSITION_BY_02_BITS) & 0x3F));
  15944. v_overflow_yas532_u8 = 0;
  15945. for (i = 0; i < 3; i++) {
  15946. if (v_xy1y2_u16[i] == YAS532_DATA_OVERFLOW)
  15947. v_overflow_yas532_u8 |= (1 << (i * 2));
  15948. if (v_xy1y2_u16[i] == YAS532_DATA_UNDERFLOW)
  15949. v_overflow_yas532_u8 |= (1 << (i * 2 + 1));
  15950. }
  15951. /* assign the data*/
  15952. com_rslt = bmi160_bst_yas532_fifo_xyz_data(
  15953. v_xy1y2_u16, 1, v_overflow_yas532_u8,
  15954. v_temp_yas532_u16, v_busy_yas532_u8);
  15955. processed_data.x =
  15956. fifo_xyz_data.yas532_vector_xyz[0];
  15957. processed_data.y =
  15958. fifo_xyz_data.yas532_vector_xyz[1];
  15959. processed_data.z =
  15960. fifo_xyz_data.yas532_vector_xyz[2];
  15961. }
  15962. break;
  15963. #endif
  15964. #ifdef YAS537
  15965. case BMI160_SEC_IF_YAS537:{
  15966. u8 i = BMI160_INIT_VALUE;
  15967. /* read the busy flag*/
  15968. v_busy_u8 = mag_fifo_data.mag_y_lsb
  15969. >> BMI160_SHIFT_BIT_POSITION_BY_07_BITS;
  15970. /* read the coil status*/
  15971. v_coil_stat_u8 =
  15972. ((mag_fifo_data.mag_y_lsb >>
  15973. BMI160_SHIFT_BIT_POSITION_BY_06_BITS) & 0X01);
  15974. /* read temperature data*/
  15975. v_temperature_u16 = (u16)((mag_fifo_data.mag_x_lsb
  15976. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  15977. | mag_fifo_data.mag_x_msb);
  15978. /* read x data*/
  15979. xy1y2[0] = (u16)(((mag_fifo_data.mag_y_lsb &
  15980. 0x3F)
  15981. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  15982. | (mag_fifo_data.mag_y_msb));
  15983. /* read y1 data*/
  15984. xy1y2[1] = (u16)((mag_fifo_data.mag_z_lsb
  15985. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  15986. | mag_fifo_data.mag_z_msb);
  15987. /* read y2 data*/
  15988. xy1y2[2] = (u16)((mag_fifo_data.mag_r_y2_lsb
  15989. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  15990. | mag_fifo_data.mag_r_y2_msb);
  15991. for (i = 0; i < 3; i++)
  15992. yas537_data.last_raw[i] = xy1y2[i];
  15993. yas537_data.last_raw[i] = v_temperature_u16;
  15994. if (yas537_data.calib_yas537.ver == 1) {
  15995. for (i = 0; i < 3; i++)
  15996. a_s_s32[i] = xy1y2[i] - 8192;
  15997. /* read hx*/
  15998. a_h_s32[0] = ((yas537_data.calib_yas537.k * (
  15999. (128 * a_s_s32[0]) +
  16000. (yas537_data.calib_yas537.a2 * a_s_s32[1]) +
  16001. (yas537_data.calib_yas537.a3 * a_s_s32[2])))
  16002. / (8192));
  16003. /* read hy1*/
  16004. a_h_s32[1] = ((yas537_data.calib_yas537.k * (
  16005. (yas537_data.calib_yas537.a4 * a_s_s32[0]) +
  16006. (yas537_data.calib_yas537.a5 * a_s_s32[1]) +
  16007. (yas537_data.calib_yas537.a6 * a_s_s32[2])))
  16008. / (8192));
  16009. /* read hy2*/
  16010. a_h_s32[2] = ((yas537_data.calib_yas537.k * (
  16011. (yas537_data.calib_yas537.a7 * a_s_s32[0]) +
  16012. (yas537_data.calib_yas537.a8 * a_s_s32[1]) +
  16013. (yas537_data.calib_yas537.a9 * a_s_s32[2])))
  16014. / (8192));
  16015. for (i = 0; i < 3; i++) {
  16016. if (a_h_s32[i] < -8192)
  16017. a_h_s32[i] = -8192;
  16018. if (8192 < a_h_s32[i])
  16019. a_h_s32[i] = 8192;
  16020. xy1y2[i] = a_h_s32[i] + 8192;
  16021. }
  16022. }
  16023. v_outflow_u8 = 0;
  16024. for (i = 0; i < 3; i++) {
  16025. if (YAS537_DATA_OVERFLOW
  16026. <= xy1y2[i])
  16027. v_outflow_u8 |=
  16028. (1 << (i * 2));
  16029. if (xy1y2[i] ==
  16030. YAS537_DATA_UNDERFLOW)
  16031. v_outflow_u8
  16032. |= (1 << (i * 2 + 1));
  16033. }
  16034. com_rslt = bmi160_bst_yamaha_yas537_fifo_xyz_data(
  16035. xy1y2, v_outflow_u8, v_coil_stat_u8, v_busy_u8);
  16036. processed_data.x =
  16037. fifo_vector_xyz.yas537_vector_xyz[0];
  16038. processed_data.y =
  16039. fifo_vector_xyz.yas537_vector_xyz[1];
  16040. processed_data.z =
  16041. fifo_vector_xyz.yas537_vector_xyz[2];
  16042. }
  16043. break;
  16044. #endif
  16045. default:
  16046. com_rslt = E_BMI160_OUT_OF_RANGE;
  16047. break;
  16048. }
  16049. return com_rslt;
  16050. }
  16051. #ifdef FIFO_ENABLE
  16052. /*!
  16053. * @brief This function is used to read the
  16054. * fifo data of header mode
  16055. *
  16056. *
  16057. * @note Configure the below functions for FIFO header mode
  16058. * @note 1. bmi160_set_fifo_down_gyro()
  16059. * @note 2. bmi160_set_gyro_fifo_filter_data()
  16060. * @note 3. bmi160_set_fifo_down_accel()
  16061. * @note 4. bmi160_set_accel_fifo_filter_dat()
  16062. * @note 5. bmi160_set_fifo_mag_enable()
  16063. * @note 6. bmi160_set_fifo_accel_enable()
  16064. * @note 7. bmi160_set_fifo_gyro_enable()
  16065. * @note 8. bmi160_set_fifo_header_enable()
  16066. * @note For interrupt configuration
  16067. * @note 1. bmi160_set_intr_fifo_full()
  16068. * @note 2. bmi160_set_intr_fifo_wm()
  16069. * @note 3. bmi160_set_fifo_tag_intr2_enable()
  16070. * @note 4. bmi160_set_fifo_tag_intr1_enable()
  16071. *
  16072. *
  16073. * @return results of bus communication function
  16074. * @retval 0 -> Success
  16075. * @retval -1 -> Error
  16076. *
  16077. *
  16078. */
  16079. BMI160_RETURN_FUNCTION_TYPE bmi160_read_fifo_header_data(u8 v_mag_if_u8,
  16080. struct bmi160_fifo_data_header_t *header_data)
  16081. {
  16082. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  16083. /* read the whole FIFO data*/
  16084. com_rslt =
  16085. bmi160_read_fifo_header_data_user_defined_length(
  16086. FIFO_FRAME, v_mag_if_u8, header_data);
  16087. return com_rslt;
  16088. }
  16089. /*!
  16090. * @brief This function is used to read the
  16091. * fifo data of header mode for user defined length
  16092. *
  16093. *
  16094. * @note Configure the below functions for FIFO header mode
  16095. * @note 1. bmi160_set_fifo_down_gyro()
  16096. * @note 2. bmi160_set_gyro_fifo_filter_data()
  16097. * @note 3. bmi160_set_fifo_down_accel()
  16098. * @note 4. bmi160_set_accel_fifo_filter_dat()
  16099. * @note 5. bmi160_set_fifo_mag_enable()
  16100. * @note 6. bmi160_set_fifo_accel_enable()
  16101. * @note 7. bmi160_set_fifo_gyro_enable()
  16102. * @note 8. bmi160_set_fifo_header_enable()
  16103. * @note For interrupt configuration
  16104. * @note 1. bmi160_set_intr_fifo_full()
  16105. * @note 2. bmi160_set_intr_fifo_wm()
  16106. * @note 3. bmi160_set_fifo_tag_intr2_enable()
  16107. * @note 4. bmi160_set_fifo_tag_intr1_enable()
  16108. *
  16109. *
  16110. * @return results of bus communication function
  16111. * @retval 0 -> Success
  16112. * @retval -1 -> Error
  16113. *
  16114. *
  16115. */
  16116. BMI160_RETURN_FUNCTION_TYPE bmi160_read_fifo_header_data_user_defined_length(
  16117. u16 v_fifo_user_length_u16, u8 v_mag_if_mag_u8,
  16118. struct bmi160_fifo_data_header_t *fifo_header_data)
  16119. {
  16120. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  16121. u8 v_accel_index_u8 = BMI160_INIT_VALUE;
  16122. u8 v_gyro_index_u8 = BMI160_INIT_VALUE;
  16123. u8 v_mag_index_u8 = BMI160_INIT_VALUE;
  16124. s8 v_last_return_stat_s8 = BMI160_INIT_VALUE;
  16125. u16 v_fifo_index_u16 = BMI160_INIT_VALUE;
  16126. u8 v_frame_head_u8 = BMI160_INIT_VALUE;
  16127. u8 v_frame_index_u8 = BMI160_INIT_VALUE;
  16128. u16 v_fifo_length_u16 = BMI160_INIT_VALUE;
  16129. fifo_header_data->accel_frame_count = BMI160_INIT_VALUE;
  16130. fifo_header_data->mag_frame_count = BMI160_INIT_VALUE;
  16131. fifo_header_data->gyro_frame_count = BMI160_INIT_VALUE;
  16132. /* read FIFO data*/
  16133. com_rslt = bmi160_fifo_data(&v_fifo_data_u8[BMI160_INIT_VALUE],
  16134. v_fifo_user_length_u16);
  16135. v_fifo_length_u16 = v_fifo_user_length_u16;
  16136. for (v_fifo_index_u16 = BMI160_INIT_VALUE;
  16137. v_fifo_index_u16 < v_fifo_length_u16;) {
  16138. fifo_header_data->fifo_header[v_frame_index_u8]
  16139. = v_fifo_data_u8[v_fifo_index_u16];
  16140. v_frame_head_u8 =
  16141. fifo_header_data->fifo_header[v_frame_index_u8]
  16142. & BMI160_FIFO_TAG_INTR_MASK;
  16143. v_frame_index_u8++;
  16144. switch (v_frame_head_u8) {
  16145. /* Header frame of Accel */
  16146. case FIFO_HEAD_A:
  16147. { /*fifo data frame index + 1*/
  16148. v_fifo_index_u16 = v_fifo_index_u16 +
  16149. BMI160_FIFO_INDEX_LENGTH;
  16150. if ((v_fifo_index_u16 + BMI160_FIFO_A_LENGTH)
  16151. > v_fifo_length_u16) {
  16152. v_last_return_stat_s8 = FIFO_A_OVER_LEN;
  16153. break;
  16154. }
  16155. /* Accel raw x data */
  16156. fifo_header_data->accel_fifo[v_accel_index_u8].x =
  16157. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16158. BMI160_FIFO_X_MSB_DATA])
  16159. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16160. | (v_fifo_data_u8[v_fifo_index_u16 +
  16161. BMI160_FIFO_X_LSB_DATA]));
  16162. /* Accel raw y data */
  16163. fifo_header_data->accel_fifo[v_accel_index_u8].y =
  16164. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16165. BMI160_FIFO_Y_MSB_DATA])
  16166. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16167. | (v_fifo_data_u8[v_fifo_index_u16 +
  16168. BMI160_FIFO_Y_LSB_DATA]));
  16169. /* Accel raw z data */
  16170. fifo_header_data->accel_fifo[v_accel_index_u8].z =
  16171. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16172. BMI160_FIFO_Z_MSB_DATA])
  16173. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16174. | (v_fifo_data_u8[v_fifo_index_u16 +
  16175. BMI160_FIFO_Z_LSB_DATA]));
  16176. /* check for Accel frame count*/
  16177. fifo_header_data->accel_frame_count =
  16178. fifo_header_data->accel_frame_count
  16179. + BMI160_FRAME_COUNT;
  16180. v_fifo_index_u16 = v_fifo_index_u16 +
  16181. BMI160_FIFO_A_LENGTH;
  16182. v_accel_index_u8++;
  16183. break;
  16184. }
  16185. /* Header frame of gyro */
  16186. case FIFO_HEAD_G:
  16187. { /*fifo data frame index + 1*/
  16188. v_fifo_index_u16 = v_fifo_index_u16
  16189. + BMI160_FIFO_INDEX_LENGTH;
  16190. if ((v_fifo_index_u16 + BMI160_FIFO_G_LENGTH) >
  16191. v_fifo_length_u16) {
  16192. v_last_return_stat_s8 = FIFO_G_OVER_LEN;
  16193. break;
  16194. }
  16195. /* Gyro raw x data */
  16196. fifo_header_data->gyro_fifo[v_gyro_index_u8].x =
  16197. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16198. BMI160_FIFO_X_MSB_DATA])
  16199. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16200. | (v_fifo_data_u8[v_fifo_index_u16 +
  16201. BMI160_FIFO_X_LSB_DATA]));
  16202. /* Gyro raw y data */
  16203. fifo_header_data->gyro_fifo[v_gyro_index_u8].y =
  16204. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16205. BMI160_FIFO_Y_MSB_DATA])
  16206. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16207. | (v_fifo_data_u8[v_fifo_index_u16 +
  16208. BMI160_FIFO_Y_LSB_DATA]));
  16209. /* Gyro raw z data */
  16210. fifo_header_data->gyro_fifo[v_gyro_index_u8].z =
  16211. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16212. BMI160_FIFO_Z_MSB_DATA])
  16213. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16214. | (v_fifo_data_u8[v_fifo_index_u16 +
  16215. BMI160_FIFO_Z_LSB_DATA]));
  16216. /* check for gyro frame count*/
  16217. fifo_header_data->gyro_frame_count =
  16218. fifo_header_data->gyro_frame_count + BMI160_FRAME_COUNT;
  16219. /*fifo G data frame index + 6*/
  16220. v_fifo_index_u16 = v_fifo_index_u16 +
  16221. BMI160_FIFO_G_LENGTH;
  16222. v_gyro_index_u8++;
  16223. break;
  16224. }
  16225. /* Header frame of Mag */
  16226. case FIFO_HEAD_M:
  16227. { /*fifo data frame index + 1*/
  16228. v_fifo_index_u16 = v_fifo_index_u16
  16229. + BMI160_FIFO_INDEX_LENGTH;
  16230. if ((v_fifo_index_u16 + BMI160_FIFO_M_LENGTH) >
  16231. (v_fifo_length_u16)) {
  16232. v_last_return_stat_s8 = FIFO_M_OVER_LEN;
  16233. break;
  16234. }
  16235. /* Mag x data*/
  16236. mag_data.mag_x_lsb =
  16237. (v_fifo_data_u8[v_fifo_index_u16 +
  16238. BMI160_FIFO_X_LSB_DATA]);
  16239. mag_data.mag_x_msb =
  16240. (v_fifo_data_u8[v_fifo_index_u16 +
  16241. BMI160_FIFO_X_MSB_DATA]);
  16242. /* Mag y data*/
  16243. mag_data.mag_y_lsb =
  16244. (v_fifo_data_u8[v_fifo_index_u16 +
  16245. BMI160_FIFO_Y_LSB_DATA]);
  16246. mag_data.mag_y_msb =
  16247. (v_fifo_data_u8[v_fifo_index_u16 +
  16248. BMI160_FIFO_Y_MSB_DATA]);
  16249. mag_data.mag_z_lsb =
  16250. (v_fifo_data_u8[v_fifo_index_u16 +
  16251. BMI160_FIFO_Z_LSB_DATA]);
  16252. mag_data.mag_z_msb =
  16253. (v_fifo_data_u8[v_fifo_index_u16 +
  16254. BMI160_FIFO_Z_MSB_DATA]);
  16255. /* Mag r data*/
  16256. mag_data.mag_r_y2_lsb =
  16257. (v_fifo_data_u8[v_fifo_index_u16 +
  16258. BMI160_FIFO_R_LSB_DATA]);
  16259. mag_data.mag_r_y2_msb =
  16260. (v_fifo_data_u8[v_fifo_index_u16 +
  16261. BMI160_FIFO_R_MSB_DATA]);
  16262. com_rslt = bmi160_second_if_mag_compensate_xyz(mag_data,
  16263. v_mag_if_mag_u8);
  16264. /* compensated Mag x */
  16265. fifo_header_data->mag_fifo[v_gyro_index_u8].x
  16266. = processed_data.x;
  16267. /* compensated Mag y */
  16268. fifo_header_data->mag_fifo[v_gyro_index_u8].y
  16269. = processed_data.y;
  16270. /* compensated Mag z */
  16271. fifo_header_data->mag_fifo[v_gyro_index_u8].z
  16272. = processed_data.z;
  16273. /* check for Mag frame count*/
  16274. fifo_header_data->mag_frame_count =
  16275. fifo_header_data->mag_frame_count
  16276. + BMI160_FRAME_COUNT;
  16277. v_mag_index_u8++;
  16278. /*fifo M data frame index + 8*/
  16279. v_fifo_index_u16 = v_fifo_index_u16 +
  16280. BMI160_FIFO_M_LENGTH;
  16281. break;
  16282. }
  16283. /* Header frame of gyro and Accel */
  16284. case FIFO_HEAD_G_A:
  16285. v_fifo_index_u16 = v_fifo_index_u16 +
  16286. BMI160_FIFO_INDEX_LENGTH;
  16287. if ((v_fifo_index_u16 + BMI160_FIFO_AG_LENGTH)
  16288. > v_fifo_length_u16) {
  16289. v_last_return_stat_s8 = FIFO_G_A_OVER_LEN;
  16290. break;
  16291. }
  16292. /* Raw gyro x */
  16293. fifo_header_data->gyro_fifo[v_gyro_index_u8].x =
  16294. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16295. BMI160_GA_FIFO_G_X_MSB])
  16296. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16297. |(v_fifo_data_u8[v_fifo_index_u16 +
  16298. BMI160_GA_FIFO_G_X_LSB]));
  16299. /* Raw gyro y */
  16300. fifo_header_data->gyro_fifo[v_gyro_index_u8].y =
  16301. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16302. BMI160_GA_FIFO_G_Y_MSB])
  16303. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16304. |(v_fifo_data_u8[v_fifo_index_u16 +
  16305. BMI160_GA_FIFO_G_Y_LSB]));
  16306. /* Raw gyro z */
  16307. fifo_header_data->gyro_fifo[v_gyro_index_u8].z =
  16308. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16309. BMI160_GA_FIFO_G_Z_MSB])
  16310. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16311. |(v_fifo_data_u8[v_fifo_index_u16 +
  16312. BMI160_GA_FIFO_G_Z_LSB]));
  16313. /* check for gyro frame count*/
  16314. fifo_header_data->gyro_frame_count =
  16315. fifo_header_data->gyro_frame_count + BMI160_FRAME_COUNT;
  16316. /* Raw Accel x */
  16317. fifo_header_data->accel_fifo[v_accel_index_u8].x =
  16318. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16319. BMI160_GA_FIFO_A_X_MSB])
  16320. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16321. |(v_fifo_data_u8[v_fifo_index_u16 +
  16322. BMI160_GA_FIFO_A_X_LSB]));
  16323. /* Raw Accel y */
  16324. fifo_header_data->accel_fifo[v_accel_index_u8].y =
  16325. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16326. BMI160_GA_FIFO_A_Y_MSB])
  16327. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16328. |(v_fifo_data_u8[v_fifo_index_u16 +
  16329. BMI160_GA_FIFO_A_Y_LSB]));
  16330. /* Raw Accel z */
  16331. fifo_header_data->accel_fifo[v_accel_index_u8].z =
  16332. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16333. BMI160_GA_FIFO_A_Z_MSB])
  16334. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16335. |(v_fifo_data_u8[v_fifo_index_u16
  16336. + BMI160_GA_FIFO_A_Z_LSB]));
  16337. /* check for Accel frame count*/
  16338. fifo_header_data->accel_frame_count =
  16339. fifo_header_data->accel_frame_count
  16340. + BMI160_FRAME_COUNT;
  16341. /* Index added to 12 for gyro and Accel*/
  16342. v_fifo_index_u16 = v_fifo_index_u16 +
  16343. BMI160_FIFO_AG_LENGTH;
  16344. v_gyro_index_u8++;
  16345. v_accel_index_u8++;
  16346. break;
  16347. /* Header frame of mag, gyro and Accel */
  16348. case FIFO_HEAD_M_G_A:
  16349. { /*fifo data frame index + 1*/
  16350. v_fifo_index_u16 = v_fifo_index_u16
  16351. + BMI160_FIFO_INDEX_LENGTH;
  16352. if ((v_fifo_index_u16 + BMI160_FIFO_AMG_LENGTH)
  16353. > (v_fifo_length_u16)) {
  16354. v_last_return_stat_s8 = FIFO_M_G_A_OVER_LEN;
  16355. break;
  16356. }
  16357. /* Mag x data*/
  16358. mag_data.mag_x_lsb =
  16359. (v_fifo_data_u8[v_fifo_index_u16 +
  16360. BMI160_FIFO_X_LSB_DATA]);
  16361. mag_data.mag_x_msb =
  16362. (v_fifo_data_u8[v_fifo_index_u16 +
  16363. BMI160_FIFO_X_MSB_DATA]);
  16364. /* Mag y data*/
  16365. mag_data.mag_y_lsb =
  16366. (v_fifo_data_u8[v_fifo_index_u16 +
  16367. BMI160_FIFO_Y_LSB_DATA]);
  16368. mag_data.mag_y_msb =
  16369. (v_fifo_data_u8[v_fifo_index_u16 +
  16370. BMI160_FIFO_Y_MSB_DATA]);
  16371. mag_data.mag_z_lsb =
  16372. (v_fifo_data_u8[v_fifo_index_u16 +
  16373. BMI160_FIFO_Z_LSB_DATA]);
  16374. mag_data.mag_z_msb =
  16375. (v_fifo_data_u8[v_fifo_index_u16 +
  16376. BMI160_FIFO_Z_MSB_DATA]);
  16377. /* Mag r data*/
  16378. mag_data.mag_r_y2_lsb =
  16379. (v_fifo_data_u8[v_fifo_index_u16 +
  16380. BMI160_FIFO_R_LSB_DATA]);
  16381. mag_data.mag_r_y2_msb =
  16382. (v_fifo_data_u8[v_fifo_index_u16 +
  16383. BMI160_FIFO_R_MSB_DATA]);
  16384. /* Processing the compensation data*/
  16385. com_rslt = bmi160_second_if_mag_compensate_xyz(mag_data,
  16386. v_mag_if_mag_u8);
  16387. /* compensated Mag x */
  16388. fifo_header_data->mag_fifo[v_mag_index_u8].x =
  16389. processed_data.x;
  16390. /* compensated Mag y */
  16391. fifo_header_data->mag_fifo[v_mag_index_u8].y =
  16392. processed_data.y;
  16393. /* compensated Mag z */
  16394. fifo_header_data->mag_fifo[v_mag_index_u8].z =
  16395. processed_data.z;
  16396. /* check for Mag frame count*/
  16397. fifo_header_data->mag_frame_count =
  16398. fifo_header_data->mag_frame_count + BMI160_FRAME_COUNT;
  16399. /* Gyro raw x data */
  16400. fifo_header_data->gyro_fifo[v_gyro_index_u8].x =
  16401. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16402. BMI160_MGA_FIFO_G_X_MSB])
  16403. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16404. |(v_fifo_data_u8[v_fifo_index_u16 +
  16405. BMI160_MGA_FIFO_G_X_LSB]));
  16406. /* Gyro raw y data */
  16407. fifo_header_data->gyro_fifo[v_gyro_index_u8].y =
  16408. (s16)(((v_fifo_data_u8[
  16409. v_fifo_index_u16 + BMI160_MGA_FIFO_G_Y_MSB])
  16410. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16411. |(v_fifo_data_u8[v_fifo_index_u16 +
  16412. BMI160_MGA_FIFO_G_Y_LSB]));
  16413. /* Gyro raw z data */
  16414. fifo_header_data->gyro_fifo[v_gyro_index_u8].z =
  16415. (s16)(((v_fifo_data_u8[
  16416. v_fifo_index_u16 + BMI160_MGA_FIFO_G_Z_MSB])
  16417. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16418. |(v_fifo_data_u8[
  16419. v_fifo_index_u16 + BMI160_MGA_FIFO_G_Z_LSB]));
  16420. /* check for gyro frame count*/
  16421. fifo_header_data->gyro_frame_count =
  16422. fifo_header_data->gyro_frame_count + BMI160_FRAME_COUNT;
  16423. /* Accel raw x data */
  16424. fifo_header_data->accel_fifo[v_accel_index_u8].x =
  16425. (s16)(((v_fifo_data_u8[
  16426. v_fifo_index_u16 + BMI160_MGA_FIFO_A_X_MSB])
  16427. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16428. |(v_fifo_data_u8[v_fifo_index_u16 +
  16429. BMI160_MGA_FIFO_A_X_LSB]));
  16430. /* Accel raw y data */
  16431. fifo_header_data->accel_fifo[v_accel_index_u8].y =
  16432. (s16)(((v_fifo_data_u8[
  16433. v_fifo_index_u16 + BMI160_MGA_FIFO_A_Y_MSB])
  16434. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16435. |(v_fifo_data_u8[v_fifo_index_u16 +
  16436. BMI160_MGA_FIFO_A_Y_LSB]));
  16437. /* Accel raw z data */
  16438. fifo_header_data->accel_fifo[v_accel_index_u8].z =
  16439. (s16)(((v_fifo_data_u8[
  16440. v_fifo_index_u16 + BMI160_MGA_FIFO_A_Z_MSB])
  16441. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16442. |(v_fifo_data_u8[v_fifo_index_u16 +
  16443. BMI160_MGA_FIFO_A_Z_LSB]));
  16444. /* check for Accel frame count*/
  16445. fifo_header_data->accel_frame_count =
  16446. fifo_header_data->accel_frame_count
  16447. + BMI160_FRAME_COUNT;
  16448. /* Index added to 20 for mag, gyro and Accel*/
  16449. v_fifo_index_u16 = v_fifo_index_u16 +
  16450. BMI160_FIFO_AMG_LENGTH;
  16451. v_accel_index_u8++;
  16452. v_mag_index_u8++;
  16453. v_gyro_index_u8++;
  16454. break;
  16455. }
  16456. /* Header frame of Mag and Accel */
  16457. case FIFO_HEAD_M_A:
  16458. { /*fifo data frame index + 1*/
  16459. v_fifo_index_u16 = v_fifo_index_u16
  16460. + BMI160_GEN_READ_WRITE_DATA_LENGTH;
  16461. if ((v_fifo_index_u16 + BMI160_FIFO_MA_OR_MG_LENGTH)
  16462. > (v_fifo_length_u16)) {
  16463. v_last_return_stat_s8 = FIFO_M_A_OVER_LEN;
  16464. break;
  16465. }
  16466. /* Mag x data*/
  16467. mag_data.mag_x_lsb =
  16468. (v_fifo_data_u8[v_fifo_index_u16 +
  16469. BMI160_FIFO_X_LSB_DATA]);
  16470. mag_data.mag_x_msb = (v_fifo_data_u8[v_fifo_index_u16 +
  16471. BMI160_FIFO_X_MSB_DATA]);
  16472. /* Mag y data*/
  16473. mag_data.mag_y_lsb =
  16474. (v_fifo_data_u8[v_fifo_index_u16 +
  16475. BMI160_FIFO_Y_LSB_DATA]);
  16476. mag_data.mag_y_msb =
  16477. (v_fifo_data_u8[v_fifo_index_u16 +
  16478. BMI160_FIFO_Y_MSB_DATA]);
  16479. mag_data.mag_z_lsb =
  16480. (v_fifo_data_u8[v_fifo_index_u16 +
  16481. BMI160_FIFO_Z_LSB_DATA]);
  16482. mag_data.mag_z_msb =
  16483. (v_fifo_data_u8[v_fifo_index_u16 +
  16484. BMI160_FIFO_Z_MSB_DATA]);
  16485. /* Mag r data*/
  16486. mag_data.mag_r_y2_lsb =
  16487. (v_fifo_data_u8[v_fifo_index_u16 +
  16488. BMI160_FIFO_R_LSB_DATA]);
  16489. mag_data.mag_r_y2_msb =
  16490. (v_fifo_data_u8[v_fifo_index_u16 +
  16491. BMI160_FIFO_R_MSB_DATA]);
  16492. com_rslt =
  16493. bmi160_second_if_mag_compensate_xyz(mag_data,
  16494. v_mag_if_mag_u8);
  16495. /* compensated Mag x */
  16496. fifo_header_data->mag_fifo[v_mag_index_u8].x =
  16497. processed_data.x;
  16498. /* compensated Mag y */
  16499. fifo_header_data->mag_fifo[v_mag_index_u8].y =
  16500. processed_data.y;
  16501. /* compensated Mag z */
  16502. fifo_header_data->mag_fifo[v_mag_index_u8].z =
  16503. processed_data.z;
  16504. /* check for Mag frame count*/
  16505. fifo_header_data->mag_frame_count =
  16506. fifo_header_data->mag_frame_count
  16507. + BMI160_FRAME_COUNT;
  16508. /* Accel raw x data */
  16509. fifo_header_data->accel_fifo[v_accel_index_u8].x =
  16510. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16511. BMI160_MA_FIFO_A_X_MSB])
  16512. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16513. |(v_fifo_data_u8[v_fifo_index_u16 +
  16514. BMI160_MA_FIFO_A_X_LSB]));
  16515. /* Accel raw y data */
  16516. fifo_header_data->accel_fifo[v_accel_index_u8].y =
  16517. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16518. BMI160_MA_FIFO_A_Y_MSB])
  16519. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16520. |(v_fifo_data_u8[v_fifo_index_u16 +
  16521. BMI160_MA_FIFO_A_Y_LSB]));
  16522. /* Accel raw z data */
  16523. fifo_header_data->accel_fifo[v_accel_index_u8].z =
  16524. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16525. BMI160_MA_FIFO_A_Z_MSB])
  16526. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16527. |(v_fifo_data_u8[v_fifo_index_u16 +
  16528. BMI160_MA_FIFO_A_Z_LSB]));
  16529. /* check for Accel frame count*/
  16530. fifo_header_data->accel_frame_count =
  16531. fifo_header_data->accel_frame_count
  16532. + BMI160_FRAME_COUNT;
  16533. /*fifo AM data frame index + 14(8+6)*/
  16534. v_fifo_index_u16 = v_fifo_index_u16 +
  16535. BMI160_FIFO_MA_OR_MG_LENGTH;
  16536. v_accel_index_u8++;
  16537. v_mag_index_u8++;
  16538. break;
  16539. }
  16540. /* Header frame of Mag and gyro */
  16541. case FIFO_HEAD_M_G:
  16542. {
  16543. /*fifo data frame index + 1*/
  16544. v_fifo_index_u16 = v_fifo_index_u16
  16545. + BMI160_GEN_READ_WRITE_DATA_LENGTH;
  16546. if ((v_fifo_index_u16 + BMI160_FIFO_MA_OR_MG_LENGTH)
  16547. > v_fifo_length_u16) {
  16548. v_last_return_stat_s8 = FIFO_M_G_OVER_LEN;
  16549. break;
  16550. }
  16551. /* Mag x data*/
  16552. mag_data.mag_x_lsb =
  16553. (v_fifo_data_u8[v_fifo_index_u16 +
  16554. BMI160_FIFO_X_LSB_DATA]);
  16555. mag_data.mag_x_msb =
  16556. (v_fifo_data_u8[v_fifo_index_u16 +
  16557. BMI160_FIFO_X_MSB_DATA]);
  16558. /* Mag y data*/
  16559. mag_data.mag_y_lsb =
  16560. (v_fifo_data_u8[v_fifo_index_u16 +
  16561. BMI160_FIFO_Y_LSB_DATA]);
  16562. mag_data.mag_y_msb =
  16563. (v_fifo_data_u8[v_fifo_index_u16 +
  16564. BMI160_FIFO_Y_MSB_DATA]);
  16565. mag_data.mag_z_lsb =
  16566. (v_fifo_data_u8[v_fifo_index_u16 +
  16567. BMI160_FIFO_Z_LSB_DATA]);
  16568. mag_data.mag_z_msb =
  16569. (v_fifo_data_u8[v_fifo_index_u16 +
  16570. BMI160_FIFO_Z_MSB_DATA]);
  16571. /* Mag r data*/
  16572. mag_data.mag_r_y2_lsb =
  16573. (v_fifo_data_u8[v_fifo_index_u16 +
  16574. BMI160_FIFO_R_LSB_DATA]);
  16575. mag_data.mag_r_y2_msb =
  16576. (v_fifo_data_u8[v_fifo_index_u16 +
  16577. BMI160_FIFO_R_MSB_DATA]);
  16578. com_rslt =
  16579. bmi160_second_if_mag_compensate_xyz(mag_data,
  16580. v_mag_if_mag_u8);
  16581. /* compensated Mag x */
  16582. fifo_header_data->mag_fifo[v_mag_index_u8].x =
  16583. processed_data.x;
  16584. /* compensated Mag y */
  16585. fifo_header_data->mag_fifo[v_mag_index_u8].y =
  16586. processed_data.y;
  16587. /* compensated Mag z */
  16588. fifo_header_data->mag_fifo[v_mag_index_u8].z =
  16589. processed_data.z;
  16590. /* check for Mag frame count*/
  16591. fifo_header_data->mag_frame_count =
  16592. fifo_header_data->mag_frame_count + BMI160_FRAME_COUNT;
  16593. /* Gyro raw x data */
  16594. fifo_header_data->gyro_fifo[v_gyro_index_u8].x =
  16595. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16596. BMI160_MG_FIFO_G_X_MSB])
  16597. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16598. |(v_fifo_data_u8[v_fifo_index_u16 +
  16599. BMI160_MG_FIFO_G_X_LSB]));
  16600. /* Gyro raw y data */
  16601. fifo_header_data->gyro_fifo[v_gyro_index_u8].y =
  16602. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16603. BMI160_MG_FIFO_G_Y_MSB])
  16604. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16605. |(v_fifo_data_u8[v_fifo_index_u16 +
  16606. BMI160_MG_FIFO_G_Y_LSB]));
  16607. /* Gyro raw z data */
  16608. fifo_header_data->gyro_fifo[v_gyro_index_u8].z =
  16609. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16610. BMI160_MG_FIFO_G_Z_MSB])
  16611. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16612. |(v_fifo_data_u8[v_fifo_index_u16 +
  16613. BMI160_MG_FIFO_G_Z_LSB]));
  16614. /* check for gyro frame count*/
  16615. fifo_header_data->gyro_frame_count =
  16616. fifo_header_data->gyro_frame_count
  16617. + BMI160_FRAME_COUNT;
  16618. /*fifo GM data frame index + 14(8+6)*/
  16619. v_fifo_index_u16 = v_fifo_index_u16 +
  16620. BMI160_FIFO_MA_OR_MG_LENGTH;
  16621. v_mag_index_u8++;
  16622. v_gyro_index_u8++;
  16623. break;
  16624. }
  16625. /* Header frame of sensor time */
  16626. case FIFO_HEAD_SENSOR_TIME:
  16627. {
  16628. v_fifo_index_u16 = v_fifo_index_u16 +
  16629. BMI160_GEN_READ_WRITE_DATA_LENGTH;
  16630. if ((v_fifo_index_u16
  16631. + BMI160_FIFO_SENSOR_TIME_LENGTH) >
  16632. (v_fifo_length_u16)) {
  16633. v_last_return_stat_s8
  16634. = FIFO_SENSORTIME_RETURN;
  16635. break;
  16636. }
  16637. /* Sensor time */
  16638. fifo_header_data->fifo_time = (u32)
  16639. ((v_fifo_data_u8[v_fifo_index_u16 +
  16640. BMI160_FIFO_SENSOR_TIME_MSB]
  16641. << BMI160_SHIFT_BIT_POSITION_BY_16_BITS) |
  16642. (v_fifo_data_u8[v_fifo_index_u16 +
  16643. BMI160_FIFO_SENSOR_TIME_XLSB]
  16644. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) |
  16645. (v_fifo_data_u8[v_fifo_index_u16 +
  16646. BMI160_FIFO_SENSOR_TIME_LSB]));
  16647. v_fifo_index_u16 = v_fifo_index_u16 +
  16648. BMI160_FIFO_SENSOR_TIME_LENGTH;
  16649. break;
  16650. }
  16651. /* Header frame of skip frame */
  16652. case FIFO_HEAD_SKIP_FRAME:
  16653. {
  16654. /*fifo data frame index + 1*/
  16655. v_fifo_index_u16 = v_fifo_index_u16 +
  16656. BMI160_FIFO_INDEX_LENGTH;
  16657. if (v_fifo_index_u16
  16658. + BMI160_FIFO_INDEX_LENGTH
  16659. > v_fifo_length_u16) {
  16660. v_last_return_stat_s8 =
  16661. FIFO_SKIP_OVER_LEN;
  16662. break;
  16663. }
  16664. fifo_header_data->skip_frame =
  16665. v_fifo_data_u8[v_fifo_index_u16];
  16666. v_fifo_index_u16 = v_fifo_index_u16 +
  16667. BMI160_FIFO_INDEX_LENGTH;
  16668. break;
  16669. }
  16670. case FIFO_HEAD_INPUT_CONFIG:
  16671. {
  16672. /*fifo data frame index + 1*/
  16673. v_fifo_index_u16 = v_fifo_index_u16 +
  16674. BMI160_FIFO_INDEX_LENGTH;
  16675. if (v_fifo_index_u16
  16676. + BMI160_FIFO_INDEX_LENGTH
  16677. > v_fifo_length_u16) {
  16678. v_last_return_stat_s8 =
  16679. FIFO_INPUT_CONFIG_OVER_LEN;
  16680. break;
  16681. }
  16682. fifo_header_data->fifo_input_config_info
  16683. = v_fifo_data_u8[v_fifo_index_u16];
  16684. v_fifo_index_u16 = v_fifo_index_u16 +
  16685. BMI160_FIFO_INDEX_LENGTH;
  16686. break;
  16687. }
  16688. /* Header frame of over read FIFO data */
  16689. case FIFO_HEAD_OVER_READ_LSB:
  16690. {
  16691. /*fifo data frame index + 1*/
  16692. v_fifo_index_u16 = v_fifo_index_u16 +
  16693. BMI160_FIFO_INDEX_LENGTH;
  16694. if ((v_fifo_index_u16 + BMI160_FIFO_INDEX_LENGTH)
  16695. > (v_fifo_length_u16)) {
  16696. v_last_return_stat_s8 = FIFO_OVER_READ_RETURN;
  16697. break;
  16698. }
  16699. if (v_fifo_data_u8[v_fifo_index_u16] ==
  16700. FIFO_HEAD_OVER_READ_MSB) {
  16701. /*fifo over read frame index + 1*/
  16702. v_fifo_index_u16 = v_fifo_index_u16 +
  16703. BMI160_FIFO_INDEX_LENGTH;
  16704. break;
  16705. } else {
  16706. v_last_return_stat_s8 = FIFO_OVER_READ_RETURN;
  16707. break;
  16708. }
  16709. }
  16710. default:
  16711. v_last_return_stat_s8 = BMI160_FIFO_INDEX_LENGTH;
  16712. break;
  16713. }
  16714. if (v_last_return_stat_s8 != 0)
  16715. break;
  16716. }
  16717. return com_rslt;
  16718. }
  16719. /*!
  16720. * @brief This function is used to read the
  16721. * fifo data for header less mode
  16722. *
  16723. *
  16724. *
  16725. * @note Configure the below functions for FIFO header less mode
  16726. * @note 1. bmi160_set_fifo_down_gyro
  16727. * @note 2. bmi160_set_gyro_fifo_filter_data
  16728. * @note 3. bmi160_set_fifo_down_accel
  16729. * @note 4. bmi160_set_accel_fifo_filter_dat
  16730. * @note 5. bmi160_set_fifo_mag_enable
  16731. * @note 6. bmi160_set_fifo_accel_enable
  16732. * @note 7. bmi160_set_fifo_gyro_enable
  16733. * @note For interrupt configuration
  16734. * @note 1. bmi160_set_intr_fifo_full
  16735. * @note 2. bmi160_set_intr_fifo_wm
  16736. * @note 3. bmi160_set_fifo_tag_intr2_enable
  16737. * @note 4. bmi160_set_fifo_tag_intr1_enable
  16738. *
  16739. *
  16740. * @return results of bus communication function
  16741. * @retval 0 -> Success
  16742. * @retval -1 -> Error
  16743. *
  16744. *
  16745. */
  16746. BMI160_RETURN_FUNCTION_TYPE bmi160_read_fifo_headerless_mode(
  16747. u8 v_mag_if_u8, struct bmi160_fifo_data_header_less_t *headerless_data) {
  16748. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  16749. /* read the whole FIFO data*/
  16750. com_rslt =
  16751. bmi160_read_fifo_headerless_mode_user_defined_length(
  16752. FIFO_FRAME, headerless_data, v_mag_if_u8);
  16753. return com_rslt;
  16754. }
  16755. /*!
  16756. * @brief This function is used to read the
  16757. * fifo data for header less mode according to user defined length
  16758. *
  16759. *
  16760. * @param v_fifo_user_length_u16: length of FIFO data to be read
  16761. * @param v_mag_if_mag_u8 : the Mag interface data
  16762. * @param fifo_data : the pointer to fifo_data_header_less_t structure
  16763. *
  16764. * @note Configure the below functions for FIFO header less mode
  16765. * @note 1. bmi160_set_fifo_down_gyro
  16766. * @note 2. bmi160_set_gyro_fifo_filter_data
  16767. * @note 3. bmi160_set_fifo_down_accel
  16768. * @note 4. bmi160_set_accel_fifo_filter_dat
  16769. * @note 5. bmi160_set_fifo_mag_enable
  16770. * @note 6. bmi160_set_fifo_accel_enable
  16771. * @note 7. bmi160_set_fifo_gyro_enable
  16772. * @note For interrupt configuration
  16773. * @note 1. bmi160_set_intr_fifo_full
  16774. * @note 2. bmi160_set_intr_fifo_wm
  16775. * @note 3. bmi160_set_fifo_tag_intr2_enable
  16776. * @note 4. bmi160_set_fifo_tag_intr1_enable
  16777. *
  16778. *
  16779. * @return results of bus communication function
  16780. * @retval 0 -> Success
  16781. * @retval -1 -> Error
  16782. *
  16783. *
  16784. */
  16785. BMI160_RETURN_FUNCTION_TYPE
  16786. bmi160_read_fifo_headerless_mode_user_defined_length(
  16787. u16 v_fifo_user_length_u16,
  16788. struct bmi160_fifo_data_header_less_t *fifo_data,
  16789. u8 v_mag_if_mag_u8)
  16790. {
  16791. u8 v_data_u8 = BMI160_INIT_VALUE;
  16792. u32 v_fifo_index_u16 = BMI160_INIT_VALUE;
  16793. u32 v_fifo_length_u16 = BMI160_INIT_VALUE;
  16794. u8 v_accel_index_u8 = BMI160_INIT_VALUE;
  16795. u8 v_gyro_index_u8 = BMI160_INIT_VALUE;
  16796. u8 v_mag_index_u8 = BMI160_INIT_VALUE;
  16797. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  16798. fifo_data->accel_frame_count = BMI160_INIT_VALUE;
  16799. fifo_data->mag_frame_count = BMI160_INIT_VALUE;
  16800. fifo_data->gyro_frame_count = BMI160_INIT_VALUE;
  16801. /* disable the header data */
  16802. com_rslt = bmi160_set_fifo_header_enable(BMI160_INIT_VALUE);
  16803. /* read mag, Accel and gyro enable status*/
  16804. com_rslt += bmi160_read_reg(BMI160_USER_FIFO_CONFIG_1_ADDR,
  16805. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  16806. v_data_u8 = v_data_u8 & BMI160_FIFO_M_G_A_ENABLE;
  16807. /* read the FIFO data of 1024 bytes*/
  16808. com_rslt += bmi160_fifo_data(&v_fifo_data_u8[BMI160_INIT_VALUE],
  16809. v_fifo_user_length_u16);
  16810. v_fifo_length_u16 = v_fifo_user_length_u16;
  16811. /* loop for executing the different conditions */
  16812. for (v_fifo_index_u16 = BMI160_INIT_VALUE;
  16813. v_fifo_index_u16 < v_fifo_length_u16;) {
  16814. /* condition for mag, gyro and Accel enable*/
  16815. if (v_data_u8 == BMI160_FIFO_M_G_A_ENABLE) {
  16816. /* Raw Mag x*/
  16817. mag_data.mag_x_lsb =
  16818. (v_fifo_data_u8[v_fifo_index_u16 +
  16819. BMI160_FIFO_X_LSB_DATA]);
  16820. mag_data.mag_x_msb =
  16821. (v_fifo_data_u8[v_fifo_index_u16 +
  16822. BMI160_FIFO_X_MSB_DATA]);
  16823. /* Mag y data*/
  16824. mag_data.mag_y_lsb =
  16825. (v_fifo_data_u8[v_fifo_index_u16 +
  16826. BMI160_FIFO_Y_LSB_DATA]);
  16827. mag_data.mag_y_msb =
  16828. (v_fifo_data_u8[v_fifo_index_u16 +
  16829. BMI160_FIFO_Y_MSB_DATA]);
  16830. /* Mag z data*/
  16831. mag_data.mag_z_lsb =
  16832. (v_fifo_data_u8[v_fifo_index_u16 +
  16833. BMI160_FIFO_Z_LSB_DATA]);
  16834. mag_data.mag_z_msb =
  16835. (v_fifo_data_u8[v_fifo_index_u16 +
  16836. BMI160_FIFO_Z_MSB_DATA]);
  16837. /* Mag r data*/
  16838. mag_data.mag_r_y2_lsb =
  16839. (v_fifo_data_u8[v_fifo_index_u16 +
  16840. BMI160_FIFO_R_LSB_DATA]);
  16841. mag_data.mag_r_y2_msb =
  16842. (v_fifo_data_u8[v_fifo_index_u16 +
  16843. BMI160_FIFO_R_MSB_DATA]);
  16844. com_rslt =
  16845. bmi160_second_if_mag_compensate_xyz(mag_data,
  16846. v_mag_if_mag_u8);
  16847. /* compensated Mag x */
  16848. fifo_data->mag_fifo[v_mag_index_u8].x =
  16849. processed_data.x;
  16850. /* compensated Mag y */
  16851. fifo_data->mag_fifo[v_mag_index_u8].y =
  16852. processed_data.y;
  16853. /* compensated Mag z */
  16854. fifo_data->mag_fifo[v_mag_index_u8].z =
  16855. processed_data.z;
  16856. /* check for Mag frame count*/
  16857. fifo_data->mag_frame_count =
  16858. fifo_data->mag_frame_count + BMI160_FRAME_COUNT;
  16859. /* Gyro raw x v_data_u8 */
  16860. fifo_data->gyro_fifo[v_gyro_index_u8].x =
  16861. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16862. BMI160_MGA_FIFO_G_X_MSB])
  16863. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16864. |(v_fifo_data_u8[v_fifo_index_u16 +
  16865. BMI160_MGA_FIFO_G_X_LSB]));
  16866. /* Gyro raw y v_data_u8 */
  16867. fifo_data->gyro_fifo[v_gyro_index_u8].y =
  16868. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16869. BMI160_MGA_FIFO_G_Y_MSB])
  16870. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16871. |(v_fifo_data_u8[v_fifo_index_u16 +
  16872. BMI160_MGA_FIFO_G_Y_LSB]));
  16873. /* Gyro raw z v_data_u8 */
  16874. fifo_data->gyro_fifo[v_gyro_index_u8].z =
  16875. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16876. BMI160_MGA_FIFO_G_Z_MSB])
  16877. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16878. |(v_fifo_data_u8[v_fifo_index_u16 +
  16879. BMI160_MGA_FIFO_G_Z_LSB]));
  16880. /* check for gyro frame count*/
  16881. fifo_data->gyro_frame_count =
  16882. fifo_data->gyro_frame_count + BMI160_FRAME_COUNT;
  16883. /* Accel raw x v_data_u8 */
  16884. fifo_data->accel_fifo[v_accel_index_u8].x =
  16885. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16886. BMI160_MGA_FIFO_A_X_MSB])
  16887. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16888. |(v_fifo_data_u8[v_fifo_index_u16 +
  16889. BMI160_MGA_FIFO_A_X_LSB]));
  16890. /* Accel raw y v_data_u8 */
  16891. fifo_data->accel_fifo[v_accel_index_u8].y =
  16892. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16893. BMI160_MGA_FIFO_A_Y_MSB])
  16894. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16895. |(v_fifo_data_u8[v_fifo_index_u16 +
  16896. BMI160_MGA_FIFO_A_Y_LSB]));
  16897. /* Accel raw z v_data_u8 */
  16898. fifo_data->accel_fifo[v_accel_index_u8].z =
  16899. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16900. BMI160_MGA_FIFO_A_Z_MSB])
  16901. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16902. |(v_fifo_data_u8[v_fifo_index_u16 +
  16903. BMI160_MGA_FIFO_A_Z_LSB]));
  16904. /* check for Accel frame count*/
  16905. fifo_data->accel_frame_count =
  16906. fifo_data->accel_frame_count + BMI160_FRAME_COUNT;
  16907. v_accel_index_u8++;
  16908. v_mag_index_u8++;
  16909. v_gyro_index_u8++;
  16910. v_fifo_index_u16 = v_fifo_index_u16 +
  16911. BMI160_FIFO_AMG_LENGTH;
  16912. }
  16913. /* condition for Mag and gyro enable*/
  16914. else if (v_data_u8 == BMI160_FIFO_M_G_ENABLE) {
  16915. /* Raw Mag x*/
  16916. mag_data.mag_x_lsb =
  16917. (v_fifo_data_u8[v_fifo_index_u16 +
  16918. BMI160_FIFO_X_LSB_DATA]);
  16919. mag_data.mag_x_msb =
  16920. (v_fifo_data_u8[v_fifo_index_u16 +
  16921. BMI160_FIFO_X_MSB_DATA]);
  16922. /* Mag y data*/
  16923. mag_data.mag_y_lsb =
  16924. (v_fifo_data_u8[v_fifo_index_u16 +
  16925. BMI160_FIFO_Y_LSB_DATA]);
  16926. mag_data.mag_y_msb =
  16927. (v_fifo_data_u8[v_fifo_index_u16 +
  16928. BMI160_FIFO_Y_MSB_DATA]);
  16929. /* Mag z data*/
  16930. mag_data.mag_z_lsb =
  16931. (v_fifo_data_u8[v_fifo_index_u16 +
  16932. BMI160_FIFO_Z_LSB_DATA]);
  16933. mag_data.mag_z_msb =
  16934. (v_fifo_data_u8[v_fifo_index_u16 +
  16935. BMI160_FIFO_Z_MSB_DATA]);
  16936. /* Mag r data*/
  16937. mag_data.mag_r_y2_lsb =
  16938. (v_fifo_data_u8[v_fifo_index_u16 +
  16939. BMI160_FIFO_R_LSB_DATA]);
  16940. mag_data.mag_r_y2_msb =
  16941. (v_fifo_data_u8[v_fifo_index_u16 +
  16942. BMI160_FIFO_R_MSB_DATA]);
  16943. com_rslt = bmi160_second_if_mag_compensate_xyz(mag_data,
  16944. v_mag_if_mag_u8);
  16945. /* compensated Mag x */
  16946. fifo_data->mag_fifo[v_mag_index_u8].x =
  16947. processed_data.x;
  16948. /* compensated Mag y */
  16949. fifo_data->mag_fifo[v_mag_index_u8].y =
  16950. processed_data.y;
  16951. /* compensated Mag z */
  16952. fifo_data->mag_fifo[v_mag_index_u8].z =
  16953. processed_data.z;
  16954. /* check for Mag frame count*/
  16955. fifo_data->mag_frame_count =
  16956. fifo_data->mag_frame_count + BMI160_FRAME_COUNT;
  16957. /* Gyro raw x v_data_u8 */
  16958. fifo_data->gyro_fifo[v_gyro_index_u8].x =
  16959. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16960. BMI160_MG_FIFO_G_X_MSB])
  16961. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16962. |(v_fifo_data_u8[v_fifo_index_u16 +
  16963. BMI160_MG_FIFO_G_X_LSB]));
  16964. /* Gyro raw y v_data_u8 */
  16965. fifo_data->gyro_fifo[v_gyro_index_u8].y =
  16966. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16967. BMI160_MG_FIFO_G_Y_MSB])
  16968. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16969. |(v_fifo_data_u8[v_fifo_index_u16 +
  16970. BMI160_MG_FIFO_G_Y_LSB]));
  16971. /* Gyro raw z v_data_u8 */
  16972. fifo_data->gyro_fifo[v_gyro_index_u8].z =
  16973. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  16974. BMI160_MG_FIFO_G_Z_MSB])
  16975. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  16976. |(v_fifo_data_u8[v_fifo_index_u16 +
  16977. BMI160_MG_FIFO_G_Z_LSB]));
  16978. /* check for gyro frame count*/
  16979. fifo_data->gyro_frame_count =
  16980. fifo_data->gyro_frame_count + BMI160_FRAME_COUNT;
  16981. v_gyro_index_u8++;
  16982. v_mag_index_u8++;
  16983. v_fifo_index_u16 = v_fifo_index_u16 +
  16984. BMI160_FIFO_MA_OR_MG_LENGTH;
  16985. }
  16986. /* condition for Mag and Accel enable*/
  16987. else if (v_data_u8 == BMI160_FIFO_M_A_ENABLE) {
  16988. /* Raw Mag x*/
  16989. mag_data.mag_x_lsb =
  16990. (v_fifo_data_u8[v_fifo_index_u16 +
  16991. BMI160_FIFO_X_LSB_DATA]);
  16992. mag_data.mag_x_msb =
  16993. (v_fifo_data_u8[v_fifo_index_u16 +
  16994. BMI160_FIFO_X_MSB_DATA]);
  16995. /* Mag y data*/
  16996. mag_data.mag_y_lsb =
  16997. (v_fifo_data_u8[v_fifo_index_u16 +
  16998. BMI160_FIFO_Y_LSB_DATA]);
  16999. mag_data.mag_y_msb =
  17000. (v_fifo_data_u8[v_fifo_index_u16 +
  17001. BMI160_FIFO_Y_MSB_DATA]);
  17002. /* Mag z data*/
  17003. mag_data.mag_z_lsb =
  17004. (v_fifo_data_u8[v_fifo_index_u16 +
  17005. BMI160_FIFO_Z_LSB_DATA]);
  17006. mag_data.mag_z_msb =
  17007. (v_fifo_data_u8[v_fifo_index_u16 +
  17008. BMI160_FIFO_Z_MSB_DATA]);
  17009. /* Mag r data*/
  17010. mag_data.mag_r_y2_lsb =
  17011. (v_fifo_data_u8[v_fifo_index_u16 +
  17012. BMI160_FIFO_R_LSB_DATA]);
  17013. mag_data.mag_r_y2_msb =
  17014. (v_fifo_data_u8[v_fifo_index_u16 +
  17015. BMI160_FIFO_R_MSB_DATA]);
  17016. com_rslt = bmi160_second_if_mag_compensate_xyz(mag_data,
  17017. v_mag_if_mag_u8);
  17018. /* compensated Mag x */
  17019. fifo_data->mag_fifo[v_mag_index_u8].x =
  17020. processed_data.x;
  17021. /* compensated Mag y */
  17022. fifo_data->mag_fifo[v_mag_index_u8].y =
  17023. processed_data.y;
  17024. /* compensated Mag z */
  17025. fifo_data->mag_fifo[v_mag_index_u8].z =
  17026. processed_data.z;
  17027. /* check for Mag frame count*/
  17028. fifo_data->mag_frame_count =
  17029. fifo_data->mag_frame_count + BMI160_FRAME_COUNT;
  17030. /* Accel raw x v_data_u8 */
  17031. fifo_data->accel_fifo[v_accel_index_u8].x =
  17032. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  17033. BMI160_MA_FIFO_A_X_MSB])
  17034. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  17035. |(v_fifo_data_u8[v_fifo_index_u16 +
  17036. BMI160_MA_FIFO_A_X_LSB]));
  17037. /* Accel raw y v_data_u8 */
  17038. fifo_data->accel_fifo[v_accel_index_u8].y =
  17039. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  17040. BMI160_MA_FIFO_A_Y_MSB])
  17041. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  17042. |(v_fifo_data_u8[v_fifo_index_u16 +
  17043. BMI160_MA_FIFO_A_Y_LSB]));
  17044. /* Accel raw z v_data_u8 */
  17045. fifo_data->accel_fifo[v_accel_index_u8].z =
  17046. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  17047. BMI160_MA_FIFO_A_Z_MSB])
  17048. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  17049. |(v_fifo_data_u8[v_fifo_index_u16 +
  17050. BMI160_MA_FIFO_A_Z_LSB]));
  17051. /* check for Accel frame count*/
  17052. fifo_data->accel_frame_count =
  17053. fifo_data->accel_frame_count + BMI160_FRAME_COUNT;
  17054. v_accel_index_u8++;
  17055. v_mag_index_u8++;
  17056. v_fifo_index_u16 = v_fifo_index_u16 +
  17057. BMI160_FIFO_MA_OR_MG_LENGTH;
  17058. }
  17059. /* condition for gyro and Accel enable*/
  17060. else if (v_data_u8 == BMI160_FIFO_G_A_ENABLE) {
  17061. /* Gyro raw x v_data_u8 */
  17062. fifo_data->gyro_fifo[v_gyro_index_u8].x =
  17063. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  17064. BMI160_GA_FIFO_G_X_MSB])
  17065. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  17066. |(v_fifo_data_u8[v_fifo_index_u16 +
  17067. BMI160_GA_FIFO_G_X_LSB]));
  17068. /* Gyro raw y v_data_u8 */
  17069. fifo_data->gyro_fifo[v_gyro_index_u8].y =
  17070. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  17071. BMI160_GA_FIFO_G_Y_MSB])
  17072. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  17073. |(v_fifo_data_u8[v_fifo_index_u16 +
  17074. BMI160_GA_FIFO_G_Y_LSB]));
  17075. /* Gyro raw z v_data_u8 */
  17076. fifo_data->gyro_fifo[v_gyro_index_u8].z =
  17077. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  17078. BMI160_GA_FIFO_G_Z_MSB])
  17079. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  17080. |(v_fifo_data_u8[v_fifo_index_u16 +
  17081. BMI160_GA_FIFO_G_Z_LSB]));
  17082. /* check for gyro frame count*/
  17083. fifo_data->gyro_frame_count =
  17084. fifo_data->gyro_frame_count + BMI160_FRAME_COUNT;
  17085. /* Accel raw x v_data_u8 */
  17086. fifo_data->accel_fifo[v_accel_index_u8].x =
  17087. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  17088. BMI160_GA_FIFO_A_X_MSB])
  17089. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  17090. |(v_fifo_data_u8[v_fifo_index_u16 +
  17091. BMI160_GA_FIFO_A_X_LSB]));
  17092. /* Accel raw y v_data_u8 */
  17093. fifo_data->accel_fifo[v_accel_index_u8].y =
  17094. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  17095. BMI160_GA_FIFO_A_Y_MSB])
  17096. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  17097. |(v_fifo_data_u8[v_fifo_index_u16 +
  17098. BMI160_GA_FIFO_A_Y_LSB]));
  17099. /* Accel raw z v_data_u8 */
  17100. fifo_data->accel_fifo[v_accel_index_u8].z =
  17101. (s16)(((v_fifo_data_u8[v_fifo_index_u16 +
  17102. BMI160_GA_FIFO_A_Z_MSB])
  17103. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  17104. |(v_fifo_data_u8[v_fifo_index_u16 +
  17105. BMI160_GA_FIFO_A_Z_LSB]));
  17106. /* check for Accel frame count*/
  17107. fifo_data->accel_frame_count =
  17108. fifo_data->accel_frame_count + BMI160_FRAME_COUNT;
  17109. v_accel_index_u8++;
  17110. v_gyro_index_u8++;
  17111. v_fifo_index_u16 = v_fifo_index_u16 +
  17112. BMI160_FIFO_AG_LENGTH;
  17113. }
  17114. /* condition for gyro enable*/
  17115. else if (v_data_u8 == BMI160_FIFO_GYRO_ENABLE) {
  17116. /* Gyro raw x v_data_u8 */
  17117. fifo_data->gyro_fifo[v_gyro_index_u8].x =
  17118. (s16)(((v_fifo_data_u8[v_fifo_index_u16
  17119. + BMI160_FIFO_X_MSB_DATA])
  17120. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  17121. |(v_fifo_data_u8[v_fifo_index_u16
  17122. + BMI160_FIFO_X_LSB_DATA]));
  17123. /* Gyro raw y v_data_u8 */
  17124. fifo_data->gyro_fifo[v_gyro_index_u8].y =
  17125. (s16)(((v_fifo_data_u8[v_fifo_index_u16
  17126. + BMI160_FIFO_Y_MSB_DATA])
  17127. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  17128. |(v_fifo_data_u8[v_fifo_index_u16
  17129. + BMI160_FIFO_Y_LSB_DATA]));
  17130. /* Gyro raw z v_data_u8 */
  17131. fifo_data->gyro_fifo[v_gyro_index_u8].z =
  17132. (s16)(((v_fifo_data_u8[v_fifo_index_u16
  17133. + BMI160_FIFO_Z_MSB_DATA])
  17134. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  17135. |(v_fifo_data_u8[v_fifo_index_u16
  17136. + BMI160_FIFO_Z_LSB_DATA]));
  17137. /* check for gyro frame count*/
  17138. fifo_data->gyro_frame_count =
  17139. fifo_data->gyro_frame_count + BMI160_FRAME_COUNT;
  17140. v_fifo_index_u16 = v_fifo_index_u16 + BMI160_FIFO_G_LENGTH;
  17141. v_gyro_index_u8++;
  17142. }
  17143. /* condition for Accel enable*/
  17144. else if (v_data_u8 == BMI160_FIFO_A_ENABLE) {
  17145. /* Accel raw x v_data_u8 */
  17146. fifo_data->accel_fifo[v_accel_index_u8].x =
  17147. (s16)(((v_fifo_data_u8[v_fifo_index_u16
  17148. + BMI160_FIFO_X_MSB_DATA])
  17149. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  17150. |(v_fifo_data_u8[v_fifo_index_u16 + BMI160_FIFO_X_LSB_DATA]));
  17151. /* Accel raw y v_data_u8 */
  17152. fifo_data->accel_fifo[v_accel_index_u8].y =
  17153. (s16)(((v_fifo_data_u8[v_fifo_index_u16
  17154. + BMI160_FIFO_Y_MSB_DATA])
  17155. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  17156. |(v_fifo_data_u8[v_fifo_index_u16 + BMI160_FIFO_Y_LSB_DATA]));
  17157. /* Accel raw z v_data_u8 */
  17158. fifo_data->accel_fifo[v_accel_index_u8].z =
  17159. (s16)(((v_fifo_data_u8[v_fifo_index_u16
  17160. + BMI160_FIFO_Z_MSB_DATA])
  17161. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  17162. |(v_fifo_data_u8[v_fifo_index_u16 + BMI160_FIFO_Z_LSB_DATA]));
  17163. /* check for Accel frame count*/
  17164. fifo_data->accel_frame_count =
  17165. fifo_data->accel_frame_count + BMI160_FRAME_COUNT;
  17166. v_fifo_index_u16 = v_fifo_index_u16 + BMI160_FIFO_A_LENGTH;
  17167. v_accel_index_u8++;
  17168. }
  17169. /* condition for Mag enable*/
  17170. else if (v_data_u8 == BMI160_FIFO_M_ENABLE) {
  17171. /* Raw Mag x*/
  17172. mag_data.mag_x_lsb =
  17173. (v_fifo_data_u8[v_fifo_index_u16 +
  17174. BMI160_FIFO_X_LSB_DATA]);
  17175. mag_data.mag_x_msb =
  17176. (v_fifo_data_u8[v_fifo_index_u16 +
  17177. BMI160_FIFO_X_MSB_DATA]);
  17178. /* Mag y data*/
  17179. mag_data.mag_y_lsb =
  17180. (v_fifo_data_u8[v_fifo_index_u16 +
  17181. BMI160_FIFO_Y_LSB_DATA]);
  17182. mag_data.mag_y_msb =
  17183. (v_fifo_data_u8[v_fifo_index_u16 +
  17184. BMI160_FIFO_Y_MSB_DATA]);
  17185. /* Mag z data*/
  17186. mag_data.mag_z_lsb =
  17187. (v_fifo_data_u8[v_fifo_index_u16 +
  17188. BMI160_FIFO_Z_LSB_DATA]);
  17189. mag_data.mag_z_msb =
  17190. (v_fifo_data_u8[v_fifo_index_u16 +
  17191. BMI160_FIFO_Z_MSB_DATA]);
  17192. /* Mag r data*/
  17193. mag_data.mag_r_y2_lsb =
  17194. (v_fifo_data_u8[v_fifo_index_u16 +
  17195. BMI160_FIFO_R_LSB_DATA]);
  17196. mag_data.mag_r_y2_msb =
  17197. (v_fifo_data_u8[v_fifo_index_u16 +
  17198. BMI160_FIFO_R_MSB_DATA]);
  17199. com_rslt = bmi160_second_if_mag_compensate_xyz(mag_data,
  17200. v_mag_if_mag_u8);
  17201. /* compensated Mag x */
  17202. fifo_data->mag_fifo[v_mag_index_u8].x =
  17203. processed_data.x;
  17204. /* compensated Mag y */
  17205. fifo_data->mag_fifo[v_mag_index_u8].y =
  17206. processed_data.y;
  17207. /* compensated Mag z */
  17208. fifo_data->mag_fifo[v_mag_index_u8].z =
  17209. processed_data.z;
  17210. /* check for Mag frame count*/
  17211. fifo_data->mag_frame_count =
  17212. fifo_data->mag_frame_count + BMI160_FRAME_COUNT;
  17213. v_fifo_index_u16 = v_fifo_index_u16
  17214. + BMI160_FIFO_M_LENGTH;
  17215. v_mag_index_u8++;
  17216. }
  17217. /* condition for FIFO over read enable*/
  17218. if (v_fifo_data_u8[v_fifo_index_u16] == FIFO_CONFIG_CHECK1 &&
  17219. v_fifo_data_u8[v_fifo_index_u16 + BMI160_FIFO_INDEX_LENGTH] ==
  17220. FIFO_CONFIG_CHECK2) {
  17221. break;
  17222. }
  17223. }
  17224. return com_rslt;
  17225. }
  17226. #endif
  17227. /*!
  17228. * @brief This function is used to read the compensated value of mag
  17229. * Before start reading the mag compensated data
  17230. * make sure the following two points are addressed
  17231. * @note
  17232. * 1. Make sure the Mag interface is enabled or not,
  17233. * by using the bmi160_get_if_mode() function.
  17234. * If Mag interface is not enabled set the value of 0x02
  17235. * to the function bmi160_get_if_mode(0x02)
  17236. * @note
  17237. * 2. And also confirm the secondary-interface power mode
  17238. * is not in the SUSPEND mode.
  17239. * by using the function bmi160_get_mag_pmu_status().
  17240. * If the secondary-interface power mode is in SUSPEND mode
  17241. * set the value of 0x19(NORMAL mode)by using the
  17242. * bmi160_set_command_register(0x19) function.
  17243. *
  17244. * @return results of bus communication function
  17245. * @retval 0 -> Success
  17246. * @retval -1 -> Error
  17247. *
  17248. *
  17249. */
  17250. BMI160_RETURN_FUNCTION_TYPE bmi160_bmm150_mag_compensate_xyz(
  17251. struct bmi160_mag_xyz_s32_t *mag_comp_xyz)
  17252. {
  17253. /* variable used to return the status of communication result*/
  17254. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  17255. struct bmi160_mag_xyzr_t mag_xyzr;
  17256. com_rslt = bmi160_read_mag_xyzr(&mag_xyzr);
  17257. if (com_rslt != 0)
  17258. return com_rslt;
  17259. /* Compensation for X axis */
  17260. mag_comp_xyz->x = bmi160_bmm150_mag_compensate_X(
  17261. mag_xyzr.x, mag_xyzr.r);
  17262. /* Compensation for Y axis */
  17263. mag_comp_xyz->y = bmi160_bmm150_mag_compensate_Y(
  17264. mag_xyzr.y, mag_xyzr.r);
  17265. /* Compensation for Z axis */
  17266. mag_comp_xyz->z = bmi160_bmm150_mag_compensate_Z(
  17267. mag_xyzr.z, mag_xyzr.r);
  17268. return com_rslt;
  17269. }
  17270. /*!
  17271. * @brief This API is used to get the compensated BMM150-X axis data
  17272. *
  17273. * Before start reading the Mag compensated X data
  17274. * make sure the following two points are addressed
  17275. * @note
  17276. * 1. Make sure the Mag interface is enabled or not,
  17277. * by using the bmi160_get_if_mode() function.
  17278. * If Mag interface is not enabled set the value of 0x02
  17279. * to the function bmi160_get_if_mode(0x02)
  17280. * @note
  17281. * 2. And also confirm the secondary-interface power mode
  17282. * is not in the SUSPEND mode.
  17283. * by using the function bmi160_get_mag_pmu_status().
  17284. * If the secondary-interface power mode is in SUSPEND mode
  17285. * set the value of 0x19(NORMAL mode)by using the
  17286. * bmi160_set_command_register(0x19) function.
  17287. *
  17288. *
  17289. *
  17290. * @param v_mag_data_x_s16 : The value of Mag raw X data
  17291. * @param v_data_r_u16 : The value of Mag R data
  17292. *
  17293. * @return compensated X axis data
  17294. *
  17295. */
  17296. s32 bmi160_bmm150_mag_compensate_X(s16 v_mag_data_x_s16, u16 v_data_r_u16)
  17297. {
  17298. s32 inter_retval = BMI160_INIT_VALUE;
  17299. /* no overflow */
  17300. if (v_mag_data_x_s16 != BMI160_MAG_FLIP_OVERFLOW_ADCVAL) {
  17301. if ((v_data_r_u16 != 0)
  17302. || (mag_trim.dig_xyz1 != 0)) {
  17303. inter_retval = ((s32)(((u16)
  17304. ((((s32)mag_trim.dig_xyz1)
  17305. << BMI160_SHIFT_BIT_POSITION_BY_14_BITS)/
  17306. (v_data_r_u16 != 0 ?
  17307. v_data_r_u16 : mag_trim.dig_xyz1))) -
  17308. ((u16)0x4000)));
  17309. } else {
  17310. inter_retval = BMI160_MAG_OVERFLOW_OUTPUT;
  17311. return inter_retval;
  17312. }
  17313. inter_retval = ((s32)((((s32)v_mag_data_x_s16) *
  17314. ((((((((s32)mag_trim.dig_xy2) *
  17315. ((((s32)inter_retval) *
  17316. ((s32)inter_retval))
  17317. >> BMI160_SHIFT_BIT_POSITION_BY_07_BITS)) +
  17318. (((s32)inter_retval) *
  17319. ((s32)(((s16)mag_trim.dig_xy1)
  17320. << BMI160_SHIFT_BIT_POSITION_BY_07_BITS))))
  17321. >> BMI160_SHIFT_BIT_POSITION_BY_09_BITS) +
  17322. ((s32)0x100000)) *
  17323. ((s32)(((s16)mag_trim.dig_x2) +
  17324. ((s16)0xA0))))
  17325. >> BMI160_SHIFT_BIT_POSITION_BY_12_BITS))
  17326. >> BMI160_SHIFT_BIT_POSITION_BY_13_BITS)) +
  17327. (((s16)mag_trim.dig_x1)
  17328. << BMI160_SHIFT_BIT_POSITION_BY_03_BITS);
  17329. /* check the overflow output */
  17330. if (inter_retval == (s32)BMI160_MAG_OVERFLOW_OUTPUT)
  17331. inter_retval = BMI160_MAG_OVERFLOW_OUTPUT_S32;
  17332. } else {
  17333. /* overflow */
  17334. inter_retval = BMI160_MAG_OVERFLOW_OUTPUT;
  17335. }
  17336. return inter_retval;
  17337. }
  17338. /*!
  17339. * @brief This API is used to get the compensated BMM150-Y axis data
  17340. *
  17341. * Before reading the Mag compensated Y axis data
  17342. * make sure the following two points are addressed
  17343. * @note
  17344. * 1. Make sure the Mag interface is enabled or not,
  17345. * by using the bmi160_get_if_mode() function.
  17346. * If Mag interface is not enabled then set the value of 0x02
  17347. * to the function bmi160_get_if_mode(0x02)
  17348. * @note
  17349. * 2. And also confirm the secondary-interface power mode
  17350. * is not in the SUSPEND mode.
  17351. * by using the function bmi160_get_mag_pmu_status().
  17352. * If the secondary-interface power mode is in SUSPEND mode
  17353. * set the value of 0x19(NORMAL mode)by using the
  17354. * bmi160_set_command_register(0x19) function.
  17355. *
  17356. *
  17357. *
  17358. * @param v_mag_data_y_s16 : The value of Mag raw Y axis data
  17359. * @param v_data_r_u16 : The value of Mag R data
  17360. *
  17361. * @return results of compensated Y axis data
  17362. */
  17363. s32 bmi160_bmm150_mag_compensate_Y(s16 v_mag_data_y_s16, u16 v_data_r_u16)
  17364. {
  17365. s32 inter_retval = BMI160_INIT_VALUE;
  17366. /* no overflow */
  17367. if (v_mag_data_y_s16 != BMI160_MAG_FLIP_OVERFLOW_ADCVAL) {
  17368. if ((v_data_r_u16 != 0)
  17369. || (mag_trim.dig_xyz1 != 0)) {
  17370. inter_retval = ((s32)(((u16)(((
  17371. (s32)mag_trim.dig_xyz1)
  17372. << BMI160_SHIFT_BIT_POSITION_BY_14_BITS) /
  17373. (v_data_r_u16 != 0 ?
  17374. v_data_r_u16 : mag_trim.dig_xyz1))) -
  17375. ((u16)0x4000)));
  17376. } else {
  17377. inter_retval = BMI160_MAG_OVERFLOW_OUTPUT;
  17378. return inter_retval;
  17379. }
  17380. inter_retval = ((s32)((((s32)v_mag_data_y_s16) * ((((((((s32)
  17381. mag_trim.dig_xy2) * ((((s32) inter_retval) *
  17382. ((s32)inter_retval)) >> BMI160_SHIFT_BIT_POSITION_BY_07_BITS))
  17383. + (((s32)inter_retval) *
  17384. ((s32)(((s16)mag_trim.dig_xy1)
  17385. << BMI160_SHIFT_BIT_POSITION_BY_07_BITS))))
  17386. >> BMI160_SHIFT_BIT_POSITION_BY_09_BITS) +
  17387. ((s32)0x100000))
  17388. * ((s32)(((s16)mag_trim.dig_y2)
  17389. + ((s16)0xA0))))
  17390. >> BMI160_SHIFT_BIT_POSITION_BY_12_BITS))
  17391. >> BMI160_SHIFT_BIT_POSITION_BY_13_BITS)) +
  17392. (((s16)mag_trim.dig_y1)
  17393. << BMI160_SHIFT_BIT_POSITION_BY_03_BITS);
  17394. /* check the overflow output */
  17395. if (inter_retval == (s32)BMI160_MAG_OVERFLOW_OUTPUT)
  17396. inter_retval = BMI160_MAG_OVERFLOW_OUTPUT_S32;
  17397. } else {
  17398. /* overflow */
  17399. inter_retval = BMI160_MAG_OVERFLOW_OUTPUT;
  17400. }
  17401. return inter_retval;
  17402. }
  17403. /*!
  17404. * @brief This API is used to get the compensated BMM150-Z axis data
  17405. *
  17406. * Before reading the Mag compensated Z data
  17407. * make sure the following two points are addressed
  17408. * @note
  17409. * 1. Make sure the Mag interface is enabled or not,
  17410. * by using the bmi160_get_if_mode() function.
  17411. * If Mag interface is not enabled then set the value of 0x02
  17412. * to the function bmi160_get_if_mode(0x02)
  17413. * @note
  17414. * 2. And also confirm the secondary-interface power mode
  17415. * is not in the SUSPEND mode.
  17416. * by using the function bmi160_get_mag_pmu_status().
  17417. * If the secondary-interface power mode is in SUSPEND mode
  17418. * set the value of 0x19(NORMAL mode)by using the
  17419. * bmi160_set_command_register(0x19) function.
  17420. *
  17421. *
  17422. *
  17423. * @param v_mag_data_z_s16 : The value of Mag raw Z data
  17424. * @param v_data_r_u16 : The value of Mag R data
  17425. *
  17426. * @return results of compensated Z axis data
  17427. */
  17428. s32 bmi160_bmm150_mag_compensate_Z(s16 v_mag_data_z_s16, u16 v_data_r_u16)
  17429. {
  17430. s32 retval = BMI160_INIT_VALUE;
  17431. if (v_mag_data_z_s16 != BMI160_MAG_HALL_OVERFLOW_ADCVAL) {
  17432. if ((v_data_r_u16 != 0)
  17433. && (mag_trim.dig_z2 != 0)
  17434. && (mag_trim.dig_z1 != 0)) {
  17435. retval = (((((s32)(v_mag_data_z_s16 - mag_trim.dig_z4))
  17436. << BMI160_SHIFT_BIT_POSITION_BY_15_BITS) -
  17437. ((((s32)mag_trim.dig_z3) *
  17438. ((s32)(((s16)v_data_r_u16) -
  17439. ((s16)mag_trim.dig_xyz1))))
  17440. >> BMI160_SHIFT_BIT_POSITION_BY_02_BITS))/
  17441. (mag_trim.dig_z2 +
  17442. ((s16)(((((s32)mag_trim.dig_z1) *
  17443. ((((s16)v_data_r_u16)
  17444. << BMI160_SHIFT_BIT_POSITION_BY_01_BIT))) +
  17445. (1 << BMI160_SHIFT_BIT_POSITION_BY_15_BITS))
  17446. >> BMI160_SHIFT_BIT_POSITION_BY_16_BITS))));
  17447. }
  17448. } else {
  17449. retval = BMI160_MAG_OVERFLOW_OUTPUT;
  17450. }
  17451. return retval;
  17452. }
  17453. /*!
  17454. * @brief This function is used to initialize the bmm150 sensor
  17455. *
  17456. *
  17457. * @return results of bus communication function
  17458. * @retval 0 -> Success
  17459. * @retval -1 -> Error
  17460. *
  17461. *
  17462. */
  17463. BMI160_RETURN_FUNCTION_TYPE bmi160_bmm150_mag_interface_init(u8 *v_chip_id_u8)
  17464. {
  17465. /* variable used to return the status of communication result*/
  17466. BMI160_RETURN_FUNCTION_TYPE com_rslt = BMI160_INIT_VALUE;
  17467. u8 v_data_u8 = BMI160_INIT_VALUE;
  17468. u8 v_accel_power_mode_status = BMI160_INIT_VALUE;
  17469. com_rslt = bmi160_get_accel_power_mode_stat(
  17470. &v_accel_power_mode_status);
  17471. /* Accel operation mode to normal*/
  17472. if (v_accel_power_mode_status != BMI160_ACCEL_NORMAL_MODE) {
  17473. com_rslt += bmi160_set_command_register(ACCEL_MODE_NORMAL);
  17474. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17475. }
  17476. /* write the Mag power mode as NORMAL*/
  17477. com_rslt += bmi160_set_mag_interface_normal();
  17478. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17479. /* Write the BMM150 i2c address*/
  17480. com_rslt += bmi160_set_i2c_device_addr(BMI160_AUX_BMM150_I2C_ADDRESS);
  17481. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17482. /* enable the Mag interface to manual mode*/
  17483. com_rslt += bmi160_set_mag_manual_enable(BMI160_MANUAL_ENABLE);
  17484. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17485. bmi160_get_mag_manual_enable(&v_data_u8);
  17486. /*Enable the MAG interface */
  17487. com_rslt += bmi160_set_if_mode(BMI160_ENABLE_MAG_IF_MODE);
  17488. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17489. bmi160_get_if_mode(&v_data_u8);
  17490. /* Mag normal mode*/
  17491. com_rslt += bmi160_bmm150_mag_wakeup();
  17492. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17493. /* Read the BMM150 device id is 0x32*/
  17494. com_rslt += bmi160_set_mag_read_addr(BMI160_BMM150_CHIP_ID);
  17495. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17496. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  17497. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  17498. *v_chip_id_u8 = v_data_u8;
  17499. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17500. /* write the power mode register*/
  17501. com_rslt += bmi160_set_mag_write_data(BMI160_BMM_POWER_MODE_REG);
  17502. /*write 0x4C register to write set power mode to normal*/
  17503. com_rslt += bmi160_set_mag_write_addr(
  17504. BMI160_BMM150_POWER_MODE_REG);
  17505. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17506. /* read the Mag trim values*/
  17507. com_rslt += bmi160_read_bmm150_mag_trim();
  17508. /* To avoid the auto mode enable when manual mode operation running*/
  17509. bmm150_manual_auto_condition_u8_g = BMI160_MANUAL_ENABLE;
  17510. /* write the XY and Z repetitions*/
  17511. com_rslt += bmi160_set_bmm150_mag_presetmode(
  17512. BMI160_MAG_PRESETMODE_REGULAR);
  17513. /* To avoid the auto mode enable when manual mode operation running*/
  17514. bmm150_manual_auto_condition_u8_g = BMI160_MANUAL_DISABLE;
  17515. /* Set the power mode of Mag as force mode*/
  17516. com_rslt += bmi160_set_mag_write_data(BMI160_BMM150_FORCE_MODE);
  17517. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17518. /* write into power mode register*/
  17519. com_rslt += bmi160_set_mag_write_addr(
  17520. BMI160_BMM150_POWER_MODE_REG);
  17521. /* write the Mag v_data_bw_u8 as 25Hz*/
  17522. com_rslt += bmi160_set_mag_output_data_rate(
  17523. BMI160_MAG_OUTPUT_DATA_RATE_25HZ);
  17524. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17525. /* When Mag interface is in auto mode - The Mag read address
  17526. starts at the register 0x42*/
  17527. com_rslt += bmi160_set_mag_read_addr(
  17528. BMI160_BMM150_DATA_REG);
  17529. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17530. /* enable Mag interface to auto mode*/
  17531. com_rslt += bmi160_set_mag_manual_enable(BMI160_MANUAL_DISABLE);
  17532. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17533. bmi160_get_mag_manual_enable(&v_data_u8);
  17534. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17535. switch (v_accel_power_mode_status) {
  17536. case BMI160_ACCEL_SUSPEND:
  17537. com_rslt += bmi160_set_command_register(ACCEL_SUSPEND);
  17538. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17539. break;
  17540. case BMI160_ACCEL_LOW_POWER:
  17541. com_rslt += bmi160_set_command_register(ACCEL_LOWPOWER);
  17542. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17543. break;
  17544. default:
  17545. break;
  17546. }
  17547. return com_rslt;
  17548. }
  17549. /*!
  17550. * @brief This function is used to set the Mag power control
  17551. * bit enable
  17552. *
  17553. *
  17554. * @return results of bus communication function
  17555. * @retval 0 -> Success
  17556. * @retval -1 -> Error
  17557. *
  17558. *
  17559. */
  17560. BMI160_RETURN_FUNCTION_TYPE bmi160_bmm150_mag_wakeup(void)
  17561. {
  17562. /* variable used to return the status of communication result*/
  17563. BMI160_RETURN_FUNCTION_TYPE com_rslt = BMI160_INIT_VALUE;
  17564. u8 v_try_times_u8 = BMI160_BMM150_MAX_RETRY_WAKEUP;
  17565. u8 v_power_control_bit_u8 = BMI160_INIT_VALUE;
  17566. u8 i = BMI160_INIT_VALUE;
  17567. for (i = BMI160_INIT_VALUE; i < v_try_times_u8; i++) {
  17568. com_rslt = bmi160_set_mag_write_data(BMI160_BMM150_POWER_ON);
  17569. p_bmi160->delay_msec(BMI160_BMM150_WAKEUP_DELAY1);
  17570. /*write 0x4B register to enable power control bit*/
  17571. com_rslt += bmi160_set_mag_write_addr(
  17572. BMI160_BMM150_POWER_CONTROL_REG);
  17573. p_bmi160->delay_msec(BMI160_BMM150_WAKEUP_DELAY2);
  17574. com_rslt += bmi160_set_mag_read_addr(
  17575. BMI160_BMM150_POWER_CONTROL_REG);
  17576. /* 0x04 is secondary read Mag x LSB register */
  17577. p_bmi160->delay_msec(BMI160_BMM150_WAKEUP_DELAY3);
  17578. com_rslt += bmi160_read_reg(BMI160_USER_DATA_0_ADDR,
  17579. &v_power_control_bit_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  17580. v_power_control_bit_u8 = BMI160_BMM150_SET_POWER_CONTROL
  17581. & v_power_control_bit_u8;
  17582. if (v_power_control_bit_u8 == BMI160_BMM150_POWER_ON)
  17583. break;
  17584. }
  17585. com_rslt = (i >= v_try_times_u8) ?
  17586. BMI160_BMM150_POWER_ON_FAIL : BMI160_BMM150_POWER_ON_SUCCESS;
  17587. return com_rslt;
  17588. }
  17589. /*!
  17590. * @brief This function is used to set the Mag
  17591. * power mode.
  17592. * @note Before setting the Mag power mode
  17593. * make sure the following points are addressed
  17594. * Make sure the Mag interface is enabled or not,
  17595. * by using the bmi160_get_if_mode() function.
  17596. * If Mag interface is not enabled set the value of 0x02
  17597. * to the function bmi160_get_if_mode(0x02)
  17598. *
  17599. * @param v_mag_sec_if_pow_mode_u8 : The value of Mag power mode
  17600. * value | mode
  17601. * ----------|------------
  17602. * 0 | BMI160_MAG_FORCE_MODE
  17603. * 1 | BMI160_MAG_SUSPEND_MODE
  17604. *
  17605. *
  17606. * @return results of bus communication function
  17607. * @retval 0 -> Success
  17608. * @retval -1 -> Error
  17609. *
  17610. *
  17611. */
  17612. BMI160_RETURN_FUNCTION_TYPE bmi160_set_bmm150_mag_and_secondary_if_power_mode(
  17613. u8 v_mag_sec_if_pow_mode_u8)
  17614. {
  17615. u8 v_accel_power_mode_status = BMI160_INIT_VALUE;
  17616. /* variable used to return the status of communication result*/
  17617. BMI160_RETURN_FUNCTION_TYPE com_rslt = BMI160_INIT_VALUE;
  17618. com_rslt = bmi160_get_accel_power_mode_stat(
  17619. &v_accel_power_mode_status);
  17620. /* set the Accel power mode to NORMAL*/
  17621. if (v_accel_power_mode_status != BMI160_ACCEL_NORMAL_MODE) {
  17622. com_rslt += bmi160_set_command_register(ACCEL_MODE_NORMAL);
  17623. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17624. }
  17625. switch (v_mag_sec_if_pow_mode_u8) {
  17626. case BMI160_MAG_FORCE_MODE:
  17627. /* set the secondary Mag power mode as NORMAL*/
  17628. com_rslt += bmi160_set_mag_interface_normal();
  17629. /* set the Mag power mode as FORCE mode*/
  17630. com_rslt += bmi160_bmm150_mag_set_power_mode(FORCE_MODE);
  17631. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17632. break;
  17633. case BMI160_MAG_SUSPEND_MODE:
  17634. /* set the Mag power mode as SUSPEND mode*/
  17635. com_rslt += bmi160_bmm150_mag_set_power_mode(SUSPEND_MODE);
  17636. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17637. /* set the secondary Mag power mode as SUSPEND*/
  17638. com_rslt += bmi160_set_command_register(MAG_MODE_SUSPEND);
  17639. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  17640. break;
  17641. default:
  17642. com_rslt = E_BMI160_OUT_OF_RANGE;
  17643. break;
  17644. }
  17645. if (p_bmi160->mag_manual_enable == BMI160_MANUAL_ENABLE) {
  17646. /* set Mag interface auto mode*/
  17647. com_rslt += bmi160_set_mag_manual_enable(
  17648. BMI160_MANUAL_DISABLE);
  17649. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17650. }
  17651. switch (v_accel_power_mode_status) {
  17652. case BMI160_ACCEL_SUSPEND:
  17653. com_rslt += bmi160_set_command_register(ACCEL_SUSPEND);
  17654. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17655. break;
  17656. case BMI160_ACCEL_LOW_POWER:
  17657. com_rslt += bmi160_set_command_register(ACCEL_LOWPOWER);
  17658. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17659. break;
  17660. default:
  17661. break;
  17662. }
  17663. return com_rslt;
  17664. }
  17665. /*!
  17666. * @brief This function is used to set the Mag
  17667. * power mode.
  17668. * @note
  17669. * Before setting the Mag power mode make sure the following
  17670. * two points are addressed
  17671. * @note
  17672. * 1. Make sure the Mag interface is enabled or not,
  17673. * by using the bmi160_get_if_mode() function.
  17674. * If Mag interface is not enabled then set the value of 0x02
  17675. * to the function bmi160_get_if_mode(0x02)
  17676. * @note
  17677. * 2. And also confirm the secondary-interface power mode
  17678. * is not in the SUSPEND mode by using the
  17679. * function bmi160_get_mag_pmu_status().
  17680. * If the secondary-interface power mode is in SUSPEND mode
  17681. * set the value of 0x19(NORMAL mode)by using the
  17682. * bmi160_set_command_register(0x19) function.
  17683. *
  17684. * @param v_mag_pow_mode_u8 : The value of Mag power mode
  17685. * value | mode
  17686. * ----------|------------
  17687. * 0 | FORCE_MODE
  17688. * 1 | SUSPEND_MODE
  17689. *
  17690. *
  17691. * @return results of bus communication function
  17692. * @retval 0 -> Success
  17693. * @retval -1 -> Error
  17694. *
  17695. *
  17696. */
  17697. BMI160_RETURN_FUNCTION_TYPE bmi160_bmm150_mag_set_power_mode(
  17698. u8 v_mag_pow_mode_u8)
  17699. {
  17700. /* variable used to return the status of communication result*/
  17701. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  17702. /* set Mag interface manual mode*/
  17703. if (p_bmi160->mag_manual_enable != BMI160_MANUAL_ENABLE) {
  17704. com_rslt = bmi160_set_mag_manual_enable(
  17705. BMI160_MANUAL_ENABLE);
  17706. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17707. if (com_rslt != SUCCESS)
  17708. return com_rslt;
  17709. } else {
  17710. com_rslt = SUCCESS;
  17711. }
  17712. switch (v_mag_pow_mode_u8) {
  17713. case FORCE_MODE:
  17714. /* Set the power control bit enabled */
  17715. com_rslt = bmi160_bmm150_mag_wakeup();
  17716. /* write the Mag power mode as FORCE mode*/
  17717. com_rslt += bmi160_set_mag_write_data(
  17718. BMI160_BMM150_FORCE_MODE);
  17719. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17720. com_rslt += bmi160_set_mag_write_addr(
  17721. BMI160_BMM150_POWER_MODE_REG);
  17722. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  17723. /* To avoid the auto mode enable when manual
  17724. mode operation running*/
  17725. bmm150_manual_auto_condition_u8_g = BMI160_MANUAL_ENABLE;
  17726. /* set the preset mode */
  17727. com_rslt += bmi160_set_bmm150_mag_presetmode(
  17728. BMI160_MAG_PRESETMODE_REGULAR);
  17729. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17730. /* To avoid the auto mode enable when manual
  17731. mode operation running*/
  17732. bmm150_manual_auto_condition_u8_g = BMI160_MANUAL_DISABLE;
  17733. /* set the Mag read address to data registers*/
  17734. com_rslt += bmi160_set_mag_read_addr(
  17735. BMI160_BMM150_DATA_REG);
  17736. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17737. break;
  17738. case SUSPEND_MODE:
  17739. /* Set the power mode of Mag as suspend mode*/
  17740. com_rslt = bmi160_set_mag_write_data(
  17741. BMI160_BMM150_POWER_OFF);
  17742. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17743. com_rslt += bmi160_set_mag_write_addr(
  17744. BMI160_BMM150_POWER_CONTROL_REG);
  17745. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  17746. break;
  17747. default:
  17748. com_rslt = E_BMI160_OUT_OF_RANGE;
  17749. break;
  17750. }
  17751. /* set Mag interface auto mode*/
  17752. if (p_bmi160->mag_manual_enable == BMI160_MANUAL_ENABLE) {
  17753. com_rslt += bmi160_set_mag_manual_enable(
  17754. BMI160_MANUAL_DISABLE);
  17755. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17756. }
  17757. return com_rslt;
  17758. }
  17759. /*!
  17760. * @brief This API is used to set the pre-set modes of bmm150
  17761. * The pre-set mode setting depends on the data rate and xy and z
  17762. * repetitions
  17763. *
  17764. * @note
  17765. * Before setting the Mag preset mode
  17766. * make sure the following two points are addressed
  17767. * @note
  17768. * 1. Make sure the Mag interface is enabled or not,
  17769. * by using the bmi160_get_if_mode() function.
  17770. * If Mag interface is not enabled set the value of 0x02
  17771. * to the function bmi160_get_if_mode(0x02)
  17772. * @note
  17773. * 2. And also confirm the secondary-interface power mode
  17774. * is not in the SUSPEND mode by using the function
  17775. * bmi160_get_mag_pmu_status().
  17776. * If the secondary-interface power mode is in SUSPEND mode
  17777. * set the value of 0x19(NORMAL mode)by using the
  17778. * bmi160_set_command_register(0x19) function.
  17779. *
  17780. *
  17781. * @param v_mode_u8: The value of pre-set mode selection value
  17782. * value | pre_set mode
  17783. * ----------|------------
  17784. * 1 | BMI160_MAG_PRESETMODE_LOWPOWER
  17785. * 2 | BMI160_MAG_PRESETMODE_REGULAR
  17786. * 3 | BMI160_MAG_PRESETMODE_HIGHACCURACY
  17787. * 4 | BMI160_MAG_PRESETMODE_ENHANCED
  17788. *
  17789. * @return results of bus communication function
  17790. * @retval 0 -> Success
  17791. * @retval -1 -> Error
  17792. *
  17793. */
  17794. BMI160_RETURN_FUNCTION_TYPE bmi160_set_bmm150_mag_presetmode(u8 v_mode_u8)
  17795. {
  17796. /* variable used to return the status of communication result*/
  17797. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  17798. /* set Mag interface manual mode*/
  17799. if (p_bmi160->mag_manual_enable != BMI160_MANUAL_ENABLE)
  17800. com_rslt = bmi160_set_mag_manual_enable(
  17801. BMI160_MANUAL_ENABLE);
  17802. switch (v_mode_u8) {
  17803. case BMI160_MAG_PRESETMODE_LOWPOWER:
  17804. /* write the XY and Z repetitions*/
  17805. com_rslt = bmi160_set_mag_write_data(
  17806. BMI160_MAG_LOWPOWER_REPXY);
  17807. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17808. com_rslt += bmi160_set_mag_write_addr(
  17809. BMI160_BMM150_XY_REP);
  17810. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17811. /* write the Z repetitions*/
  17812. com_rslt += bmi160_set_mag_write_data(
  17813. BMI160_MAG_LOWPOWER_REPZ);
  17814. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17815. com_rslt += bmi160_set_mag_write_addr(
  17816. BMI160_BMM150_Z_REP);
  17817. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17818. /* set the Mag v_data_u8 rate as 10 to the register 0x4C*/
  17819. com_rslt += bmi160_set_mag_write_data(
  17820. BMI160_MAG_LOWPOWER_DR);
  17821. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17822. com_rslt += bmi160_set_mag_write_addr(
  17823. BMI160_BMM150_POWER_MODE_REG);
  17824. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17825. break;
  17826. case BMI160_MAG_PRESETMODE_REGULAR:
  17827. /* write the XY and Z repetitions*/
  17828. com_rslt = bmi160_set_mag_write_data(
  17829. BMI160_MAG_REGULAR_REPXY);
  17830. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17831. com_rslt += bmi160_set_mag_write_addr(
  17832. BMI160_BMM150_XY_REP);
  17833. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17834. /* write the Z repetitions*/
  17835. com_rslt += bmi160_set_mag_write_data(
  17836. BMI160_MAG_REGULAR_REPZ);
  17837. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17838. com_rslt += bmi160_set_mag_write_addr(
  17839. BMI160_BMM150_Z_REP);
  17840. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17841. /* set the Mag v_data_u8 rate as 10 to the register 0x4C*/
  17842. com_rslt += bmi160_set_mag_write_data(
  17843. BMI160_MAG_REGULAR_DR);
  17844. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17845. com_rslt += bmi160_set_mag_write_addr(
  17846. BMI160_BMM150_POWER_MODE_REG);
  17847. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17848. break;
  17849. case BMI160_MAG_PRESETMODE_HIGHACCURACY:
  17850. /* write the XY and Z repetitions*/
  17851. com_rslt = bmi160_set_mag_write_data(
  17852. BMI160_MAG_HIGHACCURACY_REPXY);
  17853. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17854. com_rslt += bmi160_set_mag_write_addr(
  17855. BMI160_BMM150_XY_REP);
  17856. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17857. /* write the Z repetitions*/
  17858. com_rslt += bmi160_set_mag_write_data(
  17859. BMI160_MAG_HIGHACCURACY_REPZ);
  17860. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17861. com_rslt += bmi160_set_mag_write_addr(
  17862. BMI160_BMM150_Z_REP);
  17863. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17864. /* set the Mag v_data_u8 rate as 20 to the register 0x4C*/
  17865. com_rslt += bmi160_set_mag_write_data(
  17866. BMI160_MAG_HIGHACCURACY_DR);
  17867. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17868. com_rslt += bmi160_set_mag_write_addr(
  17869. BMI160_BMM150_POWER_MODE_REG);
  17870. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17871. break;
  17872. case BMI160_MAG_PRESETMODE_ENHANCED:
  17873. /* write the XY and Z repetitions*/
  17874. com_rslt = bmi160_set_mag_write_data(
  17875. BMI160_MAG_ENHANCED_REPXY);
  17876. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17877. com_rslt += bmi160_set_mag_write_addr(
  17878. BMI160_BMM150_XY_REP);
  17879. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17880. /* write the Z repetitions*/
  17881. com_rslt += bmi160_set_mag_write_data(
  17882. BMI160_MAG_ENHANCED_REPZ);
  17883. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17884. com_rslt += bmi160_set_mag_write_addr(
  17885. BMI160_BMM150_Z_REP);
  17886. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17887. /* set the Mag v_data_u8 rate as 10 to the register 0x4C*/
  17888. com_rslt += bmi160_set_mag_write_data(
  17889. BMI160_MAG_ENHANCED_DR);
  17890. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17891. com_rslt += bmi160_set_mag_write_addr(
  17892. BMI160_BMM150_POWER_MODE_REG);
  17893. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17894. break;
  17895. default:
  17896. com_rslt = E_BMI160_OUT_OF_RANGE;
  17897. break;
  17898. }
  17899. if (bmm150_manual_auto_condition_u8_g == BMI160_MANUAL_DISABLE) {
  17900. com_rslt += bmi160_set_mag_write_data(
  17901. BMI160_BMM150_FORCE_MODE);
  17902. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17903. com_rslt += bmi160_set_mag_write_addr(
  17904. BMI160_BMM150_POWER_MODE_REG);
  17905. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  17906. com_rslt += bmi160_set_mag_read_addr(BMI160_BMM150_DATA_REG);
  17907. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17908. /* set Mag interface auto mode*/
  17909. if (p_bmi160->mag_manual_enable == BMI160_MANUAL_ENABLE)
  17910. com_rslt = bmi160_set_mag_manual_enable(
  17911. BMI160_MANUAL_DISABLE);
  17912. }
  17913. return com_rslt;
  17914. }
  17915. /*!
  17916. * @brief This function is used to read the trim values of Mag
  17917. *
  17918. * @note Before reading the Mag trimming values
  17919. * make sure the following two points are addressed
  17920. * @note
  17921. * 1. Make sure the Mag interface is enabled or not,
  17922. * by using the bmi160_get_if_mode() function.
  17923. * If Mag interface is not enabled set the value of 0x02
  17924. * to the function bmi160_get_if_mode(0x02)
  17925. * @note
  17926. * 2. And also confirm the secondary-interface power mode
  17927. * is not in the SUSPEND mode.
  17928. * by using the function bmi160_get_mag_pmu_status().
  17929. * If the secondary-interface power mode is in SUSPEND mode
  17930. * set the value of 0x19(NORMAL mode)by using the
  17931. * bmi160_set_command_register(0x19) function.
  17932. *
  17933. * @return results of bus communication function
  17934. * @retval 0 -> Success
  17935. * @retval -1 -> Error
  17936. *
  17937. *
  17938. */
  17939. BMI160_RETURN_FUNCTION_TYPE bmi160_read_bmm150_mag_trim(void)
  17940. {
  17941. /* variable used to return the status of communication result*/
  17942. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  17943. /* Array holding the bmm150 trim data
  17944. */
  17945. u8 v_data_u8[BMI160_MAG_TRIM_DATA_SIZE] = {
  17946. BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  17947. BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  17948. BMI160_INIT_VALUE,
  17949. BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  17950. BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  17951. BMI160_INIT_VALUE,
  17952. BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  17953. BMI160_INIT_VALUE,
  17954. BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  17955. BMI160_INIT_VALUE};
  17956. /* read dig_x1 value */
  17957. com_rslt = bmi160_set_mag_read_addr(
  17958. BMI160_MAG_DIG_X1);
  17959. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17960. /* 0x04 is secondary read Mag x LSB register */
  17961. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  17962. &v_data_u8[BMI160_BMM150_DIG_X1],
  17963. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  17964. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17965. mag_trim.dig_x1 = v_data_u8[BMI160_BMM150_DIG_X1];
  17966. /* read dig_y1 value */
  17967. com_rslt += bmi160_set_mag_read_addr(
  17968. BMI160_MAG_DIG_Y1);
  17969. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17970. /* 0x04 is secondary read Mag x LSB register */
  17971. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  17972. &v_data_u8[BMI160_BMM150_DIG_Y1],
  17973. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  17974. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17975. mag_trim.dig_y1 = v_data_u8[BMI160_BMM150_DIG_Y1];
  17976. /* read dig_x2 value */
  17977. com_rslt += bmi160_set_mag_read_addr(
  17978. BMI160_MAG_DIG_X2);
  17979. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17980. /* 0x04 is secondary read Mag x LSB register */
  17981. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  17982. &v_data_u8[BMI160_BMM150_DIG_X2],
  17983. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  17984. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17985. mag_trim.dig_x2 = v_data_u8[BMI160_BMM150_DIG_X2];
  17986. /* read dig_y2 value */
  17987. com_rslt += bmi160_set_mag_read_addr(
  17988. BMI160_MAG_DIG_Y2);
  17989. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17990. /* 0x04 is secondary read Mag x LSB register */
  17991. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  17992. &v_data_u8[BMI160_BMM150_DIG_Y3],
  17993. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  17994. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  17995. mag_trim.dig_y2 = v_data_u8[BMI160_BMM150_DIG_Y3];
  17996. /* read dig_xy1 value */
  17997. com_rslt += bmi160_set_mag_read_addr(
  17998. BMI160_MAG_DIG_XY1);
  17999. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18000. /* 0x04 is secondary read Mag x LSB register */
  18001. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  18002. &v_data_u8[BMI160_BMM150_DIG_XY1],
  18003. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  18004. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18005. mag_trim.dig_xy1 = v_data_u8[BMI160_BMM150_DIG_XY1];
  18006. /* read dig_xy2 value */
  18007. com_rslt += bmi160_set_mag_read_addr(
  18008. BMI160_MAG_DIG_XY2);
  18009. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18010. /* 0x04 is v_mag_x_s16 ls register */
  18011. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  18012. &v_data_u8[BMI160_BMM150_DIG_XY2],
  18013. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  18014. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18015. mag_trim.dig_xy2 = v_data_u8[BMI160_BMM150_DIG_XY2];
  18016. /* read dig_z1 LSB value */
  18017. com_rslt += bmi160_set_mag_read_addr(
  18018. BMI160_MAG_DIG_Z1_LSB);
  18019. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18020. /* 0x04 is secondary read Mag x LSB register */
  18021. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  18022. &v_data_u8[BMI160_BMM150_DIG_Z1_LSB],
  18023. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  18024. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18025. /* read dig_z1 MSB value */
  18026. com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_Z1_MSB);
  18027. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18028. /* 0x04 is v_mag_x_s16 MSB register */
  18029. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  18030. &v_data_u8[BMI160_BMM150_DIG_Z1_MSB],
  18031. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  18032. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18033. mag_trim.dig_z1 =
  18034. (u16)((((u32)((u8)v_data_u8[BMI160_BMM150_DIG_Z1_MSB]))
  18035. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) |
  18036. (v_data_u8[BMI160_BMM150_DIG_Z1_LSB]));
  18037. /* read dig_z2 LSB value */
  18038. com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_Z2_LSB);
  18039. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18040. /* 0x04 is secondary read Mag x LSB register */
  18041. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  18042. &v_data_u8[BMI160_BMM150_DIG_Z2_LSB],
  18043. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  18044. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18045. /* read dig_z2 MSB value */
  18046. com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_Z2_MSB);
  18047. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18048. /* 0x04 is v_mag_x_s16 MSB register */
  18049. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  18050. &v_data_u8[BMI160_BMM150_DIG_Z2_MSB],
  18051. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  18052. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18053. mag_trim.dig_z2 =
  18054. (s16)((((s32)((s8)v_data_u8[BMI160_BMM150_DIG_Z2_MSB]))
  18055. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) |
  18056. (v_data_u8[BMI160_BMM150_DIG_Z2_LSB]));
  18057. /* read dig_z3 LSB value */
  18058. com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_Z3_LSB);
  18059. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18060. /* 0x04 is secondary read Mag x LSB register */
  18061. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  18062. &v_data_u8[BMI160_BMM150_DIG_DIG_Z3_LSB],
  18063. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  18064. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18065. /* read dig_z3 MSB value */
  18066. com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_Z3_MSB);
  18067. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18068. /* 0x04 is v_mag_x_s16 MSB register */
  18069. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  18070. &v_data_u8[BMI160_BMM150_DIG_DIG_Z3_MSB],
  18071. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  18072. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18073. mag_trim.dig_z3 =
  18074. (s16)((((s32)((s8)v_data_u8[BMI160_BMM150_DIG_DIG_Z3_MSB]))
  18075. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) |
  18076. (v_data_u8[BMI160_BMM150_DIG_DIG_Z3_LSB]));
  18077. /* read dig_z4 LSB value */
  18078. com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_Z4_LSB);
  18079. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18080. /* 0x04 is secondary read Mag x LSB register */
  18081. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  18082. &v_data_u8[BMI160_BMM150_DIG_DIG_Z4_LSB],
  18083. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  18084. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18085. /* read dig_z4 MSB value */
  18086. com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_Z4_MSB);
  18087. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18088. /* 0x04 is v_mag_x_s16 MSB register */
  18089. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  18090. &v_data_u8[BMI160_BMM150_DIG_DIG_Z4_MSB],
  18091. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  18092. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18093. mag_trim.dig_z4 =
  18094. (s16)((((s32)((s8)v_data_u8[BMI160_BMM150_DIG_DIG_Z4_MSB]))
  18095. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) |
  18096. (v_data_u8[BMI160_BMM150_DIG_DIG_Z4_LSB]));
  18097. /* read dig_xyz1 LSB value */
  18098. com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_XYZ1_LSB);
  18099. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18100. /* 0x04 is secondary read Mag x LSB register */
  18101. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  18102. &v_data_u8[BMI160_BMM150_DIG_DIG_XYZ1_LSB],
  18103. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  18104. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18105. /* read dig_xyz1 MSB value */
  18106. com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_XYZ1_MSB);
  18107. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18108. /* 0x04 is v_mag_x_s16 MSB register */
  18109. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  18110. &v_data_u8[BMI160_BMM150_DIG_DIG_XYZ1_MSB],
  18111. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  18112. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18113. mag_trim.dig_xyz1 =
  18114. (u16)((((u32)((u8)v_data_u8[BMI160_BMM150_DIG_DIG_XYZ1_MSB]))
  18115. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) |
  18116. (v_data_u8[BMI160_BMM150_DIG_DIG_XYZ1_LSB]));
  18117. return com_rslt;
  18118. }
  18119. #ifdef AKM09912
  18120. /***************************************************/
  18121. /**\name FUNCTIONS FOR AKM09912*/
  18122. /***************************************************/
  18123. /*!
  18124. * @brief This API is used to get the compensated X data
  18125. * of AKM09912 sensor
  18126. * Output of X is s32
  18127. * @note Before start reading the Mag compensated X data
  18128. * make sure the following two points are addressed
  18129. * @note 1. Make sure the Mag interface is enabled or not,
  18130. * by using the bmi160_get_if_mode() function.
  18131. * If Mag interface is not enabled set the value of 0x02
  18132. * to the function bmi160_get_if_mode(0x02)
  18133. * @note 2. And also confirm the secondary-interface power mode
  18134. * is not in the SUSPEND mode.
  18135. * by using the function bmi160_get_mag_pmu_status().
  18136. * If the secondary-interface power mode is in SUSPEND mode
  18137. * set the value of 0x19(NORMAL mode)by using the
  18138. * bmi160_set_command_register(0x19) function.
  18139. *
  18140. *
  18141. * @param v_bst_akm_x_s16 : The value of X data
  18142. *
  18143. * @return compensated X data value
  18144. *
  18145. */
  18146. s32 bmi160_bst_akm09912_compensate_X(s16 v_bst_akm_x_s16)
  18147. {
  18148. /*Return value of AKM x compensated data*/
  18149. s32 retval = BMI160_INIT_VALUE;
  18150. /* Convert raw data into compensated data*/
  18151. retval = v_bst_akm_x_s16 *
  18152. (akm_asa_data.asax + AKM09912_SENSITIVITY)
  18153. / AKM09912_SENSITIVITY_DIV;
  18154. return retval;
  18155. }
  18156. /*!
  18157. * @brief This API is used to get the compensated Y data
  18158. * of AKM09912 sensor
  18159. * @note Before reading the Mag compensated Y data
  18160. * make sure the following two points are addressed
  18161. * @note 1. Make sure the Mag interface is enabled or not,
  18162. * by using the bmi160_get_if_mode() function.
  18163. * If Mag interface is not enabled set the value of 0x02
  18164. * to the function bmi160_get_if_mode(0x02)
  18165. * @note 2. And also confirm the secondary-interface power mode
  18166. * is not in the SUSPEND mode by using the function
  18167. * bmi160_get_mag_pmu_status().
  18168. * If the secondary-interface power mode is in SUSPEND mode
  18169. * set the value of 0x19(NORMAL mode)by using the
  18170. * bmi160_set_command_register(0x19) function.
  18171. *
  18172. *
  18173. * @param v_bst_akm_y_s16 : The value of Y data
  18174. *
  18175. * @return compensated Y data value
  18176. *
  18177. */
  18178. s32 bmi160_bst_akm09912_compensate_Y(s16 v_bst_akm_y_s16)
  18179. {
  18180. /*Return value of AKM y compensated data*/
  18181. s32 retval = BMI160_INIT_VALUE;
  18182. /* Convert raw data into compensated data*/
  18183. retval = v_bst_akm_y_s16 *
  18184. (akm_asa_data.asax + AKM09912_SENSITIVITY)
  18185. / AKM09912_SENSITIVITY_DIV;
  18186. return retval;
  18187. }
  18188. /*!
  18189. * @brief This API is used to get the compensated Z data
  18190. * of AKM09912
  18191. * Output of X is s32
  18192. * @note Before start reading the Mag compensated Z data
  18193. * make sure the following two points are addressed
  18194. * @note 1. Make sure the Mag interface is enabled or not,
  18195. * by using the bmi160_get_if_mode() function.
  18196. * If Mag interface is not enabled set the value of 0x02
  18197. * to the function bmi160_get_if_mode(0x02)
  18198. * @note 2. And also confirm the secondary-interface power mode
  18199. * is not in the SUSPEND mode.
  18200. * by using the function bmi160_get_mag_pmu_status().
  18201. * If the secondary-interface power mode is in SUSPEND mode
  18202. * set the value of 0x19(NORMAL mode)by using the
  18203. * bmi160_set_command_register(0x19) function.
  18204. *
  18205. *
  18206. * @param v_bst_akm_z_s16 : The value of Z data
  18207. *
  18208. * @return compensated Z data value
  18209. *
  18210. */
  18211. s32 bmi160_bst_akm09912_compensate_Z(s16 v_bst_akm_z_s16)
  18212. {
  18213. /*Return value of AKM z compensated data*/
  18214. s32 retval = BMI160_INIT_VALUE;
  18215. /* Convert raw data into compensated data*/
  18216. retval = v_bst_akm_z_s16 *
  18217. (akm_asa_data.asax + AKM09912_SENSITIVITY)
  18218. / AKM09912_SENSITIVITY_DIV;
  18219. return retval;
  18220. }
  18221. /*!
  18222. * @brief This function is used to read the compensated value of
  18223. * AKM09912 sensor
  18224. * @note Before start reading the Mag compensated data's
  18225. * make sure the following two points are addressed
  18226. * @note 1. Make sure the Mag interface is enabled or not,
  18227. * by using the bmi160_get_if_mode() function.
  18228. * If Mag interface is not enabled set the value of 0x02
  18229. * to the function bmi160_get_if_mode(0x02)
  18230. * @note 2. And also confirm the secondary-interface power mode
  18231. * is not in the SUSPEND mode by using the function
  18232. * bmi160_get_mag_pmu_status().
  18233. * If the secondary-interface power mode is in SUSPEND mode
  18234. * set the value of 0x19(NORMAL mode)by using the
  18235. * bmi160_set_command_register(0x19) function.
  18236. *
  18237. *
  18238. * @return results of bus communication function
  18239. * @retval 0 -> Success
  18240. * @retval -1 -> Error
  18241. *
  18242. *
  18243. */
  18244. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_akm09912_compensate_xyz(
  18245. struct bmi160_bst_akm_xyz_t *bst_akm_xyz)
  18246. {
  18247. /* variable used to return the status of communication result*/
  18248. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  18249. struct bmi160_mag_t mag_xyz;
  18250. com_rslt = bmi160_read_mag_xyz(&mag_xyz, BST_AKM);
  18251. /* Compensation for X axis */
  18252. bst_akm_xyz->x = bmi160_bst_akm09912_compensate_X(mag_xyz.x);
  18253. /* Compensation for Y axis */
  18254. bst_akm_xyz->y = bmi160_bst_akm09912_compensate_Y(mag_xyz.y);
  18255. /* Compensation for Z axis */
  18256. bst_akm_xyz->z = bmi160_bst_akm09912_compensate_Z(mag_xyz.z);
  18257. return com_rslt;
  18258. }
  18259. #endif
  18260. #ifdef AKM09911
  18261. /***************************************************/
  18262. /**\name FUNCTIONS FOR AKM09911 */
  18263. /***************************************************/
  18264. /*!
  18265. * @brief This API is used to get the compensated X data
  18266. * of AKM09911 sensor
  18267. * Output of X is s32
  18268. * @note Before start reading the Mag compensated X data
  18269. * make sure the following two points are addressed
  18270. * @note 1. Make sure the Mag interface is enabled or not,
  18271. * by using the bmi160_get_if_mode() function.
  18272. * If Mag interface is not enabled set the value of 0x02
  18273. * to the function bmi160_get_if_mode(0x02)
  18274. * @note 2. And also confirm the secondary-interface power mode
  18275. * is not in the SUSPEND mode.
  18276. * by using the function bmi160_get_mag_pmu_status().
  18277. * If the secondary-interface power mode is in SUSPEND mode
  18278. * set the value of 0x19(NORMAL mode)by using the
  18279. * bmi160_set_command_register(0x19) function.
  18280. *
  18281. *
  18282. * @param v_bst_akm_x_s16 : The value of X data
  18283. *
  18284. * @return compensated X data value
  18285. *
  18286. */
  18287. s32 bmi160_bst_akm09911_compensate_X(s16 v_bst_akm_x_s16)
  18288. {
  18289. /*Return value of AKM x compensated v_data_u8*/
  18290. s32 retval = BMI160_INIT_VALUE;
  18291. /* Convert raw v_data_u8 into compensated v_data_u8*/
  18292. retval = (v_bst_akm_x_s16 *
  18293. ((akm_asa_data.asax/AKM09911_SENSITIVITY_DIV) +
  18294. BMI160_GEN_READ_WRITE_DATA_LENGTH));
  18295. return retval;
  18296. }
  18297. /*!
  18298. * @brief This API is used to get the compensated Y data
  18299. * of AKM09911 sensor
  18300. * Output of Y is s32
  18301. * @note Before start reading the Mag compensated Y data
  18302. * make sure the following two points are addressed
  18303. * @note 1. Make sure the Mag interface is enabled or not,
  18304. * by using the bmi160_get_if_mode() function.
  18305. * If Mag interface is not enabled set the value of 0x02
  18306. * to the function bmi160_get_if_mode(0x02)
  18307. * @note 2. And also confirm the secondary-interface power mode
  18308. * is not in the SUSPEND mode.
  18309. * by using the function bmi160_get_mag_pmu_status().
  18310. * If the secondary-interface power mode is in SUSPEND mode
  18311. * set the value of 0x19(NORMAL mode)by using the
  18312. * bmi160_set_command_register(0x19) function.
  18313. *
  18314. *
  18315. * @param v_bst_akm_y_s16 : The value of Y data
  18316. *
  18317. * @return compensated Y data value
  18318. *
  18319. */
  18320. s32 bmi160_bst_akm09911_compensate_Y(s16 v_bst_akm_y_s16)
  18321. {
  18322. /*Return value of AKM y compensated v_data_u8*/
  18323. s32 retval = BMI160_INIT_VALUE;
  18324. /* Convert raw v_data_u8 into compensated v_data_u8*/
  18325. retval = (v_bst_akm_y_s16 *
  18326. ((akm_asa_data.asay/AKM09911_SENSITIVITY_DIV) +
  18327. BMI160_GEN_READ_WRITE_DATA_LENGTH));
  18328. return retval;
  18329. }
  18330. /*!
  18331. * @brief This API is used to get the compensated Z data
  18332. * of AKM09911 sensor
  18333. * Out put of Z is s32
  18334. * @note Before start reading the Mag compensated Z data
  18335. * make sure the following two points are addressed
  18336. * @note 1. Make sure the Mag interface is enabled or not,
  18337. * by using the bmi160_get_if_mode() function.
  18338. * If Mag interface is not enabled set the value of 0x02
  18339. * to the function bmi160_get_if_mode(0x02)
  18340. * @note 2. And also confirm the secondary-interface power mode
  18341. * is not in the SUSPEND mode.
  18342. * by using the function bmi160_get_mag_pmu_status().
  18343. * If the secondary-interface power mode is in SUSPEND mode
  18344. * set the value of 0x19(NORMAL mode)by using the
  18345. * bmi160_set_command_register(0x19) function.
  18346. *
  18347. *
  18348. * @param v_bst_akm_z_s16 : The value of Z data
  18349. *
  18350. * @return compensated Z data value
  18351. *
  18352. */
  18353. s32 bmi160_bst_akm09911_compensate_Z(s16 v_bst_akm_z_s16)
  18354. {
  18355. /*Return value of AKM z compensated v_data_u8*/
  18356. s32 retval = BMI160_INIT_VALUE;
  18357. /* Convert raw v_data_u8 into compensated v_data_u8*/
  18358. retval = (v_bst_akm_z_s16 *
  18359. ((akm_asa_data.asaz/AKM09911_SENSITIVITY_DIV) +
  18360. BMI160_GEN_READ_WRITE_DATA_LENGTH));
  18361. return retval;
  18362. }
  18363. /*!
  18364. * @brief This function is used to read the compensated value of
  18365. * AKM09911
  18366. * @note Before start reading the Mag compensated data's
  18367. * make sure the following two points are addressed
  18368. * @note 1. Make sure the Mag interface is enabled or not,
  18369. * by using the bmi160_get_if_mode() function.
  18370. * If Mag interface is not enabled set the value of 0x02
  18371. * to the function bmi160_get_if_mode(0x02)
  18372. * @note 2. And also confirm the secondary-interface power mode
  18373. * is not in the SUSPEND mode by using the function
  18374. * bmi160_get_mag_pmu_status().
  18375. * If the secondary-interface power mode is in SUSPEND mode
  18376. * set the value of 0x19(NORMAL mode)by using the
  18377. * bmi160_set_command_register(0x19) function.
  18378. *
  18379. *
  18380. * @return results of bus communication function
  18381. * @retval 0 -> Success
  18382. * @retval -1 -> Error
  18383. *
  18384. *
  18385. */
  18386. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_akm09911_compensate_xyz(
  18387. struct bmi160_bst_akm_xyz_t *bst_akm_xyz)
  18388. {
  18389. /* variable used to return the status of communication result*/
  18390. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  18391. struct bmi160_mag_t mag_xyz;
  18392. com_rslt = bmi160_read_mag_xyz(&mag_xyz, BST_AKM);
  18393. /* Compensation for X axis */
  18394. bst_akm_xyz->x = bmi160_bst_akm09911_compensate_X(mag_xyz.x);
  18395. /* Compensation for Y axis */
  18396. bst_akm_xyz->y = bmi160_bst_akm09911_compensate_Y(mag_xyz.y);
  18397. /* Compensation for Z axis */
  18398. bst_akm_xyz->z = bmi160_bst_akm09911_compensate_Z(mag_xyz.z);
  18399. return com_rslt;
  18400. }
  18401. #endif
  18402. #if defined AKM09911 || defined AKM09912
  18403. /***************************************************/
  18404. /**\name FUNCTIONS FOR AKM09911 and AKM09912 */
  18405. /***************************************************/
  18406. /*!
  18407. * @brief This function is used to initialize
  18408. * the AKM09911 and AKM09912 sensor
  18409. *
  18410. *
  18411. * @param v_akm_i2c_address_u8: The value of device address
  18412. * AKM sensor | Slave address
  18413. * --------------|---------------------
  18414. * AKM09911 | AKM09911_I2C_ADDR_1
  18415. * - | and AKM09911_I2C_ADDR_2
  18416. * AKM09912 | AKM09912_I2C_ADDR_1
  18417. * - | AKM09912_I2C_ADDR_2
  18418. * - | AKM09912_I2C_ADDR_3
  18419. * - | AKM09912_I2C_ADDR_4
  18420. *
  18421. * @return results of bus communication function
  18422. * @retval 0 -> Success
  18423. * @retval -1 -> Error
  18424. *
  18425. *
  18426. */
  18427. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_akm_mag_interface_init(
  18428. u8 v_akm_i2c_address_u8)
  18429. {
  18430. /* variable used to return the status of communication result*/
  18431. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  18432. u8 v_data_u8 = BMI160_INIT_VALUE;
  18433. u8 v_akm_chip_id_u8 = BMI160_INIT_VALUE;
  18434. u8 v_accel_power_mode_status = BMI160_INIT_VALUE;
  18435. com_rslt = bmi160_get_accel_power_mode_stat(
  18436. &v_accel_power_mode_status);
  18437. /* set Accel operation mode to normal*/
  18438. if (v_accel_power_mode_status != BMI160_ACCEL_NORMAL_MODE) {
  18439. com_rslt += bmi160_set_command_register(ACCEL_MODE_NORMAL);
  18440. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18441. }
  18442. com_rslt += bmi160_set_command_register(MAG_MODE_NORMAL);
  18443. p_bmi160->delay_msec(BMI160_AKM_INIT_DELAY);
  18444. bmi160_get_mag_power_mode_stat(&v_data_u8);
  18445. /* Write the AKM09911 0r AKM09912 i2c address*/
  18446. com_rslt += bmi160_set_i2c_device_addr(v_akm_i2c_address_u8);
  18447. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18448. /* enable the Mag interface to manual mode*/
  18449. com_rslt += bmi160_set_mag_manual_enable(BMI160_MANUAL_ENABLE);
  18450. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18451. bmi160_get_mag_manual_enable(&v_data_u8);
  18452. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18453. /*Enable the MAG interface */
  18454. com_rslt += bmi160_set_if_mode(BMI160_ENABLE_MAG_IF_MODE);
  18455. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18456. bmi160_get_if_mode(&v_data_u8);
  18457. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18458. /* Set the AKM Fuse ROM mode */
  18459. com_rslt += bmi160_set_mag_write_data(AKM_FUSE_ROM_MODE);
  18460. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18461. /* AKM mode address is 0x31*/
  18462. com_rslt += bmi160_set_mag_write_addr(AKM_POWER_MODE_REG);
  18463. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  18464. /* Read the Fuse ROM v_data_u8 from registers
  18465. 0x60,0x61 and 0x62*/
  18466. /* ASAX v_data_u8 */
  18467. com_rslt += bmi160_read_bst_akm_sensitivity_data();
  18468. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  18469. /* read the device id of the AKM sensor
  18470. if device id is 0x05 - AKM09911
  18471. if device id is 0x04 - AKM09912*/
  18472. com_rslt += bmi160_set_mag_read_addr(AKM_CHIP_ID_REG);
  18473. /* 0x04 is mag_x LSB register */
  18474. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  18475. &v_akm_chip_id_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  18476. /* Set power down mode*/
  18477. com_rslt += bmi160_set_mag_write_data(AKM_POWER_DOWN_MODE_DATA);
  18478. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18479. /* AKM mode address is 0x31*/
  18480. com_rslt += bmi160_set_mag_write_addr(AKM_POWER_MODE_REG);
  18481. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  18482. /* Set AKM Force mode*/
  18483. com_rslt += bmi160_set_mag_write_data(
  18484. AKM_SINGLE_MEASUREMENT_MODE);
  18485. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18486. /* AKM mode address is 0x31*/
  18487. com_rslt += bmi160_set_mag_write_addr(AKM_POWER_MODE_REG);
  18488. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  18489. /* Set the AKM read xyz v_data_u8 address*/
  18490. com_rslt += bmi160_set_mag_read_addr(AKM_DATA_REGISTER);
  18491. /* write the Mag v_data_bw_u8 as 25Hz*/
  18492. com_rslt += bmi160_set_mag_output_data_rate(
  18493. BMI160_MAG_OUTPUT_DATA_RATE_25HZ);
  18494. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18495. /* Enable Mag interface to auto mode*/
  18496. com_rslt += bmi160_set_mag_manual_enable(BMI160_MANUAL_DISABLE);
  18497. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18498. bmi160_get_mag_manual_enable(&v_data_u8);
  18499. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18500. switch (v_accel_power_mode_status) {
  18501. case BMI160_ACCEL_SUSPEND:
  18502. com_rslt += bmi160_set_command_register(ACCEL_SUSPEND);
  18503. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18504. break;
  18505. case BMI160_ACCEL_LOW_POWER:
  18506. com_rslt += bmi160_set_command_register(ACCEL_LOWPOWER);
  18507. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18508. break;
  18509. default:
  18510. break;
  18511. }
  18512. return com_rslt;
  18513. }
  18514. /*!
  18515. * @brief This function is used to read the sensitivity data of
  18516. * AKM09911 and AKM09912
  18517. *
  18518. * @note Before reading the Mag sensitivity values
  18519. * make sure the following two points are addressed
  18520. * @note 1. Make sure the Mag interface is enabled or not,
  18521. * by using the bmi160_get_if_mode() function.
  18522. * If Mag interface is not enabled set the value of 0x02
  18523. * to the function bmi160_get_if_mode(0x02)
  18524. * @note 2. And also confirm the secondary-interface power mode
  18525. * is not in the SUSPEND mode by using the function
  18526. * bmi160_get_mag_pmu_status().
  18527. * If the secondary-interface power mode is in SUSPEND mode
  18528. * set the value of 0x19(NORMAL mode)by using the
  18529. * bmi160_set_command_register(0x19) function.
  18530. *
  18531. * @return results of bus communication function
  18532. * @retval 0 -> Success
  18533. * @retval -1 -> Error
  18534. *
  18535. *
  18536. */
  18537. BMI160_RETURN_FUNCTION_TYPE bmi160_read_bst_akm_sensitivity_data(void)
  18538. {
  18539. /* This variable is used to provide the communication
  18540. results*/
  18541. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  18542. /* Array holding the sensitivity ax,ay and az data*/
  18543. u8 v_data_u8[BMI160_AKM_SENSITIVITY_DATA_SIZE] = {
  18544. BMI160_INIT_VALUE,
  18545. BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  18546. /* read asax value */
  18547. com_rslt = bmi160_set_mag_read_addr(BMI160_BST_AKM_ASAX);
  18548. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18549. /* 0x04 is secondary read Mag x LSB register */
  18550. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  18551. &v_data_u8[AKM_ASAX],
  18552. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  18553. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18554. akm_asa_data.asax = v_data_u8[AKM_ASAX];
  18555. /* read asay value */
  18556. com_rslt += bmi160_set_mag_read_addr(BMI160_BST_AKM_ASAY);
  18557. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18558. /* 0x04 is secondary read Mag x LSB register */
  18559. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  18560. &v_data_u8[AKM_ASAY],
  18561. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  18562. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18563. akm_asa_data.asay = v_data_u8[AKM_ASAY];
  18564. /* read asaz value */
  18565. com_rslt += bmi160_set_mag_read_addr(BMI160_BST_AKM_ASAZ);
  18566. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18567. /* 0x04 is secondary read Mag x LSB register */
  18568. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  18569. &v_data_u8[AKM_ASAZ],
  18570. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  18571. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18572. akm_asa_data.asaz = v_data_u8[AKM_ASAZ];
  18573. return com_rslt;
  18574. }
  18575. /*!
  18576. * @brief This function is used to set the AKM09911 and AKM09912
  18577. * power mode.
  18578. * @note Before setting the AKM power mode
  18579. * make sure the following two points are addressed
  18580. * @note 1. Make sure the Mag interface is enabled or not,
  18581. * by using the bmi160_get_if_mode() function.
  18582. * If Mag interface is not enabled then set the value of 0x02
  18583. * to the function bmi160_get_if_mode(0x02)
  18584. * @note 2. And also confirm the secondary-interface power mode
  18585. * is not in the SUSPEND mode.
  18586. * by using the function bmi160_get_mag_pmu_status().
  18587. * If the secondary-interface power mode is in SUSPEND mode
  18588. * set the value of 0x19(NORMAL mode)by using the
  18589. * bmi160_set_command_register(0x19) function.
  18590. *
  18591. * @param v_akm_pow_mode_u8 : The value of akm power mode
  18592. * value | Description
  18593. * ---------|--------------------
  18594. * 0 | AKM_POWER_DOWN_MODE
  18595. * 1 | AKM_SINGLE_MEAS_MODE
  18596. * 2 | FUSE_ROM_MODE
  18597. *
  18598. *
  18599. * @return results of bus communication function
  18600. * @retval 0 -> Success
  18601. * @retval -1 -> Error
  18602. *
  18603. *
  18604. */
  18605. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_akm_set_powermode(
  18606. u8 v_akm_pow_mode_u8)
  18607. {
  18608. /* variable is used to return the status of communication result*/
  18609. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  18610. /* set Mag interface manual mode*/
  18611. if (p_bmi160->mag_manual_enable != BMI160_MANUAL_ENABLE) {
  18612. com_rslt = bmi160_set_mag_manual_enable(
  18613. BMI160_MANUAL_ENABLE);
  18614. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18615. }
  18616. switch (v_akm_pow_mode_u8) {
  18617. case AKM_POWER_DOWN_MODE:
  18618. /* Set the power mode of AKM as power down mode*/
  18619. com_rslt += bmi160_set_mag_write_data(
  18620. AKM_POWER_DOWN_MODE_DATA);
  18621. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18622. com_rslt += bmi160_set_mag_write_addr(
  18623. AKM_POWER_MODE_REG);
  18624. p_bmi160->delay_msec(
  18625. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  18626. break;
  18627. case AKM_SINGLE_MEAS_MODE:
  18628. /* Set the power mode of AKM as
  18629. single measurement mode*/
  18630. com_rslt += bmi160_set_mag_write_data
  18631. (AKM_SINGLE_MEASUREMENT_MODE);
  18632. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18633. com_rslt += bmi160_set_mag_write_addr(
  18634. AKM_POWER_MODE_REG);
  18635. p_bmi160->delay_msec(
  18636. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  18637. com_rslt += bmi160_set_mag_read_addr(AKM_DATA_REGISTER);
  18638. break;
  18639. case FUSE_ROM_MODE:
  18640. /* Set the power mode of AKM as
  18641. Fuse ROM mode*/
  18642. com_rslt += bmi160_set_mag_write_data(
  18643. AKM_FUSE_ROM_MODE);
  18644. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18645. com_rslt += bmi160_set_mag_write_addr(
  18646. AKM_POWER_MODE_REG);
  18647. p_bmi160->delay_msec(
  18648. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  18649. /* Sensitivity v_data_u8 */
  18650. com_rslt += bmi160_read_bst_akm_sensitivity_data();
  18651. p_bmi160->delay_msec(
  18652. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  18653. /* power down mode*/
  18654. com_rslt += bmi160_set_mag_write_data(
  18655. AKM_POWER_DOWN_MODE);
  18656. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18657. com_rslt += bmi160_set_mag_write_addr(
  18658. AKM_POWER_MODE_REG);
  18659. p_bmi160->delay_msec(
  18660. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  18661. break;
  18662. default:
  18663. com_rslt = E_BMI160_OUT_OF_RANGE;
  18664. break;
  18665. }
  18666. /* set Mag interface auto mode*/
  18667. if (p_bmi160->mag_manual_enable == BMI160_MANUAL_ENABLE) {
  18668. com_rslt += bmi160_set_mag_manual_enable(
  18669. BMI160_MANUAL_DISABLE);
  18670. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18671. }
  18672. return com_rslt;
  18673. }
  18674. /*!
  18675. * @brief This function is used to set the Mag
  18676. * power mode of AKM09911 and AKM09912
  18677. * @note Before setting the Mag power mode
  18678. * make sure the following two points are addressed
  18679. * Make sure the Mag interface is enabled or not,
  18680. * by using the bmi160_get_if_mode() function.
  18681. * If Mag interface is not enabled then set the value of 0x02
  18682. * to the function bmi160_get_if_mode(0x02)
  18683. *
  18684. * @param v_mag_sec_if_pow_mode_u8 : The value of secondary if power mode
  18685. * value | Description
  18686. * ---------|--------------------
  18687. * 0 | BMI160_MAG_FORCE_MODE
  18688. * 1 | BMI160_MAG_SUSPEND_MODE
  18689. *
  18690. *
  18691. * @return results of bus communication function
  18692. * @retval 0 -> Success
  18693. * @retval -1 -> Error
  18694. *
  18695. *
  18696. */
  18697. BMI160_RETURN_FUNCTION_TYPE
  18698. bmi160_set_bst_akm_and_secondary_if_powermode(
  18699. u8 v_mag_sec_if_pow_mode_u8)
  18700. {
  18701. u8 v_accel_power_mode_status = BMI160_INIT_VALUE;
  18702. /* variable used to return the status of communication result*/
  18703. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  18704. com_rslt = bmi160_get_accel_power_mode_stat(
  18705. &v_accel_power_mode_status);
  18706. /* Accel operation mode to normal*/
  18707. if (v_accel_power_mode_status != BMI160_ACCEL_NORMAL_MODE) {
  18708. com_rslt += bmi160_set_command_register(ACCEL_MODE_NORMAL);
  18709. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18710. }
  18711. /* set Mag interface manual mode*/
  18712. if (p_bmi160->mag_manual_enable != BMI160_MANUAL_ENABLE) {
  18713. com_rslt += bmi160_set_mag_manual_enable(
  18714. BMI160_MANUAL_ENABLE);
  18715. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18716. }
  18717. switch (v_mag_sec_if_pow_mode_u8) {
  18718. case BMI160_MAG_FORCE_MODE:
  18719. /* set the secondary Mag power mode as NORMAL*/
  18720. com_rslt += bmi160_set_mag_interface_normal();
  18721. /* set the akm power mode as single measurement mode*/
  18722. com_rslt += bmi160_bst_akm_set_powermode(
  18723. AKM_SINGLE_MEAS_MODE);
  18724. p_bmi160->delay_msec(
  18725. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  18726. com_rslt += bmi160_set_mag_read_addr(AKM_DATA_REGISTER);
  18727. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18728. break;
  18729. case BMI160_MAG_SUSPEND_MODE:
  18730. /* set the akm power mode as power down mode*/
  18731. com_rslt += bmi160_bst_akm_set_powermode(
  18732. AKM_POWER_DOWN_MODE);
  18733. p_bmi160->delay_msec(
  18734. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  18735. /* set the secondary Mag power mode as SUSPEND*/
  18736. com_rslt += bmi160_set_command_register(
  18737. MAG_MODE_SUSPEND);
  18738. p_bmi160->delay_msec(
  18739. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  18740. break;
  18741. default:
  18742. com_rslt = E_BMI160_OUT_OF_RANGE;
  18743. break;
  18744. }
  18745. /* set Mag interface auto mode*/
  18746. if (p_bmi160->mag_manual_enable == BMI160_MANUAL_ENABLE)
  18747. com_rslt += bmi160_set_mag_manual_enable(
  18748. BMI160_MANUAL_DISABLE);
  18749. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18750. switch (v_accel_power_mode_status) {
  18751. case BMI160_ACCEL_SUSPEND:
  18752. com_rslt += bmi160_set_command_register(ACCEL_SUSPEND);
  18753. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18754. break;
  18755. case BMI160_ACCEL_LOW_POWER:
  18756. com_rslt += bmi160_set_command_register(ACCEL_LOWPOWER);
  18757. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18758. break;
  18759. default:
  18760. break;
  18761. }
  18762. return com_rslt;
  18763. }
  18764. #endif
  18765. #ifdef YAS532
  18766. /***************************************************/
  18767. /**\name FUNCTIONS FOR YAMAHA-YAS532 */
  18768. /***************************************************/
  18769. /*!
  18770. * @brief This function is used to initialize the YAMAHA-YAS532 sensor
  18771. *
  18772. *
  18773. * @return results of bus communication function
  18774. * @retval 0 -> Success
  18775. * @retval -1 -> Error
  18776. *
  18777. *
  18778. */
  18779. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yamaha_yas532_mag_interface_init(
  18780. void)
  18781. {
  18782. /* This variable used to provide the communication
  18783. results*/
  18784. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  18785. u8 v_data_u8 = BMI160_INIT_VALUE;
  18786. u8 i = BMI160_INIT_VALUE;
  18787. u8 v_accel_power_mode_status = BMI160_INIT_VALUE;
  18788. com_rslt = bmi160_get_accel_power_mode_stat(
  18789. &v_accel_power_mode_status);
  18790. /* Accel operation mode to normal*/
  18791. if (v_accel_power_mode_status != BMI160_ACCEL_NORMAL_MODE) {
  18792. com_rslt += bmi160_set_command_register(ACCEL_MODE_NORMAL);
  18793. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18794. }
  18795. /* write Mag power mode as NORMAL*/
  18796. com_rslt += bmi160_set_mag_interface_normal();
  18797. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18798. /* Write the YAS532 i2c address*/
  18799. com_rslt += bmi160_set_i2c_device_addr(BMI160_AUX_YAS532_I2C_ADDRESS);
  18800. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18801. /* enable the Mag interface to manual mode*/
  18802. com_rslt += bmi160_set_mag_manual_enable(BMI160_MANUAL_ENABLE);
  18803. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18804. bmi160_get_mag_manual_enable(&v_data_u8);
  18805. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18806. /*Enable the MAG interface */
  18807. com_rslt += bmi160_set_if_mode(BMI160_ENABLE_MAG_IF_MODE);
  18808. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18809. bmi160_get_if_mode(&v_data_u8);
  18810. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18811. v_data_u8 = BMI160_MANUAL_DISABLE;
  18812. /* Read the YAS532 device id is 0x02*/
  18813. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS_DEVICE_ID_REG);
  18814. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18815. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  18816. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  18817. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18818. /* Read the YAS532 calibration data*/
  18819. com_rslt += bmi160_bst_yamaha_yas532_calib_values();
  18820. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  18821. /* Assign the data acquisition mode*/
  18822. yas532_data.measure_state = YAS532_MAG_STATE_INIT_COIL;
  18823. /* Set the default offset as invalid offset*/
  18824. set_vector(yas532_data.v_hard_offset_s8, INVALID_OFFSET);
  18825. /* set the transform to zero */
  18826. yas532_data.transform = BMI160_NULL;
  18827. /* Assign overflow as zero*/
  18828. yas532_data.overflow = 0;
  18829. #if 1 < YAS532_MAG_TEMPERATURE_LOG
  18830. yas532_data.temp_data.num =
  18831. yas532_data.temp_data.idx = 0;
  18832. #endif
  18833. /* Assign the coefficient value*/
  18834. for (i = 0; i < 3; i++) {
  18835. yas532_data.coef[i] = yas532_version_ac_coef[i];
  18836. yas532_data.last_raw[i] = 0;
  18837. }
  18838. yas532_data.last_raw[3] = 0;
  18839. /* Set the initial values of yas532*/
  18840. com_rslt += bmi160_bst_yas532_set_initial_values();
  18841. /* write the Mag v_data_bw_u8 as 25Hz*/
  18842. com_rslt += bmi160_set_mag_output_data_rate(
  18843. BMI160_MAG_OUTPUT_DATA_RATE_25HZ);
  18844. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18845. /* Enable Mag interface to auto mode*/
  18846. com_rslt += bmi160_set_mag_manual_enable(
  18847. BMI160_MANUAL_DISABLE);
  18848. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18849. bmi160_get_mag_manual_enable(&v_data_u8);
  18850. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18851. switch (v_accel_power_mode_status) {
  18852. case BMI160_ACCEL_SUSPEND:
  18853. com_rslt += bmi160_set_command_register(ACCEL_SUSPEND);
  18854. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18855. break;
  18856. case BMI160_ACCEL_LOW_POWER:
  18857. com_rslt += bmi160_set_command_register(ACCEL_LOWPOWER);
  18858. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  18859. break;
  18860. default:
  18861. break;
  18862. }
  18863. return com_rslt;
  18864. }
  18865. /*!
  18866. * @brief This function used to set the YAS532 initial values
  18867. *
  18868. *
  18869. * @return results of bus communication function
  18870. * @retval 0 -> Success
  18871. * @retval -1 -> Error
  18872. *
  18873. *
  18874. */
  18875. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yas532_set_initial_values(void)
  18876. {
  18877. /* This variable is used to provide the communication
  18878. results*/
  18879. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  18880. /* write testr1 as 0x00*/
  18881. com_rslt = bmi160_set_mag_write_data(
  18882. BMI160_YAS532_WRITE_TESTR1);
  18883. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  18884. com_rslt += bmi160_set_mag_write_addr(BMI160_YAS532_TESTR1);
  18885. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  18886. /* write testr2 as 0x00*/
  18887. com_rslt += bmi160_set_mag_write_data(
  18888. BMI160_YAS532_WRITE_TESTR2);
  18889. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  18890. com_rslt += bmi160_set_mag_write_addr(BMI160_YAS532_TESTR2);
  18891. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  18892. /* write Rcoil as 0x00*/
  18893. com_rslt += bmi160_set_mag_write_data(
  18894. BMI160_YAS532_WRITE_RCOIL);
  18895. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  18896. com_rslt += bmi160_set_mag_write_addr(BMI160_YAS532_RCOIL);
  18897. p_bmi160->delay_msec(BMI160_YAS532_SET_INITIAL_VALUE_DELAY);
  18898. /* check the valid offset*/
  18899. if (is_valid_offset(yas532_data.v_hard_offset_s8)) {
  18900. com_rslt += bmi160_bst_yas532_set_offset(
  18901. yas532_data.v_hard_offset_s8);
  18902. yas532_data.measure_state = YAS532_MAG_STATE_NORMAL;
  18903. } else {
  18904. /* set the default offset as invalid offset*/
  18905. set_vector(yas532_data.v_hard_offset_s8, INVALID_OFFSET);
  18906. /*Set the default measure state for offset correction*/
  18907. yas532_data.measure_state = YAS532_MAG_STATE_MEASURE_OFFSET;
  18908. }
  18909. return com_rslt;
  18910. }
  18911. /*!
  18912. * @brief This function is used to perform YAS532 offset correction
  18913. *
  18914. *
  18915. * @return results of bus communication function
  18916. * @retval 0 -> Success
  18917. * @retval -1 -> Error
  18918. *
  18919. *
  18920. */
  18921. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yas532_magnetic_measure_set_offset(
  18922. void)
  18923. {
  18924. /* This variable used to provide the communication
  18925. results*/
  18926. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  18927. /* to set the offset register*/
  18928. s8 v_hard_offset_s8[BMI160_HARD_OFFSET_DATA_SIZE] = {
  18929. BMI160_INIT_VALUE,
  18930. BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  18931. /* offset correction factors*/
  18932. static const u8 v_correct_u8[BMI160_YAS_CORRECT_DATA_SIZE] = {
  18933. 16, 8, 4, 2, 1};
  18934. /* used to store the temperature */
  18935. u16 v_temp_u16 = BMI160_INIT_VALUE;
  18936. /* used to read for the xy1y2 value */
  18937. u16 v_xy1y2_u16[BMI160_YAS_XY1Y2_DATA_SIZE] = {BMI160_INIT_VALUE,
  18938. BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  18939. /* local flag for assigning the values*/
  18940. s32 v_flag_s32[BMI160_YAS_FLAG_DATA_SIZE] = {BMI160_INIT_VALUE,
  18941. BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  18942. u8 i, j, v_busy_u8, v_overflow_u8 = BMI160_INIT_VALUE;
  18943. for (i = 0; i < 5; i++) {
  18944. /* set the offset values*/
  18945. com_rslt = bmi160_bst_yas532_set_offset(v_hard_offset_s8);
  18946. /* read the sensor data*/
  18947. com_rslt += bmi160_bst_yas532_normal_measurement_data(
  18948. BMI160_YAS532_ACQ_START, &v_busy_u8, &v_temp_u16,
  18949. v_xy1y2_u16, &v_overflow_u8);
  18950. /* check the sensor busy status*/
  18951. if (v_busy_u8)
  18952. return E_BMI160_BUSY;
  18953. /* calculate the magnetic correction with
  18954. offset and assign the values
  18955. to the offset register */
  18956. for (j = 0; j < 3; j++) {
  18957. if (YAS532_DATA_CENTER == v_xy1y2_u16[j])
  18958. v_flag_s32[j] = 0;
  18959. if (YAS532_DATA_CENTER < v_xy1y2_u16[j])
  18960. v_flag_s32[j] = 1;
  18961. if (v_xy1y2_u16[j] < YAS532_DATA_CENTER)
  18962. v_flag_s32[j] = -1;
  18963. }
  18964. for (j = 0; j < 3; j++) {
  18965. if (v_flag_s32[j])
  18966. v_hard_offset_s8[j] = (s8)(v_hard_offset_s8[j]
  18967. + v_flag_s32[j] * v_correct_u8[i]);
  18968. }
  18969. }
  18970. /* set the offset */
  18971. com_rslt += bmi160_bst_yas532_set_offset(v_hard_offset_s8);
  18972. return com_rslt;
  18973. }
  18974. /*!
  18975. * @brief This function used to read the
  18976. * YAMAHA YAS532 calibration data
  18977. *
  18978. *
  18979. * @return results of bus communication function
  18980. * @retval 0 -> Success
  18981. * @retval -1 -> Error
  18982. *
  18983. *
  18984. */
  18985. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yamaha_yas532_calib_values(void)
  18986. {
  18987. /* This variable is used to provide the communication
  18988. results*/
  18989. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  18990. /* Array holding the YAS532 calibration values */
  18991. u8 v_data_u8[BMI160_YAS532_CALIB_DATA_SIZE] = {
  18992. BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  18993. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  18994. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  18995. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  18996. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  18997. /* Read the DX value */
  18998. com_rslt = bmi160_set_mag_read_addr(BMI160_YAS532_CALIB_CX);
  18999. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19000. /* 0x04 is secondary read Mag x LSB register */
  19001. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19002. &v_data_u8[0], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19003. yas532_data.calib_yas532.cx = (s32)((v_data_u8[0]
  19004. * 10) - 1280);
  19005. /* Read the DY1 value */
  19006. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB_CY1);
  19007. /* 0x04 is secondary read Mag x LSB register */
  19008. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19009. &v_data_u8[1], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19010. yas532_data.calib_yas532.cy1 =
  19011. (s32)((v_data_u8[1] * 10) - 1280);
  19012. /* Read the DY2 value */
  19013. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB_CY2);
  19014. /* 0x04 is secondary read Mag x LSB register */
  19015. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19016. &v_data_u8[2], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19017. yas532_data.calib_yas532.cy2 =
  19018. (s32)((v_data_u8[2] * 10) - 1280);
  19019. /* Read the D2 and D3 value */
  19020. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB1);
  19021. /* 0x04 is secondary read Mag x LSB register */
  19022. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19023. &v_data_u8[3], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19024. yas532_data.calib_yas532.a2 =
  19025. (s32)(((v_data_u8[3] >>
  19026. BMI160_SHIFT_BIT_POSITION_BY_02_BITS)
  19027. & 0x03F) - 32);
  19028. /* Read the D3 and D4 value */
  19029. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB2);
  19030. /* 0x04 is secondary read Mag x LSB register */
  19031. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19032. &v_data_u8[4], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19033. /* calculate a3*/
  19034. yas532_data.calib_yas532.a3 = (s32)((((v_data_u8[3] <<
  19035. BMI160_SHIFT_BIT_POSITION_BY_02_BITS) & 0x0C) |
  19036. ((v_data_u8[4]
  19037. >> BMI160_SHIFT_BIT_POSITION_BY_06_BITS)
  19038. & 0x03)) - 8);
  19039. /* calculate a4*/
  19040. yas532_data.calib_yas532.a4 = (s32)((v_data_u8[4]
  19041. & 0x3F) - 32);
  19042. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19043. /* Read the D5 and D6 value */
  19044. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB3);
  19045. /* 0x04 is secondary read Mag x LSB register */
  19046. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19047. &v_data_u8[5], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19048. /* calculate a5*/
  19049. yas532_data.calib_yas532.a5 =
  19050. (s32)(((v_data_u8[5]
  19051. >> BMI160_SHIFT_BIT_POSITION_BY_02_BITS)
  19052. & 0x3F) + 38);
  19053. /* Read the D6 and D7 value */
  19054. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB4);
  19055. /* 0x04 is secondary read Mag x LSB register */
  19056. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19057. &v_data_u8[6], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19058. /* calculate a6*/
  19059. yas532_data.calib_yas532.a6 =
  19060. (s32)((((v_data_u8[5]
  19061. << BMI160_SHIFT_BIT_POSITION_BY_04_BITS)
  19062. & 0x30) | ((v_data_u8[6] >>
  19063. BMI160_SHIFT_BIT_POSITION_BY_04_BITS)
  19064. & 0x0F)) - 32);
  19065. /* Read the D7 and D8 value */
  19066. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB5);
  19067. /* 0x04 is secondary read Mag x LSB register */
  19068. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19069. &v_data_u8[7], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19070. /* calculate a7*/
  19071. yas532_data.calib_yas532.a7 = (s32)((((v_data_u8[6]
  19072. << BMI160_SHIFT_BIT_POSITION_BY_03_BITS)
  19073. & 0x78) |
  19074. ((v_data_u8[7]
  19075. >> BMI160_SHIFT_BIT_POSITION_BY_05_BITS) &
  19076. 0x07)) - 64);
  19077. /* Read the D8 and D9 value */
  19078. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB6);
  19079. /* 0x04 is secondary read Mag x LSB register */
  19080. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19081. &v_data_u8[8], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19082. /* calculate a8*/
  19083. yas532_data.calib_yas532.a8 = (s32)((((v_data_u8[7] <<
  19084. BMI160_GEN_READ_WRITE_DATA_LENGTH) & 0x3E) |
  19085. ((v_data_u8[8] >>
  19086. BMI160_SHIFT_BIT_POSITION_BY_07_BITS) & 0x01)) -
  19087. 32);
  19088. /* Read the D8 and D9 value */
  19089. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB7);
  19090. /* 0x04 is secondary read Mag x LSB register */
  19091. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19092. &v_data_u8[9], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19093. /* calculate a9*/
  19094. yas532_data.calib_yas532.a9 = (s32)(((v_data_u8[8] <<
  19095. BMI160_GEN_READ_WRITE_DATA_LENGTH) & 0xFE) |
  19096. ((v_data_u8[9] >>
  19097. BMI160_SHIFT_BIT_POSITION_BY_07_BITS) & 0x01));
  19098. /* calculate k*/
  19099. yas532_data.calib_yas532.k = (s32)((v_data_u8[9] >>
  19100. BMI160_SHIFT_BIT_POSITION_BY_02_BITS) & 0x1F);
  19101. /* Read the value from register 0x9A*/
  19102. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB8);
  19103. /* 0x04 is secondary read Mag x LSB register */
  19104. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19105. &v_data_u8[10],
  19106. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19107. /* Read the value from register 0x9B*/
  19108. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB9);
  19109. /* 0x04 is secondary read Mag x LSB register */
  19110. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19111. &v_data_u8[11],
  19112. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19113. /* Read the value from register 0x9C*/
  19114. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB10);
  19115. /* 0x04 is secondary read Mag x LSB register */
  19116. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19117. &v_data_u8[12],
  19118. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19119. /* Read the value from register 0x9D*/
  19120. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB11);
  19121. /* 0x04 is secondary read Mag x LSB register */
  19122. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19123. &v_data_u8[13],
  19124. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19125. /* Calculate the fxy1y2 and rxy1y1*/
  19126. yas532_data.calib_yas532.fxy1y2[0] =
  19127. (u8)(((v_data_u8[10]
  19128. & 0x01)
  19129. << BMI160_SHIFT_BIT_POSITION_BY_01_BIT)
  19130. | ((v_data_u8[11] >>
  19131. BMI160_SHIFT_BIT_POSITION_BY_07_BITS) & 0x01));
  19132. yas532_data.calib_yas532.rxy1y2[0] =
  19133. ((s8)(((v_data_u8[10]
  19134. >> BMI160_SHIFT_BIT_POSITION_BY_01_BIT) & 0x3F)
  19135. << BMI160_SHIFT_BIT_POSITION_BY_02_BITS))
  19136. >> BMI160_SHIFT_BIT_POSITION_BY_02_BITS;
  19137. yas532_data.calib_yas532.fxy1y2[1] =
  19138. (u8)(((v_data_u8[11] & 0x01)
  19139. << BMI160_SHIFT_BIT_POSITION_BY_01_BIT)
  19140. | ((v_data_u8[12] >>
  19141. BMI160_SHIFT_BIT_POSITION_BY_07_BITS) & 0x01));
  19142. yas532_data.calib_yas532.rxy1y2[1] =
  19143. ((s8)(((v_data_u8[11]
  19144. >> BMI160_SHIFT_BIT_POSITION_BY_01_BIT) & 0x3F)
  19145. << BMI160_SHIFT_BIT_POSITION_BY_02_BITS))
  19146. >> BMI160_SHIFT_BIT_POSITION_BY_02_BITS;
  19147. yas532_data.calib_yas532.fxy1y2[2] =
  19148. (u8)(((v_data_u8[12] & 0x01)
  19149. << BMI160_SHIFT_BIT_POSITION_BY_01_BIT)
  19150. | ((v_data_u8[13]
  19151. >> BMI160_SHIFT_BIT_POSITION_BY_07_BITS) & 0x01));
  19152. yas532_data.calib_yas532.rxy1y2[2] =
  19153. ((s8)(((v_data_u8[12]
  19154. >> BMI160_SHIFT_BIT_POSITION_BY_01_BIT) & 0x3F)
  19155. << BMI160_SHIFT_BIT_POSITION_BY_02_BITS))
  19156. >> BMI160_SHIFT_BIT_POSITION_BY_02_BITS;
  19157. return com_rslt;
  19158. }
  19159. /*!
  19160. * @brief This function is used to calculate the
  19161. * linear data in YAS532 sensor.
  19162. *
  19163. *
  19164. * @return results of bus communication function
  19165. * @retval 0 -> Success
  19166. * @retval -1 -> Error
  19167. *
  19168. *
  19169. */
  19170. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yas532_xy1y2_to_linear(
  19171. u16 *v_xy1y2_u16, s32 *xy1y2_linear)
  19172. {
  19173. /* This variable used to provide the communication
  19174. results*/
  19175. BMI160_RETURN_FUNCTION_TYPE com_rslt = SUCCESS;
  19176. static const u16 v_calib_data[] = {
  19177. 3721, 3971, 4221, 4471};
  19178. u8 i = BMI160_INIT_VALUE;
  19179. for (i = 0; i < 3; i++)
  19180. xy1y2_linear[i] = v_xy1y2_u16[i] -
  19181. v_calib_data[yas532_data.calib_yas532.fxy1y2[i]]
  19182. + (yas532_data.v_hard_offset_s8[i] -
  19183. yas532_data.calib_yas532.rxy1y2[i])
  19184. * yas532_data.coef[i];
  19185. return com_rslt;
  19186. }
  19187. /*!
  19188. * @brief This function is used to read the YAS532 sensor data
  19189. * @param v_acquisition_command_u8: used to set the data acquisition
  19190. * acquisition_command | operation
  19191. * ---------------------|-------------------------
  19192. * 0x17 | turn on the acquisition coil
  19193. * - | set direction of the coil
  19194. * _ | (x and y as minus(-))
  19195. * _ | Deferred acquisition mode
  19196. * 0x07 | turn on the acquisition coil
  19197. * _ | set direction of the coil
  19198. * _ | (x and y as minus(-))
  19199. * _ | Normal acquisition mode
  19200. * 0x11 | turn OFF the acquisition coil
  19201. * _ | set direction of the coil
  19202. * _ | (x and y as plus(+))
  19203. * _ | Deferred acquisition mode
  19204. * 0x01 | turn OFF the acquisition coil
  19205. * _ | set direction of the coil
  19206. * _ | (x and y as plus(+))
  19207. * _ | Normal acquisition mode
  19208. *
  19209. * @param v_busy_u8 : used to get the busy flag for sensor data read
  19210. * @param v_temp_u16 : used to get the temperature data
  19211. * @param v_xy1y2_u16 : used to get the sensor xy1y2 data
  19212. * @param v_overflow_u8 : used to get the overflow data
  19213. *
  19214. *
  19215. *
  19216. * @return results of bus communication function
  19217. * @retval 0 -> Success
  19218. * @retval -1 -> Error
  19219. *
  19220. *
  19221. */
  19222. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yas532_normal_measurement_data(
  19223. u8 v_acquisition_command_u8, u8 *v_busy_u8,
  19224. u16 *v_temp_u16, u16 *v_xy1y2_u16, u8 *v_overflow_u8)
  19225. {
  19226. /* This variable is used to provide the communication
  19227. results*/
  19228. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  19229. /* Array holding the YAS532 xyy1 data*/
  19230. u8 v_data_u8[BMI160_YAS_XY1Y2T_DATA_SIZE] = {
  19231. BMI160_INIT_VALUE,
  19232. BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  19233. BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  19234. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  19235. u8 i = BMI160_INIT_VALUE;
  19236. /* check the p_bmi160 structure for NULL pointer assignment*/
  19237. if (p_bmi160 == BMI160_NULL) {
  19238. return E_BMI160_NULL_PTR;
  19239. } else {
  19240. /* read the sensor data */
  19241. com_rslt = bmi160_bst_yas532_acquisition_command_register(
  19242. v_acquisition_command_u8);
  19243. com_rslt +=
  19244. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  19245. BMI160_USER_DATA_MAG_X_LSB__REG,
  19246. v_data_u8, BMI160_MAG_YAS_DATA_LENGTH);
  19247. /* read the xyy1 data*/
  19248. *v_busy_u8 =
  19249. ((v_data_u8[0]
  19250. >> BMI160_SHIFT_BIT_POSITION_BY_07_BITS) & 0x01);
  19251. *v_temp_u16 =
  19252. (u16)((((s32)v_data_u8[0]
  19253. << BMI160_SHIFT_BIT_POSITION_BY_03_BITS)
  19254. & 0x3F8) | ((v_data_u8[1]
  19255. >> BMI160_SHIFT_BIT_POSITION_BY_05_BITS) & 0x07));
  19256. v_xy1y2_u16[0] =
  19257. (u16)((((s32)v_data_u8[2]
  19258. << BMI160_SHIFT_BIT_POSITION_BY_06_BITS) & 0x1FC0)
  19259. | ((v_data_u8[3] >>
  19260. BMI160_SHIFT_BIT_POSITION_BY_02_BITS) & 0x3F));
  19261. v_xy1y2_u16[1] =
  19262. (u16)((((s32)v_data_u8[4]
  19263. << BMI160_SHIFT_BIT_POSITION_BY_06_BITS)
  19264. & 0x1FC0)
  19265. | ((v_data_u8[5]
  19266. >> BMI160_SHIFT_BIT_POSITION_BY_02_BITS) & 0x3F));
  19267. v_xy1y2_u16[2] =
  19268. (u16)((((s32)v_data_u8[6]
  19269. << BMI160_SHIFT_BIT_POSITION_BY_06_BITS)
  19270. & 0x1FC0)
  19271. | ((v_data_u8[7]
  19272. >> BMI160_SHIFT_BIT_POSITION_BY_02_BITS) & 0x3F));
  19273. *v_overflow_u8 = 0;
  19274. for (i = 0; i < 3; i++) {
  19275. if (v_xy1y2_u16[i] == YAS532_DATA_OVERFLOW)
  19276. *v_overflow_u8 |= (1 << (i * 2));
  19277. if (v_xy1y2_u16[i] == YAS532_DATA_UNDERFLOW)
  19278. *v_overflow_u8 |= (1 << (i * 2 + 1));
  19279. }
  19280. }
  19281. return com_rslt;
  19282. }
  19283. /*!
  19284. * @brief This function is used to read the YAS532 sensor data
  19285. * @param v_acquisition_command_u8 : the value of CMDR
  19286. * acquisition_command | operation
  19287. * ---------------------|-------------------------
  19288. * 0x17 | turn on the acquisition coil
  19289. * - | set direction of the coil
  19290. * _ | (x and y as minus(-))
  19291. * _ | Deferred acquisition mode
  19292. * 0x07 | turn on the acquisition coil
  19293. * _ | set direction of the coil
  19294. * _ | (x and y as minus(-))
  19295. * _ | Normal acquisition mode
  19296. * 0x11 | turn OFF the acquisition coil
  19297. * _ | set direction of the coil
  19298. * _ | (x and y as plus(+))
  19299. * _ | Deferred acquisition mode
  19300. * 0x01 | turn OFF the acquisition coil
  19301. * _ | set direction of the coil
  19302. * _ | (x and y as plus(+))
  19303. * _ | Normal acquisition mode
  19304. *
  19305. * @param xyz_data : the vector xyz output
  19306. * @param v_overflow_s8 : the value of overflow
  19307. * @param v_temp_correction_u8 : the value of temperate correction enable
  19308. *
  19309. *
  19310. * @return results of bus communication function
  19311. * @retval 0 -> Success
  19312. * @retval -1 -> Error
  19313. *
  19314. *
  19315. */
  19316. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yas532_measurement_xyz_data(
  19317. struct yas532_vector *xyz_data, u8 *v_overflow_s8, u8 v_temp_correction_u8,
  19318. u8 v_acquisition_command_u8)
  19319. {
  19320. /* This variable is used to provide the communication
  19321. results*/
  19322. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  19323. /* Array holding the linear calculation output*/
  19324. s32 v_xy1y2_linear_s32[BMI160_YAS_XY1Y2_DATA_SIZE] = {
  19325. BMI160_INIT_VALUE,
  19326. BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  19327. /* Array holding the temperature data */
  19328. s32 v_xyz_tmp_s32[BMI160_YAS_TEMP_DATA_SIZE] = {BMI160_INIT_VALUE,
  19329. BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  19330. s32 tmp = BMI160_INIT_VALUE;
  19331. s32 sx, sy1, sy2, sy, sz = BMI160_INIT_VALUE;
  19332. u8 i, v_busy_u8 = BMI160_INIT_VALUE;
  19333. u16 v_temp_u16 = BMI160_INIT_VALUE;
  19334. /* Array holding the xyy1 sensor raw data*/
  19335. u16 v_xy1y2_u16[BMI160_YAS_XY1Y2_DATA_SIZE] = {BMI160_INIT_VALUE,
  19336. BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  19337. #if 1 < YAS532_MAG_TEMPERATURE_LOG
  19338. s32 sum = BMI160_INIT_VALUE;
  19339. #endif
  19340. *v_overflow_s8 = BMI160_INIT_VALUE;
  19341. switch (yas532_data.measure_state) {
  19342. case YAS532_MAG_STATE_INIT_COIL:
  19343. if (p_bmi160->mag_manual_enable != BMI160_MANUAL_ENABLE)
  19344. com_rslt = bmi160_set_mag_manual_enable(
  19345. BMI160_MANUAL_ENABLE);
  19346. /* write Rcoil*/
  19347. com_rslt += bmi160_set_mag_write_data(
  19348. BMI160_YAS_DISABLE_RCOIL);
  19349. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19350. com_rslt += bmi160_set_mag_write_addr(BMI160_YAS532_RCOIL);
  19351. p_bmi160->delay_msec(BMI160_YAS532_MEASUREMENT_DELAY);
  19352. if (!yas532_data.overflow && is_valid_offset(
  19353. yas532_data.v_hard_offset_s8))
  19354. yas532_data.measure_state = 0;
  19355. break;
  19356. case YAS532_MAG_STATE_MEASURE_OFFSET:
  19357. com_rslt = bmi160_bst_yas532_magnetic_measure_set_offset();
  19358. yas532_data.measure_state = 0;
  19359. break;
  19360. default:
  19361. break;
  19362. }
  19363. /* Read sensor data*/
  19364. com_rslt += bmi160_bst_yas532_normal_measurement_data(
  19365. v_acquisition_command_u8, &v_busy_u8, &v_temp_u16,
  19366. v_xy1y2_u16, v_overflow_s8);
  19367. /* Calculate the linear data*/
  19368. com_rslt += bmi160_bst_yas532_xy1y2_to_linear(v_xy1y2_u16,
  19369. v_xy1y2_linear_s32);
  19370. /* Calculate temperature correction */
  19371. #if 1 < YAS532_MAG_TEMPERATURE_LOG
  19372. yas532_data.temp_data.log[yas532_data.temp_data.idx++] =
  19373. v_temp_u16;
  19374. if (YAS532_MAG_TEMPERATURE_LOG <= yas532_data.temp_data.idx)
  19375. yas532_data.temp_data.idx = 0;
  19376. yas532_data.temp_data.num++;
  19377. if (YAS532_MAG_TEMPERATURE_LOG <= yas532_data.temp_data.num)
  19378. yas532_data.temp_data.num = YAS532_MAG_TEMPERATURE_LOG;
  19379. for (i = 0; i < yas532_data.temp_data.num; i++)
  19380. sum += yas532_data.temp_data.log[i];
  19381. tmp = sum * 10 / yas532_data.temp_data.num
  19382. - YAS532_TEMP20DEGREE_TYPICAL * 10;
  19383. #else
  19384. tmp = (v_temp_u16 - YAS532_TEMP20DEGREE_TYPICAL)
  19385. * 10;
  19386. #endif
  19387. sx = v_xy1y2_linear_s32[0];
  19388. sy1 = v_xy1y2_linear_s32[1];
  19389. sy2 = v_xy1y2_linear_s32[2];
  19390. /* Temperature correction */
  19391. if (v_temp_correction_u8) {
  19392. sx -= (yas532_data.calib_yas532.cx * tmp)
  19393. / 1000;
  19394. sy1 -= (yas532_data.calib_yas532.cy1 * tmp)
  19395. / 1000;
  19396. sy2 -= (yas532_data.calib_yas532.cy2 * tmp)
  19397. / 1000;
  19398. }
  19399. sy = sy1 - sy2;
  19400. sz = -sy1 - sy2;
  19401. #if 1
  19402. xyz_data->yas532_vector_xyz[0] = yas532_data.calib_yas532.k *
  19403. ((100 * sx + yas532_data.calib_yas532.a2 * sy +
  19404. yas532_data.calib_yas532.a3 * sz) / 10);
  19405. xyz_data->yas532_vector_xyz[1] = yas532_data.calib_yas532.k *
  19406. ((yas532_data.calib_yas532.a4 * sx + yas532_data.calib_yas532.a5 * sy +
  19407. yas532_data.calib_yas532.a6 * sz) / 10);
  19408. xyz_data->yas532_vector_xyz[2] = yas532_data.calib_yas532.k *
  19409. ((yas532_data.calib_yas532.a7 * sx + yas532_data.calib_yas532.a8 * sy +
  19410. yas532_data.calib_yas532.a9 * sz) / 10);
  19411. if (yas532_data.transform != BMI160_NULL) {
  19412. for (i = 0; i < 3; i++) {
  19413. v_xyz_tmp_s32[i] = yas532_data.transform[i
  19414. * 3] *
  19415. xyz_data->yas532_vector_xyz[0]
  19416. + yas532_data.transform[i * 3 + 1] *
  19417. xyz_data->yas532_vector_xyz[1]
  19418. + yas532_data.transform[i * 3 + 2] *
  19419. xyz_data->yas532_vector_xyz[2];
  19420. }
  19421. set_vector(xyz_data->yas532_vector_xyz, v_xyz_tmp_s32);
  19422. }
  19423. for (i = 0; i < 3; i++) {
  19424. xyz_data->yas532_vector_xyz[i] -=
  19425. xyz_data->yas532_vector_xyz[i] % 10;
  19426. if (*v_overflow_s8 & (1
  19427. << (i * 2)))
  19428. xyz_data->yas532_vector_xyz[i] +=
  19429. 1; /* set overflow */
  19430. if (*v_overflow_s8 & (1 <<
  19431. (i * 2 + 1)))
  19432. xyz_data->yas532_vector_xyz[i] += 2; /* set underflow */
  19433. }
  19434. #else
  19435. xyz_data->yas532_vector_xyz[0] = sx;
  19436. xyz_data->yas532_vector_xyz[1] = sy;
  19437. xyz_data->yas532_vector_xyz[2] = sz;
  19438. #endif
  19439. if (v_busy_u8)
  19440. return com_rslt;
  19441. if (0 < *v_overflow_s8) {
  19442. if (!yas532_data.overflow)
  19443. yas532_data.overflow = 1;
  19444. yas532_data.measure_state = YAS532_MAG_STATE_INIT_COIL;
  19445. } else
  19446. yas532_data.overflow = 0;
  19447. for (i = 0; i < 3; i++)
  19448. yas532_data.last_raw[i] = v_xy1y2_u16[i];
  19449. yas532_data.last_raw[i] = v_temp_u16;
  19450. return com_rslt;
  19451. }
  19452. /*!
  19453. * @brief This function is used to read YAS532 sensor data
  19454. *
  19455. *
  19456. * @param v_xy1y2_u16 : the vector xyz output
  19457. * @param v_overflow_s8 : the value of overflow
  19458. * @param v_temp_correction_u8 : the value of temperate correction enable
  19459. * @param v_temp_u16 : the value of temperature
  19460. * @param v_busy_u8 : the value denoting the sensor is busy
  19461. *
  19462. * @return results of bus communication function
  19463. * @retval 0 -> Success
  19464. * @retval -1 -> Error
  19465. *
  19466. *
  19467. */
  19468. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yas532_fifo_xyz_data(
  19469. u16 *v_xy1y2_u16, u8 v_temp_correction_u8,
  19470. s8 v_overflow_s8, u16 v_temp_u16, u8 v_busy_u8)
  19471. {
  19472. /* This variable is used to provide the communication
  19473. results*/
  19474. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  19475. /* Array holding the linear calculation output*/
  19476. s32 v_xy1y2_linear_s32[BMI160_YAS_XY1Y2_DATA_SIZE] = {
  19477. BMI160_INIT_VALUE,
  19478. BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  19479. /* Array holding the temperature data */
  19480. s32 v_xyz_tmp_s32[BMI160_YAS_TEMP_DATA_SIZE] = {BMI160_INIT_VALUE,
  19481. BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  19482. s32 tmp = BMI160_INIT_VALUE;
  19483. s32 sx, sy1, sy2, sy, sz = BMI160_INIT_VALUE;
  19484. u8 i = BMI160_INIT_VALUE;
  19485. #if 1 < YAS532_MAG_TEMPERATURE_LOG
  19486. s32 sum = BMI160_INIT_VALUE;
  19487. #endif
  19488. v_overflow_s8 = BMI160_INIT_VALUE;
  19489. /* Calculate the linear data*/
  19490. com_rslt = bmi160_bst_yas532_xy1y2_to_linear(v_xy1y2_u16,
  19491. v_xy1y2_linear_s32);
  19492. /* Calculate temperature correction */
  19493. #if 1 < YAS532_MAG_TEMPERATURE_LOG
  19494. yas532_data.temp_data.log[yas532_data.temp_data.idx++] =
  19495. v_temp_u16;
  19496. if (YAS532_MAG_TEMPERATURE_LOG <= yas532_data.temp_data.idx)
  19497. yas532_data.temp_data.idx = 0;
  19498. yas532_data.temp_data.num++;
  19499. if (YAS532_MAG_TEMPERATURE_LOG <= yas532_data.temp_data.num)
  19500. yas532_data.temp_data.num = YAS532_MAG_TEMPERATURE_LOG;
  19501. for (i = 0; i < yas532_data.temp_data.num; i++)
  19502. sum += yas532_data.temp_data.log[i];
  19503. tmp = sum * 10 / yas532_data.temp_data.num
  19504. - YAS532_TEMP20DEGREE_TYPICAL * 10;
  19505. #else
  19506. tmp = (v_temp_u16 - YAS532_TEMP20DEGREE_TYPICAL)
  19507. * 10;
  19508. #endif
  19509. sx = v_xy1y2_linear_s32[0];
  19510. sy1 = v_xy1y2_linear_s32[1];
  19511. sy2 = v_xy1y2_linear_s32[2];
  19512. /* Temperature correction */
  19513. if (v_temp_correction_u8) {
  19514. sx -= (yas532_data.calib_yas532.cx * tmp)
  19515. / 1000;
  19516. sy1 -= (yas532_data.calib_yas532.cy1 * tmp)
  19517. / 1000;
  19518. sy2 -= (yas532_data.calib_yas532.cy2 * tmp)
  19519. / 1000;
  19520. }
  19521. sy = sy1 - sy2;
  19522. sz = -sy1 - sy2;
  19523. #if 1
  19524. fifo_xyz_data.yas532_vector_xyz[0] = yas532_data.calib_yas532.k *
  19525. ((100 * sx + yas532_data.calib_yas532.a2 * sy +
  19526. yas532_data.calib_yas532.a3 * sz) / 10);
  19527. fifo_xyz_data.yas532_vector_xyz[1] = yas532_data.calib_yas532.k *
  19528. ((yas532_data.calib_yas532.a4 * sx + yas532_data.calib_yas532.a5 * sy +
  19529. yas532_data.calib_yas532.a6 * sz) / 10);
  19530. fifo_xyz_data.yas532_vector_xyz[2] = yas532_data.calib_yas532.k *
  19531. ((yas532_data.calib_yas532.a7 * sx + yas532_data.calib_yas532.a8 * sy +
  19532. yas532_data.calib_yas532.a9 * sz) / 10);
  19533. if (yas532_data.transform != BMI160_NULL) {
  19534. for (i = 0; i < 3; i++) {
  19535. v_xyz_tmp_s32[i] = yas532_data.transform[i
  19536. * 3] *
  19537. fifo_xyz_data.yas532_vector_xyz[0]
  19538. + yas532_data.transform[i * 3 + 1] *
  19539. fifo_xyz_data.yas532_vector_xyz[1]
  19540. + yas532_data.transform[i * 3 + 2] *
  19541. fifo_xyz_data.yas532_vector_xyz[2];
  19542. }
  19543. set_vector(fifo_xyz_data.yas532_vector_xyz, v_xyz_tmp_s32);
  19544. }
  19545. for (i = 0; i < 3; i++) {
  19546. fifo_xyz_data.yas532_vector_xyz[i] -=
  19547. fifo_xyz_data.yas532_vector_xyz[i] % 10;
  19548. if (v_overflow_s8 & (1
  19549. << (i * 2)))
  19550. fifo_xyz_data.yas532_vector_xyz[i] +=
  19551. 1; /* set overflow */
  19552. if (v_overflow_s8 & (1 <<
  19553. (i * 2 + 1)))
  19554. fifo_xyz_data.yas532_vector_xyz[i] += 2;
  19555. }
  19556. #else
  19557. fifo_xyz_data.yas532_vector_xyz[0] = sx;
  19558. fifo_xyz_data.yas532_vector_xyz[1] = sy;
  19559. fifo_xyz_data.yas532_vector_xyz[2] = sz;
  19560. #endif
  19561. if (v_busy_u8)
  19562. return com_rslt;
  19563. if (0 < v_overflow_s8) {
  19564. if (!yas532_data.overflow)
  19565. yas532_data.overflow = 1;
  19566. yas532_data.measure_state = YAS532_MAG_STATE_INIT_COIL;
  19567. } else
  19568. yas532_data.overflow = 0;
  19569. for (i = 0; i < 3; i++)
  19570. yas532_data.last_raw[i] = v_xy1y2_u16[i];
  19571. yas532_data.last_raw[i] = v_temp_u16;
  19572. return com_rslt;
  19573. }
  19574. /*!
  19575. * @brief This function is used to write the data acquisition
  19576. * command register in YAS532 sensor.
  19577. * @param v_command_reg_data_u8 : the value of data acquisition
  19578. *
  19579. * acquisition_command | operation
  19580. * ---------------------|-------------------------
  19581. * 0x17 | turn on the acquisition coil
  19582. * - | set direction of the coil
  19583. * _ | (x and y as minus(-))
  19584. * _ | Deferred acquisition mode
  19585. * 0x07 | turn on the acquisition coil
  19586. * _ | set direction of the coil
  19587. * _ | (x and y as minus(-))
  19588. * _ | Normal acquisition mode
  19589. * 0x11 | turn OFF the acquisition coil
  19590. * _ | set direction of the coil
  19591. * _ | (x and y as plus(+))
  19592. * _ | Deferred acquisition mode
  19593. * 0x01 | turn OFF the acquisition coil
  19594. * _ | set direction of the coil
  19595. * _ | (x and y as plus(+))
  19596. * _ | Normal acquisition mode
  19597. *
  19598. *
  19599. *
  19600. * @return results of bus communication function
  19601. * @retval 0 -> Success
  19602. * @retval -1 -> Error
  19603. *
  19604. *
  19605. */
  19606. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yas532_acquisition_command_register(
  19607. u8 v_command_reg_data_u8)
  19608. {
  19609. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  19610. if (p_bmi160->mag_manual_enable != BMI160_MANUAL_ENABLE)
  19611. com_rslt = bmi160_set_mag_manual_enable(
  19612. BMI160_MANUAL_ENABLE);
  19613. com_rslt = bmi160_set_mag_write_data(v_command_reg_data_u8);
  19614. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19615. /* YAMAHA YAS532-0x82*/
  19616. com_rslt += bmi160_set_mag_write_addr(
  19617. BMI160_YAS532_COMMAND_REGISTER);
  19618. p_bmi160->delay_msec(BMI160_YAS_ACQ_COMMAND_DELAY);
  19619. com_rslt += bmi160_set_mag_read_addr(
  19620. BMI160_YAS532_DATA_REGISTER);
  19621. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19622. if (p_bmi160->mag_manual_enable == BMI160_MANUAL_ENABLE)
  19623. com_rslt += bmi160_set_mag_manual_enable(BMI160_MANUAL_DISABLE);
  19624. return com_rslt;
  19625. }
  19626. /*!
  19627. * @brief This function is used write the offset for YAS532 sensor
  19628. *
  19629. * @param p_offset_s8 : The value of offset to write
  19630. *
  19631. *
  19632. * @return results of bus communication function
  19633. * @retval 0 -> Success
  19634. * @retval -1 -> Error
  19635. *
  19636. *
  19637. */
  19638. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yas532_set_offset(
  19639. const s8 *p_offset_s8)
  19640. {
  19641. /* This variable is used to provide the communication
  19642. results*/
  19643. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  19644. if (p_bmi160->mag_manual_enable != BMI160_MANUAL_ENABLE)
  19645. com_rslt = bmi160_set_mag_manual_enable(BMI160_MANUAL_ENABLE);
  19646. p_bmi160->delay_msec(BMI160_YAS532_OFFSET_DELAY);
  19647. /* Write offset X data*/
  19648. com_rslt = bmi160_set_mag_write_data(p_offset_s8[0]);
  19649. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19650. /* YAS532 offset x write*/
  19651. com_rslt += bmi160_set_mag_write_addr(BMI160_YAS532_OFFSET_X);
  19652. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19653. /* Write offset Y data*/
  19654. com_rslt = bmi160_set_mag_write_data(p_offset_s8[1]);
  19655. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19656. /* YAS532 offset y write*/
  19657. com_rslt += bmi160_set_mag_write_addr(BMI160_YAS532_OFFSET_Y);
  19658. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19659. /* Write offset Z data*/
  19660. com_rslt = bmi160_set_mag_write_data(p_offset_s8[2]);
  19661. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19662. /* YAS532 offset z write*/
  19663. com_rslt += bmi160_set_mag_write_addr(BMI160_YAS532_OFFSET_Z);
  19664. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19665. set_vector(yas532_data.v_hard_offset_s8, p_offset_s8);
  19666. if (p_bmi160->mag_manual_enable == BMI160_MANUAL_ENABLE)
  19667. com_rslt = bmi160_set_mag_manual_enable(BMI160_MANUAL_DISABLE);
  19668. return com_rslt;
  19669. }
  19670. #endif
  19671. #ifdef YAS537
  19672. /***************************************************/
  19673. /**\name FUNCTIONS FOR YAMAHA-YAS537 */
  19674. /***************************************************/
  19675. /*!
  19676. * @brief This function used to init the YAMAHA-YAS537
  19677. *
  19678. *
  19679. * @return results of bus communication function
  19680. * @retval 0 -> Success
  19681. * @retval -1 -> Error
  19682. *
  19683. *
  19684. */
  19685. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yamaha_yas537_mag_interface_init(
  19686. void)
  19687. {
  19688. /* This variable is used to provide the communication
  19689. results*/
  19690. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  19691. u8 v_data_u8 = BMI160_INIT_VALUE;
  19692. u8 i = BMI160_INIT_VALUE;
  19693. u8 v_accel_power_mode_status = BMI160_INIT_VALUE;
  19694. com_rslt = bmi160_get_accel_power_mode_stat(
  19695. &v_accel_power_mode_status);
  19696. /* Accel operation mode to normal*/
  19697. if (v_accel_power_mode_status != BMI160_ACCEL_NORMAL_MODE) {
  19698. com_rslt += bmi160_set_command_register(ACCEL_MODE_NORMAL);
  19699. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19700. }
  19701. /* write Mag power mode as NORMAL*/
  19702. com_rslt += bmi160_set_mag_interface_normal();
  19703. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19704. /* Write the YAS532 i2c address*/
  19705. com_rslt += bmi160_set_i2c_device_addr(BMI160_YAS537_I2C_ADDRESS);
  19706. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19707. /* enable the Mag interface to manual mode*/
  19708. com_rslt += bmi160_set_mag_manual_enable(BMI160_MANUAL_ENABLE);
  19709. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19710. bmi160_get_mag_manual_enable(&v_data_u8);
  19711. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19712. /*Enable the MAG interface */
  19713. com_rslt += bmi160_set_if_mode(BMI160_ENABLE_MAG_IF_MODE);
  19714. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19715. bmi160_get_if_mode(&v_data_u8);
  19716. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19717. v_data_u8 = BMI160_MANUAL_DISABLE;
  19718. /* Read the YAS537 device id 0x07*/
  19719. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS_DEVICE_ID_REG);
  19720. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19721. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19722. &v_data_u8, BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19723. yas537_data.dev_id = v_data_u8;
  19724. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19725. /* Read the YAS537 calibration data*/
  19726. com_rslt +=
  19727. bmi160_bst_yamaha_yas537_calib_values(
  19728. BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19729. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  19730. /* set the mode to NORMAL*/
  19731. yas537_data.measure_state = YAS537_MAG_STATE_NORMAL;
  19732. /* set the transform to zero */
  19733. yas537_data.transform = BMI160_NULL;
  19734. yas537_data.average = 32;
  19735. for (i = 0; i < 3; i++) {
  19736. yas537_data.hard_offset[i] = -128;
  19737. yas537_data.last_after_rcoil[i] = 0;
  19738. }
  19739. for (i = 0; i < 4; i++)
  19740. yas537_data.last_raw[i] = 0;
  19741. /* write the Mag bandwidth as 25Hz*/
  19742. com_rslt += bmi160_set_mag_output_data_rate(
  19743. BMI160_MAG_OUTPUT_DATA_RATE_25HZ);
  19744. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19745. /* Enable Mag interface to auto mode*/
  19746. com_rslt += bmi160_set_mag_manual_enable(
  19747. BMI160_MANUAL_DISABLE);
  19748. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19749. bmi160_get_mag_manual_enable(&v_data_u8);
  19750. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19751. switch (v_accel_power_mode_status) {
  19752. case BMI160_ACCEL_SUSPEND:
  19753. com_rslt += bmi160_set_command_register(ACCEL_SUSPEND);
  19754. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19755. break;
  19756. case BMI160_ACCEL_LOW_POWER:
  19757. com_rslt += bmi160_set_command_register(ACCEL_LOWPOWER);
  19758. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19759. break;
  19760. default:
  19761. break;
  19762. }
  19763. return com_rslt;
  19764. }
  19765. /*!
  19766. * @brief This function is used to read the
  19767. * YAMAHA YAS537 calibration data
  19768. *
  19769. *
  19770. * @param v_rcoil_u8 : The value of r coil
  19771. *
  19772. *
  19773. * @return results of bus communication function
  19774. * @retval 0 -> Success
  19775. * @retval -1 -> Error
  19776. *
  19777. *
  19778. */
  19779. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yamaha_yas537_calib_values(
  19780. u8 v_rcoil_u8)
  19781. {
  19782. /* This variable is used to provide the communication
  19783. results*/
  19784. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  19785. /* Array holding the YAS532 calibration values */
  19786. u8 a_data_u8[BMI160_YAS537_CALIB_DATA_SIZE] = {
  19787. BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  19788. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  19789. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  19790. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  19791. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  19792. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  19793. };
  19794. static const u8 v_avrr_u8[] = {0x50, 0x60, 0x70};
  19795. u8 v_cal_valid_u8 = BMI160_INIT_VALUE, i;
  19796. /* write soft reset as 0x02*/
  19797. com_rslt = bmi160_set_mag_write_data(
  19798. YAS537_SRSTR_DATA);
  19799. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  19800. com_rslt += bmi160_set_mag_write_addr(YAS537_REG_SRSTR);
  19801. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  19802. /* Read the DX value */
  19803. com_rslt = bmi160_set_mag_read_addr(YAS537_REG_CALR_C0);
  19804. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19805. /* 0x04 is secondary read Mag x LSB register */
  19806. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19807. &a_data_u8[0], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19808. /* Read the DY1 value */
  19809. com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_C1);
  19810. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19811. /* 0x04 is secondary read Mag x LSB register */
  19812. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19813. &a_data_u8[1], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19814. /* Read the DY2 value */
  19815. com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_C2);
  19816. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19817. /* 0x04 is secondary read Mag x LSB register */
  19818. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19819. &a_data_u8[2], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19820. /* Read the D2 value */
  19821. com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_C3);
  19822. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19823. /* 0x04 is secondary read Mag x LSB register */
  19824. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19825. &a_data_u8[3], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19826. /* Read the D3 value */
  19827. com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_C4);
  19828. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19829. /* 0x04 is secondary read Mag x LSB register */
  19830. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19831. &a_data_u8[4], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19832. /* Read the D4 value */
  19833. com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_C5);
  19834. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19835. /* 0x04 is secondary read Mag x LSB register */
  19836. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19837. &a_data_u8[5], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19838. /* Read the D5 value */
  19839. com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_C6);
  19840. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19841. /* 0x04 is secondary read Mag x LSB register */
  19842. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19843. &a_data_u8[6], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19844. /* Read the D6 value */
  19845. com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_C7);
  19846. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19847. /* 0x04 is secondary read Mag x LSB register */
  19848. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19849. &a_data_u8[7], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19850. /* Read the D7 value */
  19851. com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_C8);
  19852. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19853. /* 0x04 is secondary read Mag x LSB register */
  19854. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19855. &a_data_u8[8], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19856. /* Read the D8 value */
  19857. com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_C9);
  19858. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19859. /* 0x04 is secondary read Mag x LSB register */
  19860. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19861. &a_data_u8[9], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19862. /* Read the D9 value */
  19863. com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_CA);
  19864. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19865. /* 0x04 is secondary read Mag x LSB register */
  19866. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19867. &a_data_u8[10], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19868. /* Read the RX value */
  19869. com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_CB);
  19870. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19871. /* 0x04 is secondary read Mag x LSB register */
  19872. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19873. &a_data_u8[11], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19874. /* Read the RY1 value */
  19875. com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_CC);
  19876. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19877. /* 0x04 is secondary read Mag x LSB register */
  19878. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19879. &a_data_u8[12], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19880. /* Read the RY2 value */
  19881. com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_CD);
  19882. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19883. /* 0x04 is secondary read Mag x LSB register */
  19884. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19885. &a_data_u8[13], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19886. /* Read the RY2 value */
  19887. com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_CE);
  19888. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19889. /* 0x04 is secondary read Mag x LSB register */
  19890. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19891. &a_data_u8[14], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19892. /* Read the CHF value */
  19893. com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_CF);
  19894. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19895. /* 0x04 is secondary read Mag x LSB register */
  19896. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19897. &a_data_u8[15], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19898. /* Read the VER value */
  19899. com_rslt += bmi160_set_mag_read_addr(YAS537_REG_CALR_DO);
  19900. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  19901. /* 0x04 is secondary read Mag x LSB register */
  19902. com_rslt += bmi160_read_reg(BMI160_MAG_DATA_READ_REG,
  19903. &a_data_u8[16], BMI160_GEN_READ_WRITE_DATA_LENGTH);
  19904. /* get the calib ver*/
  19905. yas537_data.calib_yas537.ver =
  19906. (a_data_u8[16] >> BMI160_SHIFT_BIT_POSITION_BY_06_BITS);
  19907. for (i = 0; i < 17; i++) {
  19908. if (((i < 16 && a_data_u8[i]) != 0))
  19909. v_cal_valid_u8 = 1;
  19910. if ((i < 16 &&
  19911. (a_data_u8[i] & 0x3F)) != 0)
  19912. v_cal_valid_u8 = 1;
  19913. }
  19914. if (!v_cal_valid_u8)
  19915. return ERROR;
  19916. if (yas537_data.calib_yas537.ver == 0) {
  19917. for (i = 0; i < 17; i++) {
  19918. if (i < 12) {
  19919. /* write offset*/
  19920. com_rslt += bmi160_set_mag_write_data(
  19921. a_data_u8[i]);
  19922. p_bmi160->delay_msec(
  19923. BMI160_GEN_READ_WRITE_DELAY);
  19924. com_rslt += bmi160_set_mag_write_addr(
  19925. YAS537_REG_MTCR + i);
  19926. p_bmi160->delay_msec(
  19927. BMI160_GEN_READ_WRITE_DELAY);
  19928. } else if (i < 15) {
  19929. /* write offset correction*/
  19930. com_rslt += bmi160_set_mag_write_data(
  19931. a_data_u8[i]);
  19932. p_bmi160->delay_msec(
  19933. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  19934. com_rslt += bmi160_set_mag_write_addr((
  19935. (YAS537_REG_OXR + i) - 12));
  19936. p_bmi160->delay_msec(
  19937. BMI160_GEN_READ_WRITE_DELAY);
  19938. yas537_data.hard_offset[i - 12]
  19939. = a_data_u8[i];
  19940. } else {
  19941. /* write offset correction*/
  19942. com_rslt += bmi160_set_mag_write_data(
  19943. a_data_u8[i]);
  19944. p_bmi160->delay_msec(
  19945. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  19946. com_rslt += bmi160_set_mag_write_addr((
  19947. (YAS537_REG_OXR + i) - 11));
  19948. p_bmi160->delay_msec(
  19949. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  19950. }
  19951. }
  19952. } else if (yas537_data.calib_yas537.ver == 1) {
  19953. for (i = 0; i < 3; i++) {
  19954. /* write offset*/
  19955. com_rslt += bmi160_set_mag_write_data(
  19956. a_data_u8[i]);
  19957. p_bmi160->delay_msec(
  19958. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  19959. com_rslt += bmi160_set_mag_write_addr(
  19960. YAS537_REG_MTCR + i);
  19961. p_bmi160->delay_msec(
  19962. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  19963. if (com_rslt == SUCCESS) {
  19964. /* write offset*/
  19965. com_rslt += bmi160_set_mag_write_data(
  19966. a_data_u8[i + 12]);
  19967. p_bmi160->delay_msec(
  19968. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  19969. com_rslt += bmi160_set_mag_write_addr(
  19970. YAS537_REG_OXR + i);
  19971. p_bmi160->delay_msec(
  19972. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  19973. yas537_data.hard_offset[i] =
  19974. a_data_u8[i + 12];
  19975. } else {
  19976. com_rslt = ERROR;
  19977. }
  19978. }
  19979. /* write offset*/
  19980. com_rslt += bmi160_set_mag_write_data(
  19981. ((a_data_u8[i] & 0xE0) | 0x10));
  19982. p_bmi160->delay_msec(
  19983. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  19984. com_rslt += bmi160_set_mag_write_addr(
  19985. YAS537_REG_MTCR + i);
  19986. p_bmi160->delay_msec(
  19987. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  19988. /* write offset*/
  19989. com_rslt += bmi160_set_mag_write_data(
  19990. ((a_data_u8[15]
  19991. >> BMI160_SHIFT_BIT_POSITION_BY_03_BITS)
  19992. & 0x1E));
  19993. p_bmi160->delay_msec(
  19994. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  19995. com_rslt += bmi160_set_mag_write_addr(YAS537_REG_HCKR);
  19996. p_bmi160->delay_msec(
  19997. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  19998. /* write offset*/
  19999. com_rslt += bmi160_set_mag_write_data(
  20000. ((a_data_u8[15] << 1) & 0x1E));
  20001. p_bmi160->delay_msec(
  20002. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  20003. com_rslt += bmi160_set_mag_write_addr(YAS537_REG_LCKR);
  20004. p_bmi160->delay_msec(
  20005. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  20006. /* write offset*/
  20007. com_rslt += bmi160_set_mag_write_data(
  20008. (a_data_u8[16] & 0x3F));
  20009. p_bmi160->delay_msec(
  20010. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  20011. com_rslt += bmi160_set_mag_write_addr(YAS537_REG_OCR);
  20012. p_bmi160->delay_msec(
  20013. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  20014. /* Assign the calibration values*/
  20015. /* a2 */
  20016. yas537_data.calib_yas537.a2 =
  20017. ((((a_data_u8[3]
  20018. << BMI160_SHIFT_BIT_POSITION_BY_02_BITS)
  20019. & 0x7C)
  20020. | (a_data_u8[4]
  20021. >> BMI160_SHIFT_BIT_POSITION_BY_06_BITS)) - 64);
  20022. /* a3 */
  20023. yas537_data.calib_yas537.a3 =
  20024. ((((a_data_u8[4] << BMI160_SHIFT_BIT_POSITION_BY_01_BIT)
  20025. & 0x7E)
  20026. | (a_data_u8[5]
  20027. >> BMI160_SHIFT_BIT_POSITION_BY_07_BITS)) - 64);
  20028. /* a4 */
  20029. yas537_data.calib_yas537.a4 =
  20030. ((((a_data_u8[5]
  20031. << BMI160_SHIFT_BIT_POSITION_BY_01_BIT)
  20032. & 0xFE)
  20033. | (a_data_u8[6]
  20034. >> BMI160_SHIFT_BIT_POSITION_BY_07_BITS))
  20035. - 128);
  20036. /* a5 */
  20037. yas537_data.calib_yas537.a5 =
  20038. ((((a_data_u8[6]
  20039. << BMI160_SHIFT_BIT_POSITION_BY_02_BITS)
  20040. & 0x1FC)
  20041. | (a_data_u8[7]
  20042. >> BMI160_SHIFT_BIT_POSITION_BY_06_BITS))
  20043. - 112);
  20044. /* a6 */
  20045. yas537_data.calib_yas537.a6 =
  20046. ((((a_data_u8[7]
  20047. << BMI160_SHIFT_BIT_POSITION_BY_01_BIT)
  20048. & 0x7E)
  20049. | (a_data_u8[8]
  20050. >> BMI160_SHIFT_BIT_POSITION_BY_07_BITS)) - 64);
  20051. /* a7 */
  20052. yas537_data.calib_yas537.a7 =
  20053. ((((a_data_u8[8]
  20054. << BMI160_SHIFT_BIT_POSITION_BY_01_BIT)
  20055. & 0xFE)
  20056. | (a_data_u8[9]
  20057. >> BMI160_SHIFT_BIT_POSITION_BY_07_BITS))
  20058. - 128);
  20059. /* a8 */
  20060. yas537_data.calib_yas537.a8 = ((a_data_u8[9] &
  20061. 0x7F) - 64);
  20062. /* a9 */
  20063. yas537_data.calib_yas537.a9 = ((((a_data_u8[10]
  20064. << BMI160_SHIFT_BIT_POSITION_BY_01_BIT) & 0x1FE)
  20065. | (a_data_u8[11]
  20066. >> BMI160_SHIFT_BIT_POSITION_BY_07_BITS))
  20067. - 112);
  20068. /* k */
  20069. yas537_data.calib_yas537.k = (
  20070. a_data_u8[11] & 0x7F);
  20071. } else {
  20072. return ERROR;
  20073. }
  20074. /* write A/D converter*/
  20075. com_rslt += bmi160_set_mag_write_data(
  20076. YAS537_WRITE_A_D_CONVERTER);
  20077. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  20078. com_rslt += bmi160_set_mag_write_addr(YAS537_REG_ADCCALR);
  20079. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  20080. /* write A/D converter second register*/
  20081. com_rslt += bmi160_set_mag_write_data(
  20082. YAS537_WRITE_A_D_CONVERTER2);
  20083. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  20084. com_rslt += bmi160_set_mag_write_addr(YAS537_REG_ADCCALR_ONE);
  20085. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  20086. /* write temperature calibration register*/
  20087. com_rslt += bmi160_set_mag_write_data(YAS537_WRITE_TEMP_CALIB);
  20088. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  20089. com_rslt += bmi160_set_mag_write_addr(YAS537_REG_TRMR);
  20090. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  20091. /* write average filter register*/
  20092. com_rslt += bmi160_set_mag_write_data(
  20093. v_avrr_u8[yas537_data.average]);
  20094. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  20095. com_rslt += bmi160_set_mag_write_addr(YAS537_REG_AVRR);
  20096. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  20097. if (v_rcoil_u8) {
  20098. /* write average; filter register*/
  20099. com_rslt += bmi160_set_mag_write_data(
  20100. YAS537_WRITE_FILTER);
  20101. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  20102. com_rslt += bmi160_set_mag_write_addr(YAS537_REG_CONFR);
  20103. p_bmi160->delay_msec(
  20104. BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  20105. }
  20106. return com_rslt;
  20107. }
  20108. /*!
  20109. * @brief This function is used for writing the data acquisition
  20110. * command register write in YAS537
  20111. * @param v_command_reg_data_u8 : the value of data acquisition
  20112. * acquisition_command | operation
  20113. * ---------------------|-------------------------
  20114. * 0x17 | turn on the acquisition coil
  20115. * - | set direction of the coil
  20116. * _ | (x and y as minus(-))
  20117. * _ | Deferred acquisition mode
  20118. * 0x07 | turn on the acquisition coil
  20119. * _ | set direction of the coil
  20120. * _ | (x and y as minus(-))
  20121. * _ | Normal acquisition mode
  20122. * 0x11 | turn OFF the acquisition coil
  20123. * _ | set direction of the coil
  20124. * _ | (x and y as plus(+))
  20125. * _ | Deferred acquisition mode
  20126. * 0x01 | turn OFF the acquisition coil
  20127. * _ | set direction of the coil
  20128. * _ | (x and y as plus(+))
  20129. * _ | Normal acquisition mode
  20130. *
  20131. *
  20132. *
  20133. * @return results of bus communication function
  20134. * @retval 0 -> Success
  20135. * @retval -1 -> Error
  20136. *
  20137. *
  20138. */
  20139. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yas537_acquisition_command_register(
  20140. u8 v_command_reg_data_u8)
  20141. {
  20142. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  20143. if (p_bmi160->mag_manual_enable != BMI160_MANUAL_ENABLE)
  20144. com_rslt = bmi160_set_mag_manual_enable(
  20145. BMI160_MANUAL_ENABLE);
  20146. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  20147. com_rslt = bmi160_set_mag_write_data(v_command_reg_data_u8);
  20148. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  20149. /* YAMAHA YAS532-0x82*/
  20150. com_rslt += bmi160_set_mag_write_addr(
  20151. BMI160_REG_YAS537_CMDR);
  20152. /* set the mode to RECORD*/
  20153. yas537_data.measure_state = YAS537_MAG_STATE_RECORD_DATA;
  20154. p_bmi160->delay_msec(BMI160_YAS_ACQ_COMMAND_DELAY);
  20155. com_rslt += bmi160_set_mag_read_addr(
  20156. YAS537_REG_TEMPERATURE_0);
  20157. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  20158. if (p_bmi160->mag_manual_enable == BMI160_MANUAL_ENABLE)
  20159. com_rslt += bmi160_set_mag_manual_enable(
  20160. BMI160_MANUAL_DISABLE);
  20161. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  20162. return com_rslt;
  20163. }
  20164. /*!
  20165. * @brief This function is used for processing the
  20166. * YAMAHA YAS537 xy1y2 raw data
  20167. *
  20168. * @param xy1y2: The value of raw xy1y2 data
  20169. * @param xyz: The value of xyz data
  20170. *
  20171. *
  20172. * @return None
  20173. *
  20174. *
  20175. */
  20176. static void xy1y2_to_xyz(u16 *xy1y2, s32 *xyz)
  20177. {
  20178. xyz[0] = ((xy1y2[0] - 8192)
  20179. * 300);
  20180. xyz[1] = (((xy1y2[1] - xy1y2[2])
  20181. * 1732) / 10);
  20182. xyz[2] = (((-xy1y2[2] - xy1y2[2])
  20183. + 16384) * 300);
  20184. }
  20185. /*!
  20186. * @brief This function is used to read the
  20187. * YAMAHA YAS537 xy1y2 data
  20188. *
  20189. * @param v_coil_stat_u8: The value of R coil status
  20190. * @param v_busy_u8: The value of busy status
  20191. * @param v_temperature_u16: The value of temperature
  20192. * @param xy1y2: The value of raw xy1y2 data
  20193. * @param v_outflow_u8: The value of overflow
  20194. *
  20195. *
  20196. * @return results of bus communication function
  20197. * @retval 0 -> Success
  20198. * @retval -1 -> Error
  20199. *
  20200. *
  20201. */
  20202. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yamaha_yas537_read_xy1y2_data(
  20203. u8 *v_coil_stat_u8, u8 *v_busy_u8,
  20204. u16 *v_temperature_u16, u16 *xy1y2, u8 *v_outflow_u8)
  20205. {
  20206. /* This variable is used to provide the communication
  20207. results*/
  20208. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  20209. /* Array holding the YAS532 calibration values */
  20210. u8 a_data_u8[BMI160_YAS_XY1Y2T_DATA_SIZE] = {
  20211. BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  20212. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  20213. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE,
  20214. };
  20215. u8 i = BMI160_INIT_VALUE;
  20216. s32 a_h_s32[BMI160_YAS_H_DATA_SIZE] = {
  20217. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  20218. s32 a_s_s32[BMI160_YAS_S_DATA_SIZE] = {
  20219. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  20220. /* set command register*/
  20221. com_rslt = bmi160_bst_yas537_acquisition_command_register(
  20222. YAS537_SET_COMMAND_REGISTER);
  20223. /* read the yas537 sensor data of xy1y2*/
  20224. com_rslt +=
  20225. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  20226. BMI160_USER_DATA_MAG_X_LSB__REG,
  20227. a_data_u8, BMI160_MAG_YAS_DATA_LENGTH);
  20228. /* read the busy flag*/
  20229. *v_busy_u8 = a_data_u8[2]
  20230. >> BMI160_SHIFT_BIT_POSITION_BY_07_BITS;
  20231. /* read the coil status*/
  20232. *v_coil_stat_u8 =
  20233. ((a_data_u8[2] >>
  20234. BMI160_SHIFT_BIT_POSITION_BY_06_BITS) & 0X01);
  20235. /* read temperature data*/
  20236. *v_temperature_u16 = (u16)((a_data_u8[0]
  20237. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS) | a_data_u8[1]);
  20238. /* read x data*/
  20239. xy1y2[0] = (u16)(((a_data_u8[2] &
  20240. 0x3F)
  20241. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  20242. | (a_data_u8[3]));
  20243. /* read y1 data*/
  20244. xy1y2[1] = (u16)((a_data_u8[4]
  20245. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  20246. | a_data_u8[5]);
  20247. /* read y2 data*/
  20248. xy1y2[2] = (u16)((a_data_u8[6]
  20249. << BMI160_SHIFT_BIT_POSITION_BY_08_BITS)
  20250. | a_data_u8[7]);
  20251. for (i = 0; i < 3; i++)
  20252. yas537_data.last_raw[i] = xy1y2[i];
  20253. yas537_data.last_raw[i] = *v_temperature_u16;
  20254. if (yas537_data.calib_yas537.ver == 1) {
  20255. for (i = 0; i < 3; i++)
  20256. a_s_s32[i] = xy1y2[i] - 8192;
  20257. /* read hx*/
  20258. a_h_s32[0] = ((yas537_data.calib_yas537.k * (
  20259. (128 * a_s_s32[0]) +
  20260. (yas537_data.calib_yas537.a2 * a_s_s32[1]) +
  20261. (yas537_data.calib_yas537.a3 * a_s_s32[2])))
  20262. / (8192));
  20263. /* read hy1*/
  20264. a_h_s32[1] = ((yas537_data.calib_yas537.k * (
  20265. (yas537_data.calib_yas537.a4 * a_s_s32[0]) +
  20266. (yas537_data.calib_yas537.a5 * a_s_s32[1]) +
  20267. (yas537_data.calib_yas537.a6 * a_s_s32[2])))
  20268. / (8192));
  20269. /* read hy2*/
  20270. a_h_s32[2] = ((yas537_data.calib_yas537.k * (
  20271. (yas537_data.calib_yas537.a7 * a_s_s32[0]) +
  20272. (yas537_data.calib_yas537.a8 * a_s_s32[1]) +
  20273. (yas537_data.calib_yas537.a9 * a_s_s32[2])))
  20274. / (8192));
  20275. for (i = 0; i < 3; i++) {
  20276. if (a_h_s32[i] < -8192)
  20277. a_h_s32[i] = -8192;
  20278. if (8192 < a_h_s32[i])
  20279. a_h_s32[i] = 8192;
  20280. xy1y2[i] = a_h_s32[i] + 8192;
  20281. }
  20282. }
  20283. *v_outflow_u8 = 0;
  20284. for (i = 0; i < 3; i++) {
  20285. if (YAS537_DATA_OVERFLOW <= xy1y2[i])
  20286. *v_outflow_u8 |= (1 << (i * 2));
  20287. if (xy1y2[i] == YAS537_DATA_UNDERFLOW)
  20288. *v_outflow_u8 |= (1 << (i * 2 + 1));
  20289. }
  20290. return com_rslt;
  20291. }
  20292. /*!
  20293. * @brief This function is used for detecting whether the mag
  20294. * data obtained is valid or not
  20295. *
  20296. *
  20297. * @param v_cur_u16: The value of current Mag data
  20298. * @param v_last_u16: The value of last Mag data
  20299. *
  20300. *
  20301. * @return results of magnetic field data's validity
  20302. * @retval 0 -> VALID DATA
  20303. * @retval 1 -> INVALID DATA
  20304. *
  20305. *
  20306. */
  20307. static BMI160_RETURN_FUNCTION_TYPE invalid_magnetic_field(
  20308. u16 *v_cur_u16, u16 *v_last_u16)
  20309. {
  20310. s16 invalid_thresh[] = {1500, 1500, 1500};
  20311. u8 i = BMI160_INIT_VALUE;
  20312. for (i = 0; i < 3; i++)
  20313. if (invalid_thresh[i] < ABS(v_cur_u16[i] - v_last_u16[i]))
  20314. return 1;
  20315. return 0;
  20316. }
  20317. /*!
  20318. * @brief This function is used to read the
  20319. * YAMAHA YAS537 xy1y2 data
  20320. *
  20321. * @param v_outflow_u8: The value of overflow
  20322. * @param *vector_xyz : yas vector structure pointer
  20323. *
  20324. * @return results of bus communication function
  20325. * @retval 0 -> Success
  20326. * @retval -1 -> Error
  20327. *
  20328. *
  20329. */
  20330. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yamaha_yas537_measure_xyz_data(
  20331. u8 *v_outflow_u8, struct yas_vector *vector_xyz)
  20332. {
  20333. s32 a_xyz_tmp_s32[BMI160_YAS_TEMP_DATA_SIZE] = {
  20334. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  20335. u8 i = BMI160_INIT_VALUE;
  20336. s8 com_rslt = BMI160_INIT_VALUE;
  20337. u8 v_busy_u8 = BMI160_INIT_VALUE;
  20338. u8 v_rcoil_u8 = BMI160_INIT_VALUE;
  20339. u16 v_temperature_u16 = BMI160_INIT_VALUE;
  20340. u16 a_xy1y2_u16[BMI160_YAS_XY1Y2_DATA_SIZE] = {
  20341. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  20342. *v_outflow_u8 = 0;
  20343. /* read the yas537 xy1y2 data*/
  20344. com_rslt = bmi160_bst_yamaha_yas537_read_xy1y2_data(
  20345. &v_rcoil_u8, &v_busy_u8,
  20346. &v_temperature_u16, a_xy1y2_u16, v_outflow_u8);
  20347. /* linear calculation*/
  20348. xy1y2_to_xyz(a_xy1y2_u16, vector_xyz->yas537_vector_xyz);
  20349. if (yas537_data.transform != BMI160_NULL) {
  20350. for (i = 0; i < 3; i++) {
  20351. a_xyz_tmp_s32[i] = ((
  20352. yas537_data.transform[i + 3]
  20353. * vector_xyz->yas537_vector_xyz[0])
  20354. + (yas537_data.transform[
  20355. i * 3 + 1]
  20356. * vector_xyz->yas537_vector_xyz[1])
  20357. + (yas537_data.transform[
  20358. i * 3 + 2]
  20359. * vector_xyz->yas537_vector_xyz[2]));
  20360. }
  20361. yas537_set_vector(
  20362. vector_xyz->yas537_vector_xyz, a_xyz_tmp_s32);
  20363. }
  20364. for (i = 0; i < 3; i++) {
  20365. vector_xyz->yas537_vector_xyz[i] -=
  20366. vector_xyz->yas537_vector_xyz[i] % 10;
  20367. if (*v_outflow_u8 & (1 <<
  20368. (i * 2)))
  20369. vector_xyz->yas537_vector_xyz[i] +=
  20370. 1; /* set overflow */
  20371. if (*v_outflow_u8 & (1 << (i * 2 + 1)))
  20372. /* set underflow */
  20373. vector_xyz->yas537_vector_xyz[i] += 2;
  20374. }
  20375. if (v_busy_u8)
  20376. return ERROR;
  20377. switch (yas537_data.measure_state) {
  20378. case YAS537_MAG_STATE_INIT_COIL:
  20379. if (p_bmi160->mag_manual_enable != BMI160_MANUAL_ENABLE)
  20380. com_rslt = bmi160_set_mag_manual_enable(
  20381. BMI160_MANUAL_ENABLE);
  20382. com_rslt += bmi160_set_mag_write_data(YAS537_WRITE_CONFR);
  20383. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  20384. com_rslt += bmi160_set_mag_write_addr(YAS537_REG_CONFR);
  20385. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  20386. yas537_data.measure_state = YAS537_MAG_STATE_RECORD_DATA;
  20387. if (p_bmi160->mag_manual_enable == BMI160_MANUAL_ENABLE)
  20388. com_rslt = bmi160_set_mag_manual_enable(
  20389. BMI160_MANUAL_DISABLE);
  20390. break;
  20391. case YAS537_MAG_STATE_RECORD_DATA:
  20392. if (v_rcoil_u8)
  20393. break;
  20394. yas537_set_vector(yas537_data.last_after_rcoil, a_xy1y2_u16);
  20395. yas537_data.measure_state = YAS537_MAG_STATE_NORMAL;
  20396. break;
  20397. case YAS537_MAG_STATE_NORMAL:
  20398. if (BMI160_INIT_VALUE < v_outflow_u8
  20399. || invalid_magnetic_field(a_xy1y2_u16,
  20400. yas537_data.last_after_rcoil)) {
  20401. yas537_data.measure_state = YAS537_MAG_STATE_INIT_COIL;
  20402. for (i = 0; i < 3; i++) {
  20403. if (!*v_outflow_u8)
  20404. vector_xyz->yas537_vector_xyz[i] += 3;
  20405. }
  20406. }
  20407. break;
  20408. }
  20409. return com_rslt;
  20410. }
  20411. /*!
  20412. * @brief This function is used to read the
  20413. * YAMAHA YAS537 xy1y2 data of fifo
  20414. *
  20415. * @param a_xy1y2_u16: The value of xyy1 data
  20416. * @param v_over_flow_u8: The value of overflow
  20417. * @param v_rcoil_u8: The value of rcoil
  20418. * @param v_busy_u8: The value of busy flag
  20419. *
  20420. *
  20421. * @return results of bus communication function
  20422. * @retval 0 -> Success
  20423. * @retval -1 -> Error
  20424. *
  20425. *
  20426. */
  20427. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yamaha_yas537_fifo_xyz_data(
  20428. u16 *a_xy1y2_u16, u8 v_over_flow_u8, u8 v_rcoil_u8, u8 v_busy_u8)
  20429. {
  20430. s32 a_xyz_tmp_s32[BMI160_YAS_TEMP_DATA_SIZE] = {
  20431. BMI160_INIT_VALUE, BMI160_INIT_VALUE, BMI160_INIT_VALUE};
  20432. u8 i = BMI160_INIT_VALUE;
  20433. s8 com_rslt = BMI160_INIT_VALUE;
  20434. /* linear calculation*/
  20435. xy1y2_to_xyz(a_xy1y2_u16, fifo_vector_xyz.yas537_vector_xyz);
  20436. if (yas537_data.transform != BMI160_NULL) {
  20437. for (i = 0; i < 3; i++) {
  20438. a_xyz_tmp_s32[i] = ((
  20439. yas537_data.transform[i + 3]
  20440. * fifo_vector_xyz.yas537_vector_xyz[0])
  20441. + (yas537_data.transform[
  20442. i * 3 + 1]
  20443. * fifo_vector_xyz.yas537_vector_xyz[1])
  20444. + (yas537_data.transform[
  20445. i * 3 + 2]
  20446. * fifo_vector_xyz.yas537_vector_xyz[2]));
  20447. }
  20448. yas537_set_vector(
  20449. fifo_vector_xyz.yas537_vector_xyz, a_xyz_tmp_s32);
  20450. }
  20451. for (i = 0; i < 3; i++) {
  20452. fifo_vector_xyz.yas537_vector_xyz[i] -=
  20453. fifo_vector_xyz.yas537_vector_xyz[i] % 10;
  20454. if (v_over_flow_u8 & (1 <<
  20455. (i * 2)))
  20456. fifo_vector_xyz.yas537_vector_xyz[i] +=
  20457. 1; /* set overflow */
  20458. if (v_over_flow_u8 & (1 << (i * 2 + 1)))
  20459. /* set underflow */
  20460. fifo_vector_xyz.yas537_vector_xyz[i] += 2;
  20461. }
  20462. if (v_busy_u8)
  20463. return ERROR;
  20464. switch (yas537_data.measure_state) {
  20465. case YAS537_MAG_STATE_INIT_COIL:
  20466. if (p_bmi160->mag_manual_enable != BMI160_MANUAL_ENABLE)
  20467. com_rslt = bmi160_set_mag_manual_enable(
  20468. BMI160_MANUAL_ENABLE);
  20469. com_rslt += bmi160_set_mag_write_data(YAS537_WRITE_CONFR);
  20470. p_bmi160->delay_msec(BMI160_GEN_READ_WRITE_DELAY);
  20471. com_rslt += bmi160_set_mag_write_addr(YAS537_REG_CONFR);
  20472. p_bmi160->delay_msec(BMI160_SEC_INTERFACE_GEN_READ_WRITE_DELAY);
  20473. yas537_data.measure_state = YAS537_MAG_STATE_RECORD_DATA;
  20474. if (p_bmi160->mag_manual_enable == BMI160_MANUAL_ENABLE)
  20475. com_rslt = bmi160_set_mag_manual_enable(
  20476. BMI160_MANUAL_DISABLE);
  20477. break;
  20478. case YAS537_MAG_STATE_RECORD_DATA:
  20479. if (v_rcoil_u8)
  20480. break;
  20481. yas537_set_vector(yas537_data.last_after_rcoil, a_xy1y2_u16);
  20482. yas537_data.measure_state = YAS537_MAG_STATE_NORMAL;
  20483. break;
  20484. case YAS537_MAG_STATE_NORMAL:
  20485. if (BMI160_INIT_VALUE < v_over_flow_u8
  20486. || invalid_magnetic_field(a_xy1y2_u16,
  20487. yas537_data.last_after_rcoil)) {
  20488. yas537_data.measure_state = YAS537_MAG_STATE_INIT_COIL;
  20489. for (i = 0; i < 3; i++) {
  20490. if (!v_over_flow_u8)
  20491. fifo_vector_xyz.yas537_vector_xyz[i]
  20492. += 3;
  20493. }
  20494. }
  20495. break;
  20496. }
  20497. return com_rslt;
  20498. }
  20499. #endif