bmi160.c 563 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361
  1. /*
  2. ****************************************************************************
  3. * Copyright (C) 2014 Bosch Sensortec GmbH
  4. *
  5. * bmi160.c
  6. * Date: 2014/12/12
  7. * Revision: 2.0.5 $
  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. #include "SEGGER_RTT.h"
  56. /* user defined code to be added here ... */
  57. static struct bmi160_t *p_bmi160;
  58. /* used for reading the mag trim values for compensation*/
  59. static struct trim_data_t mag_trim;
  60. /* the following variable used for avoiding the selecting of auto mode
  61. when it is running in the manual mode of BMM150 mag interface*/
  62. u8 V_bmm150_maual_auto_condition_u8 = C_BMI160_ZERO_U8X;
  63. /* used for reading the AKM compensating data */
  64. static struct bst_akm_sensitivity_data_t akm_asa_data;
  65. /* Assign the fifo time */
  66. u32 V_fifo_time_U32 = C_BMI160_ZERO_U8X;
  67. /* Used to store as accel fifo data */
  68. struct bmi160_accel_t accel_fifo[FIFO_FRAME_CNT];
  69. /* Used to store as gyro fifo data */
  70. struct bmi160_gyro_t gyro_fifo[FIFO_FRAME_CNT];
  71. /* Used to store as mag fifo data */
  72. struct bmi160_mag_t mag_fifo[FIFO_FRAME_CNT];
  73. /* FIFO data read for 1024 bytes of data */
  74. u8 v_fifo_data_u8[FIFO_FRAME] = {C_BMI160_ZERO_U8X};
  75. /* YAMAHA-YAS532*/
  76. /* value of coeff*/
  77. static const int yas532_version_ac_coef[] = {YAS532_VERSION_AC_COEF_X,
  78. YAS532_VERSION_AC_COEF_Y1, YAS532_VERSION_AC_COEF_Y2};
  79. /* used for reading the yas532 calibration data*/
  80. static struct yas532_t yas532_data;
  81. /*!
  82. * @brief
  83. * This function is used for initialize
  84. * bus read and bus write functions
  85. * assign the chip id and device address
  86. * chip id is read in the register 0x00 bit from 0 to 7
  87. *
  88. * @param bmi160 : structure pointer
  89. *
  90. * @return results of bus communication function
  91. * @retval 0 -> Success
  92. * @retval -1 -> Error
  93. *
  94. * @note
  95. * While changing the parameter of the bmi160_t
  96. * consider the following point:
  97. * Changing the reference value of the parameter
  98. * will changes the local copy or local reference
  99. * make sure your changes will not
  100. * affect the reference value of the parameter
  101. * (Better case don't change the reference value of the parameter)
  102. *
  103. */
  104. BMI160_RETURN_FUNCTION_TYPE bmi160_init(struct bmi160_t *bmi160)
  105. {
  106. /* variable used for return the status of communication result*/
  107. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  108. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  109. u8 v_pmu_data_u8 = BMI160_HEX_0_0_DATA;
  110. /* assign bmi160 ptr */
  111. p_bmi160 = bmi160;
  112. com_rslt =
  113. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  114. BMI160_USER_CHIP_ID__REG,
  115. &v_data_u8, C_BMI160_ONE_U8X);
  116. /* read Chip Id */
  117. p_bmi160->chip_id = v_data_u8;
  118. /* To avoid gyro wakeup it is required to write 0x00 to 0x6C*/
  119. com_rslt += bmi160_write_reg(BMI160_USER_PMU_TRIGGER_ADDR,
  120. &v_pmu_data_u8, C_BMI160_ONE_U8X);
  121. return com_rslt;
  122. }
  123. /*!
  124. * @brief
  125. * This API write the data to
  126. * the given register
  127. *
  128. *
  129. * @param v_addr_u8 -> Address of the register
  130. * @param v_data_u8 -> The data from the register
  131. * @param v_len_u8 -> no of bytes to read
  132. *
  133. *
  134. * @return results of bus communication function
  135. * @retval 0 -> Success
  136. * @retval -1 -> Error
  137. *
  138. *
  139. */
  140. BMI160_RETURN_FUNCTION_TYPE bmi160_write_reg(u8 v_addr_u8,
  141. u8 *v_data_u8, u8 v_len_u8)
  142. {
  143. /* variable used for return the status of communication result*/
  144. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  145. /* check the p_bmi160 structure as NULL*/
  146. if (p_bmi160 == BMI160_NULL) {
  147. return E_BMI160_NULL_PTR;
  148. } else {
  149. /* write data from register*/
  150. com_rslt =
  151. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->dev_addr,
  152. v_addr_u8, v_data_u8, v_len_u8);
  153. }
  154. return com_rslt;
  155. }
  156. /*!
  157. * @brief
  158. * This API reads the data from
  159. * the given register
  160. *
  161. *
  162. * @param v_addr_u8 -> Address of the register
  163. * @param v_data_u8 -> The data from the register
  164. * @param v_len_u8 -> no of bytes to read
  165. *
  166. *
  167. * @return results of bus communication function
  168. * @retval 0 -> Success
  169. * @retval -1 -> Error
  170. *
  171. *
  172. */
  173. BMI160_RETURN_FUNCTION_TYPE bmi160_read_reg(u8 v_addr_u8,
  174. u8 *v_data_u8, u8 v_len_u8)
  175. {
  176. /* variable used for return the status of communication result*/
  177. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  178. /* check the p_bmi160 structure as NULL*/
  179. if (p_bmi160 == BMI160_NULL) {
  180. return E_BMI160_NULL_PTR;
  181. } else {
  182. /* Read data from register*/
  183. com_rslt =
  184. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  185. v_addr_u8, v_data_u8, v_len_u8);
  186. }
  187. return com_rslt;
  188. }
  189. /*!
  190. * @brief This API used to reads the fatal error
  191. * from the Register 0x02 bit 0
  192. * This flag will be reset only by power-on-reset and soft reset
  193. *
  194. *
  195. * @param v_fatal_err_u8 : The status of fatal error
  196. *
  197. *
  198. *
  199. * @return results of bus communication function
  200. * @retval 0 -> Success
  201. * @retval -1 -> Error
  202. *
  203. *
  204. */
  205. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fatal_err(u8
  206. *v_fatal_err_u8)
  207. {
  208. /* variable used for return the status of communication result*/
  209. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  210. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  211. /* check the p_bmi160 structure as NULL*/
  212. if (p_bmi160 == BMI160_NULL) {
  213. return E_BMI160_NULL_PTR;
  214. } else {
  215. /* reading the fatal error status*/
  216. com_rslt =
  217. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  218. BMI160_USER_FATAL_ERR__REG,
  219. &v_data_u8, C_BMI160_ONE_U8X);
  220. *v_fatal_err_u8 = BMI160_GET_BITSLICE(v_data_u8,
  221. BMI160_USER_FATAL_ERR);
  222. }
  223. return com_rslt;
  224. }
  225. /*!
  226. * @brief This API used to read the error code
  227. * from register 0x02 bit 1 to 4
  228. *
  229. *
  230. * @param v_err_code_u8 : The status of error codes
  231. * error_code | description
  232. * ------------|---------------
  233. * 0x00 |no error
  234. * 0x01 |ACC_CONF error (accel ODR and bandwidth not compatible)
  235. * 0x02 |GYR_CONF error (Gyroscope ODR and bandwidth not compatible)
  236. * 0x03 |Under sampling mode and interrupt uses pre filtered data
  237. * 0x04 |reserved
  238. * 0x05 |Selected trigger-readout offset in
  239. * - |MAG_IF greater than selected ODR
  240. * 0x06 |FIFO configuration error for header less mode
  241. * 0x07 |Under sampling mode and pre filtered data as FIFO source
  242. *
  243. * @return results of bus communication function
  244. * @retval 0 -> Success
  245. * @retval -1 -> Error
  246. *
  247. *
  248. */
  249. BMI160_RETURN_FUNCTION_TYPE bmi160_get_err_code(u8
  250. *v_err_code_u8)
  251. {
  252. /* variable used for return the status of communication result*/
  253. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  254. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  255. /* check the p_bmi160 structure as NULL*/
  256. if (p_bmi160 == BMI160_NULL) {
  257. return E_BMI160_NULL_PTR;
  258. } else {
  259. com_rslt =
  260. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  261. BMI160_USER_ERR_CODE__REG,
  262. &v_data_u8, C_BMI160_ONE_U8X);
  263. *v_err_code_u8 = BMI160_GET_BITSLICE(v_data_u8,
  264. BMI160_USER_ERR_CODE);
  265. }
  266. return com_rslt;
  267. }
  268. /*!
  269. * @brief This API Reads the i2c error code from the
  270. * Register 0x02 bit 5.
  271. * This error occurred in I2C master detected
  272. *
  273. * @param v_i2c_err_code_u8 : The status of i2c fail error
  274. *
  275. *
  276. *
  277. * @return results of bus communication function
  278. * @retval 0 -> Success
  279. * @retval -1 -> Error
  280. *
  281. *
  282. */
  283. BMI160_RETURN_FUNCTION_TYPE bmi160_get_i2c_fail_err(u8
  284. *v_i2c_err_code_u8)
  285. {
  286. /* variable used for return the status of communication result*/
  287. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  288. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  289. /* check the p_bmi160 structure as NULL*/
  290. if (p_bmi160 == BMI160_NULL) {
  291. return E_BMI160_NULL_PTR;
  292. } else {
  293. com_rslt =
  294. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  295. BMI160_USER_I2C_FAIL_ERR__REG,
  296. &v_data_u8, C_BMI160_ONE_U8X);
  297. *v_i2c_err_code_u8 = BMI160_GET_BITSLICE(v_data_u8,
  298. BMI160_USER_I2C_FAIL_ERR);
  299. }
  300. return com_rslt;
  301. }
  302. /*!
  303. * @brief This API Reads the dropped command error
  304. * from the register 0x02 bit 6
  305. *
  306. *
  307. * @param v_drop_cmd_err_u8 : The status of drop command error
  308. *
  309. *
  310. *
  311. * @return results of bus communication function
  312. * @retval 0 -> Success
  313. * @retval -1 -> Error
  314. *
  315. *
  316. */
  317. BMI160_RETURN_FUNCTION_TYPE bmi160_get_drop_cmd_err(u8
  318. *v_drop_cmd_err_u8)
  319. {
  320. /* variable used for return the status of communication result*/
  321. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  322. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  323. /* check the p_bmi160 structure as NULL*/
  324. if (p_bmi160 == BMI160_NULL) {
  325. return E_BMI160_NULL_PTR;
  326. } else {
  327. com_rslt =
  328. p_bmi160->BMI160_BUS_READ_FUNC(
  329. p_bmi160->dev_addr,
  330. BMI160_USER_DROP_CMD_ERR__REG,
  331. &v_data_u8, C_BMI160_ONE_U8X);
  332. *v_drop_cmd_err_u8 = BMI160_GET_BITSLICE(
  333. v_data_u8,
  334. BMI160_USER_DROP_CMD_ERR);
  335. }
  336. return com_rslt;
  337. }
  338. /*!
  339. * @brief This API reads the magnetometer data ready
  340. * interrupt not active.
  341. * It reads from the error register 0x0x2 bit 7
  342. *
  343. *
  344. *
  345. *
  346. * @param v_mag_data_rdy_err_u8 : The status of mag data ready interrupt
  347. *
  348. *
  349. *
  350. * @return results of bus communication function
  351. * @retval 0 -> Success
  352. * @retval -1 -> Error
  353. *
  354. *
  355. */
  356. BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_dada_rdy_err(
  357. u8 *v_mag_data_rdy_err_u8)
  358. {
  359. /* variable used for return the status of communication result*/
  360. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  361. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  362. /* check the p_bmi160 structure as NULL*/
  363. if (p_bmi160 == BMI160_NULL) {
  364. return E_BMI160_NULL_PTR;
  365. } else {
  366. com_rslt =
  367. p_bmi160->BMI160_BUS_READ_FUNC(
  368. p_bmi160->dev_addr,
  369. BMI160_USER_MAG_DADA_RDY_ERR__REG,
  370. &v_data_u8, C_BMI160_ONE_U8X);
  371. *v_mag_data_rdy_err_u8 =
  372. BMI160_GET_BITSLICE(v_data_u8,
  373. BMI160_USER_MAG_DADA_RDY_ERR);
  374. }
  375. return com_rslt;
  376. }
  377. /*!
  378. * @brief This API reads the error status
  379. * from the error register 0x02 bit 0 to 7
  380. *
  381. * @param v_mag_data_rdy_err_u8 : The status of mag data ready interrupt
  382. * @param v_fatal_er_u8r : The status of fatal error
  383. * @param v_err_code_u8 : The status of error code
  384. * @param v_i2c_fail_err_u8 : The status of I2C fail error
  385. * @param v_drop_cmd_err_u8 : The status of drop command error
  386. *
  387. *
  388. *
  389. * @return results of bus communication function
  390. * @retval 0 -> Success
  391. * @retval -1 -> Error
  392. *
  393. *
  394. */
  395. BMI160_RETURN_FUNCTION_TYPE bmi160_get_error_status(u8 *v_fatal_er_u8r,
  396. u8 *v_err_code_u8, u8 *v_i2c_fail_err_u8,
  397. u8 *v_drop_cmd_err_u8, u8 *v_mag_data_rdy_err_u8)
  398. {
  399. /* variable used for return the status of communication result*/
  400. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  401. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  402. /* check the p_bmi160 structure as NULL*/
  403. if (p_bmi160 == BMI160_NULL) {
  404. return E_BMI160_NULL_PTR;
  405. } else {
  406. /* read the error codes*/
  407. com_rslt =
  408. p_bmi160->BMI160_BUS_READ_FUNC(
  409. p_bmi160->dev_addr,
  410. BMI160_USER_ERR_STAT__REG,
  411. &v_data_u8, C_BMI160_ONE_U8X);
  412. /* fatal error*/
  413. *v_fatal_er_u8r =
  414. BMI160_GET_BITSLICE(v_data_u8,
  415. BMI160_USER_FATAL_ERR);
  416. /* user error*/
  417. *v_err_code_u8 =
  418. BMI160_GET_BITSLICE(v_data_u8,
  419. BMI160_USER_ERR_CODE);
  420. /* i2c fail error*/
  421. *v_i2c_fail_err_u8 =
  422. BMI160_GET_BITSLICE(v_data_u8,
  423. BMI160_USER_I2C_FAIL_ERR);
  424. /* drop command error*/
  425. *v_drop_cmd_err_u8 =
  426. BMI160_GET_BITSLICE(v_data_u8,
  427. BMI160_USER_DROP_CMD_ERR);
  428. /* mag data ready error*/
  429. *v_mag_data_rdy_err_u8 =
  430. BMI160_GET_BITSLICE(v_data_u8,
  431. BMI160_USER_MAG_DADA_RDY_ERR);
  432. }
  433. return com_rslt;
  434. }
  435. /*!
  436. * @brief This API reads the magnetometer power mode from
  437. * PMU status register 0x03 bit 0 and 1
  438. *
  439. * @param v_mag_power_mode_stat_u8 : The value of mag power mode
  440. * mag_powermode | value
  441. * ------------------|----------
  442. * SUSPEND | 0x00
  443. * NORMAL | 0x01
  444. * LOW POWER | 0x02
  445. *
  446. *
  447. * @note The power mode of mag set by the 0x7E command register
  448. * @note using the function "bmi160_set_command_register()"
  449. * value | mode
  450. * ---------|----------------
  451. * 0x18 | MAG_MODE_SUSPEND
  452. * 0x19 | MAG_MODE_NORMAL
  453. * 0x1A | MAG_MODE_LOWPOWER
  454. *
  455. * @return results of bus communication function
  456. * @retval 0 -> Success
  457. * @retval -1 -> Error
  458. *
  459. *
  460. */
  461. BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_power_mode_stat(u8
  462. *v_mag_power_mode_stat_u8)
  463. {
  464. /* variable used for return the status of communication result*/
  465. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  466. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  467. /* check the p_bmi160 structure as NULL*/
  468. if (p_bmi160 == BMI160_NULL) {
  469. return E_BMI160_NULL_PTR;
  470. } else {
  471. com_rslt =
  472. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  473. BMI160_USER_MAG_POWER_MODE_STAT__REG,
  474. &v_data_u8, C_BMI160_ONE_U8X);
  475. *v_mag_power_mode_stat_u8 =
  476. BMI160_GET_BITSLICE(v_data_u8,
  477. BMI160_USER_MAG_POWER_MODE_STAT);
  478. }
  479. return com_rslt;
  480. }
  481. /*!
  482. * @brief This API reads the gyroscope power mode from
  483. * PMU status register 0x03 bit 2 and 3
  484. *
  485. * @param v_gyro_power_mode_stat_u8 : The value of gyro power mode
  486. * gyro_powermode | value
  487. * ------------------|----------
  488. * SUSPEND | 0x00
  489. * NORMAL | 0x01
  490. * FAST POWER UP | 0x03
  491. *
  492. * @note The power mode of gyro set by the 0x7E command register
  493. * @note using the function "bmi160_set_command_register()"
  494. * value | mode
  495. * ---------|----------------
  496. * 0x14 | GYRO_MODE_SUSPEND
  497. * 0x15 | GYRO_MODE_NORMAL
  498. * 0x17 | GYRO_MODE_FASTSTARTUP
  499. *
  500. * @return results of bus communication function
  501. * @retval 0 -> Success
  502. * @retval -1 -> Error
  503. *
  504. *
  505. */
  506. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_power_mode_stat(u8
  507. *v_gyro_power_mode_stat_u8)
  508. {
  509. /* variable used for return the status of communication result*/
  510. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  511. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  512. /* check the p_bmi160 structure as NULL*/
  513. if (p_bmi160 == BMI160_NULL) {
  514. return E_BMI160_NULL_PTR;
  515. } else {
  516. com_rslt =
  517. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  518. BMI160_USER_GYRO_POWER_MODE_STAT__REG,
  519. &v_data_u8, C_BMI160_ONE_U8X);
  520. *v_gyro_power_mode_stat_u8 =
  521. BMI160_GET_BITSLICE(v_data_u8,
  522. BMI160_USER_GYRO_POWER_MODE_STAT);
  523. }
  524. return com_rslt;
  525. }
  526. /*!
  527. * @brief This API reads the accelerometer power mode from
  528. * PMU status register 0x03 bit 4 and 5
  529. *
  530. *
  531. * @param v_accel_power_mode_stat_u8 : The value of accel power mode
  532. * accel_powermode | value
  533. * ------------------|----------
  534. * SUSPEND | 0x00
  535. * NORMAL | 0x01
  536. * LOW POWER | 0x02
  537. *
  538. * @note The power mode of accel set by the 0x7E command register
  539. * @note using the function "bmi160_set_command_register()"
  540. * value | mode
  541. * ---------|----------------
  542. * 0x11 | ACCEL_MODE_NORMAL
  543. * 0x12 | ACCEL_LOWPOWER
  544. * 0x10 | ACCEL_SUSPEND
  545. *
  546. * @return results of bus communication function
  547. * @retval 0 -> Success
  548. * @retval -1 -> Error
  549. *
  550. *
  551. */
  552. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_power_mode_stat(u8
  553. *v_accel_power_mode_stat_u8)
  554. {
  555. /* variable used for return the status of communication result*/
  556. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  557. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  558. /* check the p_bmi160 structure as NULL*/
  559. if (p_bmi160 == BMI160_NULL) {
  560. return E_BMI160_NULL_PTR;
  561. } else {
  562. com_rslt =
  563. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  564. BMI160_USER_ACCEL_POWER_MODE_STAT__REG,
  565. &v_data_u8, C_BMI160_ONE_U8X);
  566. *v_accel_power_mode_stat_u8 =
  567. BMI160_GET_BITSLICE(v_data_u8,
  568. BMI160_USER_ACCEL_POWER_MODE_STAT);
  569. }
  570. return com_rslt;
  571. }
  572. /*!
  573. * @brief This API reads magnetometer data X values
  574. * from the register 0x04 and 0x05
  575. * @brief The mag sensor data read form auxiliary mag
  576. *
  577. * @param v_mag_x_s16 : The value of mag x
  578. * @param v_sensor_select_u8 : Mag selection value
  579. * value | sensor
  580. * ---------|----------------
  581. * 0 | BMM150
  582. * 1 | AKM09911
  583. *
  584. * @note For mag data output rate configuration use the following function
  585. * @note bmi160_set_mag_output_data_rate()
  586. *
  587. *
  588. *
  589. * @return results of bus communication function
  590. * @retval 0 -> Success
  591. * @retval -1 -> Error
  592. *
  593. */
  594. BMI160_RETURN_FUNCTION_TYPE bmi160_read_mag_x(s16 *v_mag_x_s16,
  595. u8 v_sensor_select_u8)
  596. {
  597. /* variable used for return the status of communication result*/
  598. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  599. /* Array contains the mag X lSB and MSB data
  600. v_data_u8[0] - LSB
  601. v_data_u8[1] - MSB*/
  602. u8 v_data_u8[ARRAY_SIZE_TWO] = {C_BMI160_ZERO_U8X,
  603. C_BMI160_ZERO_U8X};
  604. /* check the p_bmi160 structure as NULL*/
  605. if (p_bmi160 == BMI160_NULL) {
  606. return E_BMI160_NULL_PTR;
  607. } else {
  608. switch (v_sensor_select_u8) {
  609. case BST_BMM:
  610. com_rslt =
  611. p_bmi160->BMI160_BUS_READ_FUNC(
  612. p_bmi160->dev_addr,
  613. BMI160_USER_DATA_MAG_X_LSB__REG,
  614. v_data_u8, C_BMI160_TWO_U8X);
  615. /* X axis*/
  616. v_data_u8[LSB_ZERO] =
  617. BMI160_GET_BITSLICE(v_data_u8[LSB_ZERO],
  618. BMI160_USER_DATA_MAG_X_LSB);
  619. *v_mag_x_s16 = (s16)
  620. ((((s32)((s8)v_data_u8[MSB_ONE]))
  621. << BMI160_SHIFT_5_POSITION) |
  622. (v_data_u8[LSB_ZERO]));
  623. break;
  624. case BST_AKM:
  625. com_rslt =
  626. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  627. BMI160_USER_DATA_0_MAG_X_LSB__REG,
  628. v_data_u8, C_BMI160_TWO_U8X);
  629. *v_mag_x_s16 = (s16)
  630. ((((s32)((s8)v_data_u8[MSB_ONE]))
  631. << BMI160_SHIFT_8_POSITION) |
  632. (v_data_u8[LSB_ZERO]));
  633. break;
  634. default:
  635. com_rslt = E_BMI160_OUT_OF_RANGE;
  636. break;
  637. }
  638. }
  639. return com_rslt;
  640. }
  641. /*!
  642. * @brief This API reads magnetometer data Y values
  643. * from the register 0x06 and 0x07
  644. * @brief The mag sensor data read form auxiliary mag
  645. *
  646. * @param v_mag_y_s16 : The value of mag y
  647. * @param v_sensor_select_u8 : Mag selection value
  648. * value | sensor
  649. * ---------|----------------
  650. * 0 | BMM150
  651. * 1 | AKM09911
  652. *
  653. * @note For mag data output rate configuration use the following function
  654. * @note bmi160_set_mag_output_data_rate()
  655. *
  656. * @return results of bus communication function
  657. * @retval 0 -> Success
  658. * @retval -1 -> Error
  659. *
  660. *
  661. */
  662. BMI160_RETURN_FUNCTION_TYPE bmi160_read_mag_y(s16 *v_mag_y_s16,
  663. u8 v_sensor_select_u8)
  664. {
  665. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_OUT_OF_RANGE;
  666. /* Array contains the mag Y lSB and MSB data
  667. v_data_u8[0] - LSB
  668. v_data_u8[1] - MSB*/
  669. u8 v_data_u8[ARRAY_SIZE_TWO] = {C_BMI160_ZERO_U8X,
  670. C_BMI160_ZERO_U8X};
  671. /* check the p_bmi160 structure as NULL*/
  672. if (p_bmi160 == BMI160_NULL) {
  673. return E_BMI160_NULL_PTR;
  674. } else {
  675. switch (v_sensor_select_u8) {
  676. case BST_BMM:
  677. com_rslt =
  678. p_bmi160->BMI160_BUS_READ_FUNC(
  679. p_bmi160->dev_addr,
  680. BMI160_USER_DATA_MAG_Y_LSB__REG,
  681. v_data_u8, C_BMI160_TWO_U8X);
  682. /*Y-axis lsb value shifting*/
  683. v_data_u8[LSB_ZERO] =
  684. BMI160_GET_BITSLICE(v_data_u8[LSB_ZERO],
  685. BMI160_USER_DATA_MAG_Y_LSB);
  686. *v_mag_y_s16 = (s16)
  687. ((((s32)((s8)v_data_u8[MSB_ONE]))
  688. << BMI160_SHIFT_5_POSITION) |
  689. (v_data_u8[LSB_ZERO]));
  690. break;
  691. case BST_AKM:
  692. com_rslt =
  693. p_bmi160->BMI160_BUS_READ_FUNC(
  694. p_bmi160->dev_addr,
  695. BMI160_USER_DATA_2_MAG_Y_LSB__REG,
  696. v_data_u8, C_BMI160_TWO_U8X);
  697. *v_mag_y_s16 = (s16)
  698. ((((s32)((s8)v_data_u8[MSB_ONE]))
  699. << BMI160_SHIFT_8_POSITION) |
  700. (v_data_u8[LSB_ZERO]));
  701. break;
  702. default:
  703. com_rslt = E_BMI160_OUT_OF_RANGE;
  704. break;
  705. }
  706. }
  707. return com_rslt;
  708. }
  709. /*!
  710. * @brief This API reads magnetometer data Z values
  711. * from the register 0x08 and 0x09
  712. * @brief The mag sensor data read form auxiliary mag
  713. *
  714. * @param v_mag_z_s16 : The value of mag z
  715. * @param v_sensor_select_u8 : Mag selection value
  716. * value | sensor
  717. * ---------|----------------
  718. * 0 | BMM150
  719. * 1 | AKM09911
  720. *
  721. * @note For mag data output rate configuration use the following function
  722. * @note bmi160_set_mag_output_data_rate()
  723. *
  724. * @return results of bus communication function
  725. * @retval 0 -> Success
  726. * @retval -1 -> Error
  727. *
  728. *
  729. */
  730. BMI160_RETURN_FUNCTION_TYPE bmi160_read_mag_z(s16 *v_mag_z_s16,
  731. u8 v_sensor_select_u8)
  732. {
  733. /* variable used for return the status of communication result*/
  734. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  735. /* Array contains the mag Z lSB and MSB data
  736. v_data_u8[0] - LSB
  737. v_data_u8[1] - MSB*/
  738. u8 v_data_u8[ARRAY_SIZE_TWO] = {C_BMI160_ZERO_U8X,
  739. C_BMI160_ZERO_U8X};
  740. /* check the p_bmi160 structure as NULL*/
  741. if (p_bmi160 == BMI160_NULL) {
  742. return E_BMI160_NULL_PTR;
  743. } else {
  744. switch (v_sensor_select_u8) {
  745. case BST_BMM:
  746. com_rslt =
  747. p_bmi160->BMI160_BUS_READ_FUNC(
  748. p_bmi160->dev_addr,
  749. BMI160_USER_DATA_MAG_Z_LSB__REG,
  750. v_data_u8, C_BMI160_TWO_U8X);
  751. /*Z-axis lsb value shifting*/
  752. v_data_u8[LSB_ZERO] =
  753. BMI160_GET_BITSLICE(v_data_u8[LSB_ZERO],
  754. BMI160_USER_DATA_MAG_Z_LSB);
  755. *v_mag_z_s16 = (s16)
  756. ((((s32)((s8)v_data_u8[MSB_ONE]))
  757. << BMI160_SHIFT_7_POSITION) |
  758. (v_data_u8[LSB_ZERO]));
  759. break;
  760. case BST_AKM:
  761. com_rslt =
  762. p_bmi160->BMI160_BUS_READ_FUNC(
  763. p_bmi160->dev_addr,
  764. BMI160_USER_DATA_4_MAG_Z_LSB__REG,
  765. v_data_u8, C_BMI160_TWO_U8X);
  766. *v_mag_z_s16 = (s16)
  767. ((((s32)((s8)v_data_u8[MSB_ONE]))
  768. << BMI160_SHIFT_8_POSITION) | (
  769. v_data_u8[LSB_ZERO]));
  770. break;
  771. default:
  772. com_rslt = E_BMI160_OUT_OF_RANGE;
  773. break;
  774. }
  775. }
  776. return com_rslt;
  777. }
  778. /*!
  779. * @brief This API reads magnetometer data RHALL values
  780. * from the register 0x0A and 0x0B
  781. *
  782. *
  783. * @param v_mag_r_s16 : The value of BMM150 r data
  784. *
  785. *
  786. *
  787. * @return results of bus communication function
  788. * @retval 0 -> Success
  789. * @retval -1 -> Error
  790. *
  791. *
  792. */
  793. BMI160_RETURN_FUNCTION_TYPE bmi160_read_mag_r(s16 *v_mag_r_s16)
  794. {
  795. /* variable used for return the status of communication result*/
  796. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  797. /* Array contains the mag R lSB and MSB data
  798. v_data_u8[0] - LSB
  799. v_data_u8[1] - MSB*/
  800. u8 v_data_u8[ARRAY_SIZE_TWO] = {C_BMI160_ZERO_U8X,
  801. C_BMI160_ZERO_U8X};
  802. /* check the p_bmi160 structure as NULL*/
  803. if (p_bmi160 == BMI160_NULL) {
  804. return E_BMI160_NULL_PTR;
  805. } else {
  806. com_rslt =
  807. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  808. BMI160_USER_DATA_6_RHALL_LSB__REG,
  809. v_data_u8, C_BMI160_TWO_U8X);
  810. /*R-axis lsb value shifting*/
  811. v_data_u8[LSB_ZERO] =
  812. BMI160_GET_BITSLICE(v_data_u8[LSB_ZERO],
  813. BMI160_USER_DATA_MAG_R_LSB);
  814. *v_mag_r_s16 = (s16)
  815. ((((s32)((s8)v_data_u8[MSB_ONE]))
  816. << BMI160_SHIFT_6_POSITION) |
  817. (v_data_u8[LSB_ZERO]));
  818. }
  819. return com_rslt;
  820. }
  821. /*!
  822. * @brief This API reads magnetometer data X,Y,Z values
  823. * from the register 0x04 to 0x09
  824. *
  825. * @brief The mag sensor data read form auxiliary mag
  826. *
  827. * @param mag : The value of mag xyz data
  828. * @param v_sensor_select_u8 : Mag selection value
  829. * value | sensor
  830. * ---------|----------------
  831. * 0 | BMM150
  832. * 1 | AKM09911
  833. *
  834. * @note For mag data output rate configuration use the following function
  835. * @note bmi160_set_mag_output_data_rate()
  836. *
  837. * @return results of bus communication function
  838. * @retval 0 -> Success
  839. * @retval -1 -> Error *
  840. *
  841. */
  842. BMI160_RETURN_FUNCTION_TYPE bmi160_read_mag_xyz(
  843. struct bmi160_mag_t *mag, u8 v_sensor_select_u8)
  844. {
  845. /* variable used for return the status of communication result*/
  846. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  847. /* Array contains the mag XYZ lSB and MSB data
  848. v_data_u8[0] - X-LSB
  849. v_data_u8[1] - X-MSB
  850. v_data_u8[0] - Y-LSB
  851. v_data_u8[1] - Y-MSB
  852. v_data_u8[0] - Z-LSB
  853. v_data_u8[1] - Z-MSB
  854. */
  855. u8 v_data_u8[ARRAY_SIZE_SIX] = {
  856. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X,
  857. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X,
  858. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X};
  859. /* check the p_bmi160 structure as NULL*/
  860. if (p_bmi160 == BMI160_NULL) {
  861. return E_BMI160_NULL_PTR;
  862. } else {
  863. switch (v_sensor_select_u8) {
  864. case BST_BMM:
  865. com_rslt =
  866. p_bmi160->BMI160_BUS_READ_FUNC(
  867. p_bmi160->dev_addr,
  868. BMI160_USER_DATA_MAG_X_LSB__REG,
  869. v_data_u8, C_BMI160_SIX_U8X);
  870. /*X-axis lsb value shifting*/
  871. v_data_u8[LSB_ZERO] = BMI160_GET_BITSLICE(
  872. v_data_u8[LSB_ZERO],
  873. BMI160_USER_DATA_MAG_X_LSB);
  874. /* Data X */
  875. mag->x = (s16)
  876. ((((s32)((s8)v_data_u8[MSB_ONE]))
  877. << BMI160_SHIFT_5_POSITION) |
  878. (v_data_u8[LSB_ZERO]));
  879. /* Data Y */
  880. /*Y-axis lsb value shifting*/
  881. v_data_u8[LSB_TWO] = BMI160_GET_BITSLICE(
  882. v_data_u8[LSB_TWO],
  883. BMI160_USER_DATA_MAG_Y_LSB);
  884. mag->y = (s16)
  885. ((((s32)((s8)v_data_u8[MSB_THREE]))
  886. << BMI160_SHIFT_5_POSITION) |
  887. (v_data_u8[LSB_TWO]));
  888. /* Data Z */
  889. /*Z-axis lsb value shifting*/
  890. v_data_u8[LSB_FOUR] = BMI160_GET_BITSLICE(
  891. v_data_u8[LSB_FOUR],
  892. BMI160_USER_DATA_MAG_Z_LSB);
  893. mag->z = (s16)
  894. ((((s32)((s8)v_data_u8[MSB_FIVE]))
  895. << BMI160_SHIFT_7_POSITION) |
  896. (v_data_u8[LSB_FOUR]));
  897. break;
  898. case BST_AKM:
  899. com_rslt =
  900. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  901. BMI160_USER_DATA_0_MAG_X_LSB__REG,
  902. v_data_u8, C_BMI160_SIX_U8X);
  903. /* Data X */
  904. mag->x = (s16)
  905. ((((s32)((s8)v_data_u8[MSB_ONE]))
  906. << BMI160_SHIFT_8_POSITION) |
  907. (v_data_u8[LSB_ZERO]));
  908. /* Data Y */
  909. mag->y = ((((s32)((s8)v_data_u8[MSB_THREE]))
  910. << BMI160_SHIFT_8_POSITION) |
  911. (v_data_u8[LSB_TWO]));
  912. /* Data Z */
  913. mag->z = (s16)
  914. ((((s32)((s8)v_data_u8[MSB_FIVE]))
  915. << BMI160_SHIFT_8_POSITION) |
  916. (v_data_u8[LSB_FOUR]));
  917. break;
  918. default:
  919. com_rslt = E_BMI160_OUT_OF_RANGE;
  920. break;
  921. }
  922. }
  923. return com_rslt;
  924. }
  925. /*!*
  926. * @brief This API reads magnetometer data X,Y,Z,r
  927. * values from the register 0x04 to 0x0B
  928. *
  929. * @brief The mag sensor data read form auxiliary mag
  930. *
  931. * @param mag : The value of mag-BMM150 xyzr data
  932. *
  933. * @note For mag data output rate configuration use the following function
  934. * @note bmi160_set_mag_output_data_rate()
  935. *
  936. * @return results of bus communication function
  937. * @retval 0 -> Success
  938. * @retval -1 -> Error
  939. *
  940. *
  941. */
  942. BMI160_RETURN_FUNCTION_TYPE bmi160_read_mag_xyzr(
  943. struct bmi160_mag_xyzr_t *mag)
  944. {
  945. /* variable used for return the status of communication result*/
  946. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  947. u8 v_data_u8[ARRAY_SIZE_EIGHT] = {
  948. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X,
  949. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X,
  950. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X};
  951. /* check the p_bmi160 structure as NULL*/
  952. if (p_bmi160 == BMI160_NULL) {
  953. return E_BMI160_NULL_PTR;
  954. } else {
  955. com_rslt =
  956. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  957. BMI160_USER_DATA_MAG_X_LSB__REG,
  958. v_data_u8, C_BMI160_EIGHT_U8X);
  959. /* Data X */
  960. /*X-axis lsb value shifting*/
  961. v_data_u8[LSB_ZERO] = BMI160_GET_BITSLICE(
  962. v_data_u8[LSB_ZERO],
  963. BMI160_USER_DATA_MAG_X_LSB);
  964. mag->x = (s16)
  965. ((((s32)((s8)v_data_u8[MSB_ONE]))
  966. << BMI160_SHIFT_5_POSITION) | (v_data_u8[LSB_ZERO]));
  967. /* Data Y */
  968. /*Y-axis lsb value shifting*/
  969. v_data_u8[LSB_TWO] = BMI160_GET_BITSLICE(
  970. v_data_u8[LSB_TWO],
  971. BMI160_USER_DATA_MAG_Y_LSB);
  972. mag->y = (s16)
  973. ((((s32)((s8)v_data_u8[MSB_THREE]))
  974. << BMI160_SHIFT_5_POSITION) | (v_data_u8[LSB_TWO]));
  975. /* Data Z */
  976. /*Z-axis lsb value shifting*/
  977. v_data_u8[LSB_FOUR] = BMI160_GET_BITSLICE(
  978. v_data_u8[LSB_FOUR],
  979. BMI160_USER_DATA_MAG_Z_LSB);
  980. mag->z = (s16)
  981. ((((s32)((s8)v_data_u8[MSB_FIVE]))
  982. << BMI160_SHIFT_7_POSITION) | (v_data_u8[LSB_FOUR]));
  983. /* RHall */
  984. /*R-axis lsb value shifting*/
  985. v_data_u8[LSB_SIX] = BMI160_GET_BITSLICE(
  986. v_data_u8[LSB_SIX],
  987. BMI160_USER_DATA_MAG_R_LSB);
  988. mag->r = (s16)
  989. ((((s32)((s8)v_data_u8[MSB_SEVEN]))
  990. << BMI160_SHIFT_6_POSITION) | (v_data_u8[LSB_SIX]));
  991. }
  992. return com_rslt;
  993. }
  994. /*!
  995. * @brief This API reads gyro data X values
  996. * form the register 0x0C and 0x0D
  997. *
  998. *
  999. *
  1000. *
  1001. * @param v_gyro_x_s16 : The value of gyro x data
  1002. *
  1003. * @note Gyro Configuration use the following function
  1004. * @note bmi160_set_gyro_output_data_rate()
  1005. * @note bmi160_set_gyro_bw()
  1006. * @note bmi160_set_gyro_range()
  1007. *
  1008. * @return results of bus communication function
  1009. * @retval 0 -> Success
  1010. * @retval -1 -> Error
  1011. *
  1012. */
  1013. BMI160_RETURN_FUNCTION_TYPE bmi160_read_gyro_x(s16 *v_gyro_x_s16)
  1014. {
  1015. /* variable used for return the status of communication result*/
  1016. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1017. /* Array contains the gyro X lSB and MSB data
  1018. v_data_u8[0] - LSB
  1019. v_data_u8[MSB_ONE] - MSB*/
  1020. u8 v_data_u8[ARRAY_SIZE_TWO] = {C_BMI160_ZERO_U8X,
  1021. C_BMI160_ZERO_U8X};
  1022. /* check the p_bmi160 structure as NULL*/
  1023. if (p_bmi160 == BMI160_NULL) {
  1024. return E_BMI160_NULL_PTR;
  1025. } else {
  1026. com_rslt =
  1027. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1028. BMI160_USER_DATA_8_GYRO_X_LSB__REG,
  1029. v_data_u8, C_BMI160_TWO_U8X);
  1030. *v_gyro_x_s16 = (s16)
  1031. ((((s32)((s8)v_data_u8[MSB_ONE]))
  1032. << BMI160_SHIFT_8_POSITION) | (v_data_u8[LSB_ZERO]));
  1033. }
  1034. return com_rslt;
  1035. }
  1036. /*!
  1037. * @brief This API reads gyro data Y values
  1038. * form the register 0x0E and 0x0F
  1039. *
  1040. *
  1041. *
  1042. *
  1043. * @param v_gyro_y_s16 : The value of gyro y data
  1044. *
  1045. * @note Gyro Configuration use the following function
  1046. * @note bmi160_set_gyro_output_data_rate()
  1047. * @note bmi160_set_gyro_bw()
  1048. * @note bmi160_set_gyro_range()
  1049. *
  1050. * @return results of bus communication function
  1051. * @retval 0 -> Success
  1052. * @retval -1 -> Error result of communication routines
  1053. *
  1054. *
  1055. */
  1056. BMI160_RETURN_FUNCTION_TYPE bmi160_read_gyro_y(s16 *v_gyro_y_s16)
  1057. {
  1058. /* variable used for return the status of communication result*/
  1059. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1060. /* Array contains the gyro Y lSB and MSB data
  1061. v_data_u8[LSB_ZERO] - LSB
  1062. v_data_u8[MSB_ONE] - MSB*/
  1063. u8 v_data_u8[ARRAY_SIZE_TWO] = {C_BMI160_ZERO_U8X,
  1064. C_BMI160_ZERO_U8X};
  1065. /* check the p_bmi160 structure as NULL*/
  1066. if (p_bmi160 == BMI160_NULL) {
  1067. return E_BMI160_NULL_PTR;
  1068. } else {
  1069. /* read gyro y data*/
  1070. com_rslt =
  1071. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1072. BMI160_USER_DATA_10_GYRO_Y_LSB__REG,
  1073. v_data_u8, C_BMI160_TWO_U8X);
  1074. *v_gyro_y_s16 = (s16)
  1075. ((((s32)((s8)v_data_u8[MSB_ONE]))
  1076. << BMI160_SHIFT_8_POSITION) | (v_data_u8[LSB_ZERO]));
  1077. }
  1078. return com_rslt;
  1079. }
  1080. /*!
  1081. * @brief This API reads gyro data Z values
  1082. * form the register 0x10 and 0x11
  1083. *
  1084. *
  1085. *
  1086. *
  1087. * @param v_gyro_z_s16 : The value of gyro z data
  1088. *
  1089. * @note Gyro Configuration use the following function
  1090. * @note bmi160_set_gyro_output_data_rate()
  1091. * @note bmi160_set_gyro_bw()
  1092. * @note bmi160_set_gyro_range()
  1093. *
  1094. * @return results of bus communication function
  1095. * @retval 0 -> Success
  1096. * @retval -1 -> Error
  1097. *
  1098. *
  1099. */
  1100. BMI160_RETURN_FUNCTION_TYPE bmi160_read_gyro_z(s16 *v_gyro_z_s16)
  1101. {
  1102. /* variable used for return the status of communication result*/
  1103. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1104. /* Array contains the gyro Z lSB and MSB data
  1105. v_data_u8[LSB_ZERO] - LSB
  1106. v_data_u8[MSB_ONE] - MSB*/
  1107. u8 v_data_u8[ARRAY_SIZE_TWO] = {C_BMI160_ZERO_U8X,
  1108. C_BMI160_ZERO_U8X};
  1109. /* check the p_bmi160 structure as NULL*/
  1110. if (p_bmi160 == BMI160_NULL) {
  1111. return E_BMI160_NULL_PTR;
  1112. } else {
  1113. /* read gyro z data */
  1114. com_rslt =
  1115. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1116. BMI160_USER_DATA_12_GYRO_Z_LSB__REG,
  1117. v_data_u8, C_BMI160_TWO_U8X);
  1118. *v_gyro_z_s16 = (s16)
  1119. ((((s32)((s8)v_data_u8[MSB_ONE]))
  1120. << BMI160_SHIFT_8_POSITION) | (v_data_u8[LSB_ZERO]));
  1121. }
  1122. return com_rslt;
  1123. }
  1124. /*!
  1125. * @brief This API reads gyro data X,Y,Z values
  1126. * from the register 0x0C to 0x11
  1127. *
  1128. *
  1129. *
  1130. *
  1131. * @param gyro : The value of gyro xyz
  1132. *
  1133. * @note Gyro Configuration use the following function
  1134. * @note bmi160_set_gyro_output_data_rate()
  1135. * @note bmi160_set_gyro_bw()
  1136. * @note bmi160_set_gyro_range()
  1137. *
  1138. * @return results of bus communication function
  1139. * @retval 0 -> Success
  1140. * @retval -1 -> Error
  1141. *
  1142. *
  1143. */
  1144. BMI160_RETURN_FUNCTION_TYPE bmi160_read_gyro_xyz(struct bmi160_gyro_t *gyro)
  1145. {
  1146. /* variable used for return the status of communication result*/
  1147. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1148. /* Array contains the mag XYZ lSB and MSB data
  1149. v_data_u8[0] - X-LSB
  1150. v_data_u8[1] - X-MSB
  1151. v_data_u8[0] - Y-LSB
  1152. v_data_u8[1] - Y-MSB
  1153. v_data_u8[0] - Z-LSB
  1154. v_data_u8[1] - Z-MSB
  1155. */
  1156. u8 v_data_u8[ARRAY_SIZE_SIX] = {C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X,
  1157. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X,
  1158. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X};
  1159. /* check the p_bmi160 structure as NULL*/
  1160. if (p_bmi160 == BMI160_NULL) {
  1161. return E_BMI160_NULL_PTR;
  1162. } else {
  1163. /* read the gyro xyz data*/
  1164. com_rslt =
  1165. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1166. BMI160_USER_DATA_8_GYRO_X_LSB__REG,
  1167. v_data_u8, C_BMI160_SIX_U8X);
  1168. /* Data X */
  1169. gyro->x = (s16)
  1170. ((((s32)((s8)v_data_u8[MSB_ONE]))
  1171. << BMI160_SHIFT_8_POSITION) | (v_data_u8[LSB_ZERO]));
  1172. /* Data Y */
  1173. gyro->y = (s16)
  1174. ((((s32)((s8)v_data_u8[MSB_THREE]))
  1175. << BMI160_SHIFT_8_POSITION) | (v_data_u8[LSB_TWO]));
  1176. /* Data Z */
  1177. gyro->z = (s16)
  1178. ((((s32)((s8)v_data_u8[MSB_FIVE]))
  1179. << BMI160_SHIFT_8_POSITION) | (v_data_u8[LSB_FOUR]));
  1180. }
  1181. return com_rslt;
  1182. }
  1183. /*!
  1184. * @brief This API reads accelerometer data X values
  1185. * form the register 0x12 and 0x13
  1186. *
  1187. *
  1188. *
  1189. *
  1190. * @param v_accel_x_s16 : The value of accel x
  1191. *
  1192. * @note For accel configuration use the following functions
  1193. * @note bmi160_set_accel_output_data_rate()
  1194. * @note bmi160_set_accel_bw()
  1195. * @note bmi160_set_accel_under_sampling_parameter()
  1196. * @note bmi160_set_accel_range()
  1197. *
  1198. * @return results of bus communication function
  1199. * @retval 0 -> Success
  1200. * @retval -1 -> Error
  1201. *
  1202. *
  1203. */
  1204. BMI160_RETURN_FUNCTION_TYPE bmi160_read_accel_x(s16 *v_accel_x_s16)
  1205. {
  1206. /* variable used for return the status of communication result*/
  1207. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1208. /* Array contains the accel X lSB and MSB data
  1209. v_data_u8[0] - LSB
  1210. v_data_u8[1] - MSB*/
  1211. u8 v_data_u8[ARRAY_SIZE_TWO] = {C_BMI160_ZERO_U8X,
  1212. C_BMI160_ZERO_U8X};
  1213. /* check the p_bmi160 structure as NULL*/
  1214. if (p_bmi160 == BMI160_NULL) {
  1215. return E_BMI160_NULL_PTR;
  1216. } else {
  1217. com_rslt =
  1218. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1219. BMI160_USER_DATA_14_ACCEL_X_LSB__REG,
  1220. v_data_u8, C_BMI160_TWO_U8X);
  1221. *v_accel_x_s16 = (s16)
  1222. ((((s32)((s8)v_data_u8[MSB_ONE]))
  1223. << BMI160_SHIFT_8_POSITION) | (v_data_u8[LSB_ZERO]));
  1224. }
  1225. return com_rslt;
  1226. }
  1227. /*!
  1228. * @brief This API reads accelerometer data Y values
  1229. * form the register 0x14 and 0x15
  1230. *
  1231. *
  1232. *
  1233. *
  1234. * @param v_accel_y_s16 : The value of accel y
  1235. *
  1236. * @note For accel configuration use the following functions
  1237. * @note bmi160_set_accel_output_data_rate()
  1238. * @note bmi160_set_accel_bw()
  1239. * @note bmi160_set_accel_under_sampling_parameter()
  1240. * @note bmi160_set_accel_range()
  1241. *
  1242. * @return results of bus communication function
  1243. * @retval 0 -> Success
  1244. * @retval -1 -> Error
  1245. *
  1246. *
  1247. */
  1248. BMI160_RETURN_FUNCTION_TYPE bmi160_read_accel_y(s16 *v_accel_y_s16)
  1249. {
  1250. /* variable used for return the status of communication result*/
  1251. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1252. /* Array contains the accel Y lSB and MSB data
  1253. v_data_u8[0] - LSB
  1254. v_data_u8[1] - MSB*/
  1255. u8 v_data_u8[ARRAY_SIZE_TWO] = {C_BMI160_ZERO_U8X,
  1256. C_BMI160_ZERO_U8X};
  1257. /* check the p_bmi160 structure as NULL*/
  1258. if (p_bmi160 == BMI160_NULL) {
  1259. return E_BMI160_NULL_PTR;
  1260. } else {
  1261. com_rslt =
  1262. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1263. BMI160_USER_DATA_16_ACCEL_Y_LSB__REG,
  1264. v_data_u8, C_BMI160_TWO_U8X);
  1265. *v_accel_y_s16 = (s16)
  1266. ((((s32)((s8)v_data_u8[MSB_ONE]))
  1267. << BMI160_SHIFT_8_POSITION) | (v_data_u8[LSB_ZERO]));
  1268. }
  1269. return com_rslt;
  1270. }
  1271. /*!
  1272. * @brief This API reads accelerometer data Z values
  1273. * form the register 0x16 and 0x17
  1274. *
  1275. *
  1276. *
  1277. *
  1278. * @param v_accel_z_s16 : The value of accel z
  1279. *
  1280. * @note For accel configuration use the following functions
  1281. * @note bmi160_set_accel_output_data_rate()
  1282. * @note bmi160_set_accel_bw()
  1283. * @note bmi160_set_accel_under_sampling_parameter()
  1284. * @note bmi160_set_accel_range()
  1285. *
  1286. * @return results of bus communication function
  1287. * @retval 0 -> Success
  1288. * @retval -1 -> Error
  1289. *
  1290. *
  1291. */
  1292. BMI160_RETURN_FUNCTION_TYPE bmi160_read_accel_z(s16 *v_accel_z_s16)
  1293. {
  1294. /* variable used for return the status of communication result*/
  1295. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1296. /* Array contains the accel Z lSB and MSB data
  1297. a_data_u8r[LSB_ZERO] - LSB
  1298. a_data_u8r[MSB_ONE] - MSB*/
  1299. u8 a_data_u8r[ARRAY_SIZE_TWO] = {C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X};
  1300. /* check the p_bmi160 structure as NULL*/
  1301. if (p_bmi160 == BMI160_NULL) {
  1302. return E_BMI160_NULL_PTR;
  1303. } else {
  1304. com_rslt =
  1305. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1306. BMI160_USER_DATA_18_ACCEL_Z_LSB__REG,
  1307. a_data_u8r, C_BMI160_TWO_U8X);
  1308. *v_accel_z_s16 = (s16)
  1309. ((((s32)((s8)a_data_u8r[MSB_ONE]))
  1310. << BMI160_SHIFT_8_POSITION) | (a_data_u8r[LSB_ZERO]));
  1311. }
  1312. return com_rslt;
  1313. }
  1314. /*!
  1315. * @brief This API reads accelerometer data X,Y,Z values
  1316. * from the register 0x12 to 0x17
  1317. *
  1318. *
  1319. *
  1320. *
  1321. * @param accel :The value of accel xyz
  1322. *
  1323. * @note For accel configuration use the following functions
  1324. * @note bmi160_set_accel_output_data_rate()
  1325. * @note bmi160_set_accel_bw()
  1326. * @note bmi160_set_accel_under_sampling_parameter()
  1327. * @note bmi160_set_accel_range()
  1328. *
  1329. * @return results of bus communication function
  1330. * @retval 0 -> Success
  1331. * @retval -1 -> Error
  1332. *
  1333. *
  1334. */
  1335. BMI160_RETURN_FUNCTION_TYPE bmi160_read_accel_xyz(
  1336. struct bmi160_accel_t *accel)
  1337. {
  1338. /* variable used for return the status of communication result*/
  1339. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1340. /* Array contains the accel XYZ lSB and MSB data
  1341. a_data_u8r[0] - X-LSB
  1342. a_data_u8r[1] - X-MSB
  1343. a_data_u8r[0] - Y-LSB
  1344. a_data_u8r[1] - Y-MSB
  1345. a_data_u8r[0] - Z-LSB
  1346. a_data_u8r[1] - Z-MSB
  1347. */
  1348. u8 a_data_u8r[ARRAY_SIZE_SIX] = {C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X,
  1349. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X,
  1350. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X};
  1351. /* check the p_bmi160 structure as NULL*/
  1352. if (p_bmi160 == BMI160_NULL) {
  1353. return E_BMI160_NULL_PTR;
  1354. } else {
  1355. com_rslt =
  1356. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1357. BMI160_USER_DATA_14_ACCEL_X_LSB__REG,
  1358. a_data_u8r, C_BMI160_SIX_U8X);
  1359. /* Data X */
  1360. accel->x = (s16)
  1361. ((((s32)((s8)a_data_u8r[MSB_ONE]))
  1362. << BMI160_SHIFT_8_POSITION) | (a_data_u8r[LSB_ZERO]));
  1363. /* Data Y */
  1364. accel->y = (s16)
  1365. ((((s32)((s8)a_data_u8r[MSB_THREE]))
  1366. << BMI160_SHIFT_8_POSITION) | (a_data_u8r[LSB_TWO]));
  1367. /* Data Z */
  1368. accel->z = (s16)
  1369. ((((s32)((s8)a_data_u8r[MSB_FIVE]))
  1370. << BMI160_SHIFT_8_POSITION) | (a_data_u8r[LSB_FOUR]));
  1371. }
  1372. return com_rslt;
  1373. }
  1374. /*!
  1375. * @brief This API reads sensor_time from the register
  1376. * 0x18 to 0x1A
  1377. *
  1378. *
  1379. * @param v_sensor_time_u32 : The value of sensor time
  1380. *
  1381. *
  1382. *
  1383. * @return results of bus communication function
  1384. * @retval 0 -> Success
  1385. * @retval -1 -> Error
  1386. *
  1387. *
  1388. */
  1389. BMI160_RETURN_FUNCTION_TYPE bmi160_get_sensor_time(u32 *v_sensor_time_u32)
  1390. {
  1391. /* variable used for return the status of communication result*/
  1392. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1393. /* Array contains the sensor time it is 32 bit data
  1394. a_data_u8r[0] - sensor time
  1395. a_data_u8r[1] - sensor time
  1396. a_data_u8r[0] - sensor time
  1397. */
  1398. u8 a_data_u8r[ARRAY_SIZE_THREE] = {C_BMI160_ZERO_U8X,
  1399. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X};
  1400. /* check the p_bmi160 structure as NULL*/
  1401. if (p_bmi160 == BMI160_NULL) {
  1402. return E_BMI160_NULL_PTR;
  1403. } else {
  1404. com_rslt =
  1405. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1406. BMI160_USER_SENSORTIME_0_SENSOR_TIME_LSB__REG,
  1407. a_data_u8r, C_BMI160_THREE_U8X);
  1408. *v_sensor_time_u32 = (u32)
  1409. ((((u32)a_data_u8r[C_BMI160_TWO_U8X])
  1410. << BMI160_SHIFT_16_POSITION)
  1411. |(((u32)a_data_u8r[C_BMI160_ONE_U8X])
  1412. << BMI160_SHIFT_8_POSITION)
  1413. | (a_data_u8r[C_BMI160_ZERO_U8X]));
  1414. }
  1415. return com_rslt;
  1416. }
  1417. /*!
  1418. * @brief This API reads the Gyroscope self test
  1419. * status from the register 0x1B bit 1
  1420. *
  1421. *
  1422. * @param v_gyro_selftest_u8 : The value of gyro self test status
  1423. * value | status
  1424. * ---------|----------------
  1425. * 0 | Gyroscope self test is running or failed
  1426. * 1 | Gyroscope self test completed successfully
  1427. *
  1428. *
  1429. * @return results of bus communication function
  1430. * @retval 0 -> Success
  1431. * @retval -1 -> Error
  1432. *
  1433. *
  1434. */
  1435. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_selftest(u8
  1436. *v_gyro_selftest_u8)
  1437. {
  1438. /* variable used for return the status of communication result*/
  1439. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1440. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  1441. /* check the p_bmi160 structure as NULL*/
  1442. if (p_bmi160 == BMI160_NULL) {
  1443. return E_BMI160_NULL_PTR;
  1444. } else {
  1445. com_rslt =
  1446. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1447. BMI160_USER_STAT_GYRO_SELFTEST_OK__REG,
  1448. &v_data_u8, C_BMI160_ONE_U8X);
  1449. *v_gyro_selftest_u8 = BMI160_GET_BITSLICE(v_data_u8,
  1450. BMI160_USER_STAT_GYRO_SELFTEST_OK);
  1451. }
  1452. return com_rslt;
  1453. }
  1454. /*!
  1455. * @brief This API reads the status of
  1456. * mag manual interface operation form the register 0x1B bit 2
  1457. *
  1458. *
  1459. *
  1460. * @param v_mag_manual_stat_u8 : The value of mag manual operation status
  1461. * value | status
  1462. * ---------|----------------
  1463. * 0 | Indicates no manual magnetometer
  1464. * - | interface operation is ongoing
  1465. * 1 | Indicates manual magnetometer
  1466. * - | interface operation is ongoing
  1467. *
  1468. * @return results of bus communication function
  1469. * @retval 0 -> Success
  1470. * @retval -1 -> Error
  1471. *
  1472. *
  1473. */
  1474. BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_manual_operation_stat(u8
  1475. *v_mag_manual_stat_u8)
  1476. {
  1477. /* variable used for return the status of communication result*/
  1478. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1479. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  1480. /* check the p_bmi160 structure as NULL*/
  1481. if (p_bmi160 == BMI160_NULL) {
  1482. return E_BMI160_NULL_PTR;
  1483. } else {
  1484. /* read manual operation*/
  1485. com_rslt =
  1486. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1487. BMI160_USER_STAT_MAG_MANUAL_OPERATION__REG,
  1488. &v_data_u8, C_BMI160_ONE_U8X);
  1489. *v_mag_manual_stat_u8 = BMI160_GET_BITSLICE(v_data_u8,
  1490. BMI160_USER_STAT_MAG_MANUAL_OPERATION);
  1491. }
  1492. return com_rslt;
  1493. }
  1494. /*!
  1495. * @brief This API reads the fast offset compensation
  1496. * status form the register 0x1B bit 3
  1497. *
  1498. *
  1499. * @param v_foc_rdy_u8 : The status of fast compensation
  1500. *
  1501. *
  1502. *
  1503. * @return results of bus communication function
  1504. * @retval 0 -> Success
  1505. * @retval -1 -> Error
  1506. *
  1507. *
  1508. */
  1509. BMI160_RETURN_FUNCTION_TYPE bmi160_get_foc_rdy(u8
  1510. *v_foc_rdy_u8)
  1511. {
  1512. /* variable used for return the status of communication result*/
  1513. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1514. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  1515. /* check the p_bmi160 structure as NULL*/
  1516. if (p_bmi160 == BMI160_NULL) {
  1517. return E_BMI160_NULL_PTR;
  1518. } else {
  1519. /* read the FOC status*/
  1520. com_rslt =
  1521. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1522. BMI160_USER_STAT_FOC_RDY__REG,
  1523. &v_data_u8, C_BMI160_ONE_U8X);
  1524. *v_foc_rdy_u8 = BMI160_GET_BITSLICE(v_data_u8,
  1525. BMI160_USER_STAT_FOC_RDY);
  1526. }
  1527. return com_rslt;
  1528. }
  1529. /*!
  1530. * @brief This API Reads the nvm_rdy status from the
  1531. * resister 0x1B bit 4
  1532. *
  1533. *
  1534. * @param v_nvm_rdy_u8 : The value of NVM ready status
  1535. * value | status
  1536. * ---------|----------------
  1537. * 0 | NVM write operation in progress
  1538. * 1 | NVM is ready to accept a new write trigger
  1539. *
  1540. *
  1541. * @return results of bus communication function
  1542. * @retval 0 -> Success
  1543. * @retval -1 -> Error
  1544. *
  1545. *
  1546. */
  1547. BMI160_RETURN_FUNCTION_TYPE bmi160_get_nvm_rdy(u8
  1548. *v_nvm_rdy_u8)
  1549. {
  1550. /* variable used for return the status of communication result*/
  1551. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1552. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  1553. /* check the p_bmi160 structure as NULL*/
  1554. if (p_bmi160 == BMI160_NULL) {
  1555. return E_BMI160_NULL_PTR;
  1556. } else {
  1557. /* read the nvm ready status*/
  1558. com_rslt =
  1559. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1560. BMI160_USER_STAT_NVM_RDY__REG,
  1561. &v_data_u8, C_BMI160_ONE_U8X);
  1562. *v_nvm_rdy_u8 = BMI160_GET_BITSLICE(v_data_u8,
  1563. BMI160_USER_STAT_NVM_RDY);
  1564. }
  1565. return com_rslt;
  1566. }
  1567. /*!
  1568. * @brief This API reads the status of mag data ready
  1569. * from the register 0x1B bit 5
  1570. * The status get reset when one mag data register is read out
  1571. *
  1572. * @param v_data_rdy_u8 : The value of mag data ready status
  1573. *
  1574. *
  1575. *
  1576. * @return results of bus communication function
  1577. * @retval 0 -> Success
  1578. * @retval -1 -> Error
  1579. *
  1580. *
  1581. */
  1582. BMI160_RETURN_FUNCTION_TYPE bmi160_get_data_rdy_mag(u8
  1583. *v_data_rdy_u8)
  1584. {
  1585. /* variable used for return the status of communication result*/
  1586. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1587. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  1588. /* check the p_bmi160 structure as NULL*/
  1589. if (p_bmi160 == BMI160_NULL) {
  1590. return E_BMI160_NULL_PTR;
  1591. } else {
  1592. com_rslt =
  1593. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1594. BMI160_USER_STAT_DATA_RDY_MAG__REG, &v_data_u8,
  1595. C_BMI160_ONE_U8X);
  1596. *v_data_rdy_u8 = BMI160_GET_BITSLICE(v_data_u8,
  1597. BMI160_USER_STAT_DATA_RDY_MAG);
  1598. }
  1599. return com_rslt;
  1600. }
  1601. /*!
  1602. * @brief This API reads the status of gyro data ready form the
  1603. * register 0x1B bit 6
  1604. * The status get reset when gyro data register read out
  1605. *
  1606. *
  1607. * @param v_data_rdy_u8 : The value of gyro data ready
  1608. *
  1609. *
  1610. *
  1611. * @return results of bus communication function
  1612. * @retval 0 -> Success
  1613. * @retval -1 -> Error
  1614. *
  1615. *
  1616. */
  1617. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_data_rdy(u8
  1618. *v_data_rdy_u8)
  1619. {
  1620. /* variable used for return the status of communication result*/
  1621. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1622. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  1623. /* check the p_bmi160 structure as NULL*/
  1624. if (p_bmi160 == BMI160_NULL) {
  1625. return E_BMI160_NULL_PTR;
  1626. } else {
  1627. com_rslt =
  1628. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1629. BMI160_USER_STAT_DATA_RDY_GYRO__REG, &v_data_u8,
  1630. C_BMI160_ONE_U8X);
  1631. *v_data_rdy_u8 = BMI160_GET_BITSLICE(v_data_u8,
  1632. BMI160_USER_STAT_DATA_RDY_GYRO);
  1633. }
  1634. return com_rslt;
  1635. }
  1636. /*!
  1637. * @brief This API reads the status of accel data ready form the
  1638. * register 0x1B bit 7
  1639. * The status get reset when accel data register read out
  1640. *
  1641. *
  1642. * @param v_data_rdy_u8 : The value of accel data ready status
  1643. *
  1644. *
  1645. *
  1646. * @return results of bus communication function
  1647. * @retval 0 -> Success
  1648. * @retval -1 -> Error
  1649. *
  1650. *
  1651. */
  1652. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_data_rdy(u8
  1653. *v_data_rdy_u8)
  1654. {
  1655. /* variable used for return the status of communication result*/
  1656. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1657. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  1658. /* check the p_bmi160 structure as NULL*/
  1659. if (p_bmi160 == BMI160_NULL) {
  1660. return E_BMI160_NULL_PTR;
  1661. } else {
  1662. /*reads the status of accel data ready*/
  1663. com_rslt =
  1664. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1665. BMI160_USER_STAT_DATA_RDY_ACCEL__REG, &v_data_u8,
  1666. C_BMI160_ONE_U8X);
  1667. *v_data_rdy_u8 = BMI160_GET_BITSLICE(v_data_u8,
  1668. BMI160_USER_STAT_DATA_RDY_ACCEL);
  1669. }
  1670. return com_rslt;
  1671. }
  1672. /*!
  1673. * @brief This API reads the step detector interrupt status
  1674. * from the register 0x1C bit 0
  1675. * flag is associated with a specific interrupt function.
  1676. * It is set when the single tab interrupt triggers. The
  1677. * setting of INT_LATCH controls if the interrupt
  1678. * signal and hence the
  1679. * respective interrupt flag will be
  1680. * permanently latched, temporarily latched
  1681. * or not latched.
  1682. *
  1683. *
  1684. *
  1685. *
  1686. * @param v_step_intr_u8 : The status of step detector interrupt
  1687. *
  1688. *
  1689. *
  1690. * @return results of bus communication function
  1691. * @retval 0 -> Success
  1692. * @retval -1 -> Error
  1693. *
  1694. *
  1695. */
  1696. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_step_intr(u8
  1697. *v_step_intr_u8)
  1698. {
  1699. /* variable used for return the status of communication result*/
  1700. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1701. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  1702. /* check the p_bmi160 structure as NULL*/
  1703. if (p_bmi160 == BMI160_NULL) {
  1704. return E_BMI160_NULL_PTR;
  1705. } else {
  1706. com_rslt =
  1707. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1708. BMI160_USER_INTR_STAT_0_STEP_INTR__REG, &v_data_u8,
  1709. C_BMI160_ONE_U8X);
  1710. *v_step_intr_u8 = BMI160_GET_BITSLICE(v_data_u8,
  1711. BMI160_USER_INTR_STAT_0_STEP_INTR);
  1712. }
  1713. return com_rslt;
  1714. }
  1715. /*!
  1716. * @brief This API reads the
  1717. * significant motion interrupt status
  1718. * from the register 0x1C bit 1
  1719. * flag is associated with a specific interrupt function.
  1720. * It is set when the single tab interrupt triggers. The
  1721. * setting of INT_LATCH controls if the interrupt
  1722. * signal and hence the
  1723. * respective interrupt flag will be
  1724. * permanently latched, temporarily latched
  1725. * or not latched.
  1726. *
  1727. *
  1728. *
  1729. *
  1730. *
  1731. * @param v_significant_intr_u8 : The status of step
  1732. * motion interrupt
  1733. *
  1734. *
  1735. *
  1736. * @return results of bus communication function
  1737. * @retval 0 -> Success
  1738. * @retval -1 -> Error
  1739. *
  1740. *
  1741. */
  1742. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_significant_intr(u8
  1743. *v_significant_intr_u8)
  1744. {
  1745. /* variable used for return the status of communication result*/
  1746. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1747. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  1748. /* check the p_bmi160 structure as NULL*/
  1749. if (p_bmi160 == BMI160_NULL) {
  1750. return E_BMI160_NULL_PTR;
  1751. } else {
  1752. com_rslt =
  1753. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1754. BMI160_USER_INTR_STAT_0_SIGNIFICANT_INTR__REG,
  1755. &v_data_u8, C_BMI160_ONE_U8X);
  1756. *v_significant_intr_u8 = BMI160_GET_BITSLICE(v_data_u8,
  1757. BMI160_USER_INTR_STAT_0_SIGNIFICANT_INTR);
  1758. }
  1759. return com_rslt;
  1760. }
  1761. /*!
  1762. * @brief This API reads the any motion interrupt status
  1763. * from the register 0x1C bit 2
  1764. * flag is associated with a specific interrupt function.
  1765. * It is set when the single tab interrupt triggers. The
  1766. * setting of INT_LATCH controls if the interrupt
  1767. * signal and hence the
  1768. * respective interrupt flag will be
  1769. * permanently latched, temporarily latched
  1770. * or not latched.
  1771. *
  1772. *
  1773. *
  1774. * @param v_any_motion_intr_u8 : The status of any-motion interrupt
  1775. *
  1776. *
  1777. *
  1778. * @return results of bus communication function
  1779. * @retval 0 -> Success
  1780. * @retval -1 -> Error
  1781. *
  1782. *
  1783. */
  1784. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_any_motion_intr(u8
  1785. *v_any_motion_intr_u8)
  1786. {
  1787. /* variable used for return the status of communication result*/
  1788. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1789. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  1790. /* check the p_bmi160 structure as NULL*/
  1791. if (p_bmi160 == BMI160_NULL) {
  1792. return E_BMI160_NULL_PTR;
  1793. } else {
  1794. com_rslt =
  1795. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1796. BMI160_USER_INTR_STAT_0_ANY_MOTION__REG, &v_data_u8,
  1797. C_BMI160_ONE_U8X);
  1798. *v_any_motion_intr_u8 = BMI160_GET_BITSLICE(v_data_u8,
  1799. BMI160_USER_INTR_STAT_0_ANY_MOTION);
  1800. }
  1801. return com_rslt;
  1802. }
  1803. /*!
  1804. * @brief This API reads the power mode trigger interrupt status
  1805. * from the register 0x1C bit 3
  1806. * flag is associated with a specific interrupt function.
  1807. * It is set when the single tab interrupt triggers. The
  1808. * setting of INT_LATCH controls if the interrupt
  1809. * signal and hence the
  1810. * respective interrupt flag will be
  1811. * permanently latched, temporarily latched
  1812. * or not latched.
  1813. *
  1814. *
  1815. *
  1816. *
  1817. *
  1818. * @param v_pmu_trigger_intr_u8 : The status of power mode trigger interrupt
  1819. *
  1820. *
  1821. *
  1822. * @return results of bus communication function
  1823. * @retval 0 -> Success
  1824. * @retval -1 -> Error
  1825. *
  1826. *
  1827. */
  1828. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_pmu_trigger_intr(u8
  1829. *v_pmu_trigger_intr_u8)
  1830. {
  1831. /* variable used for return the status of communication result*/
  1832. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1833. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  1834. /* check the p_bmi160 structure as NULL*/
  1835. if (p_bmi160 == BMI160_NULL) {
  1836. return E_BMI160_NULL_PTR;
  1837. } else {
  1838. com_rslt =
  1839. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1840. BMI160_USER_INTR_STAT_0_PMU_TRIGGER__REG,
  1841. &v_data_u8, C_BMI160_ONE_U8X);
  1842. *v_pmu_trigger_intr_u8 = BMI160_GET_BITSLICE(v_data_u8,
  1843. BMI160_USER_INTR_STAT_0_PMU_TRIGGER);
  1844. }
  1845. return com_rslt;
  1846. }
  1847. /*!
  1848. * @brief This API reads the double tab status
  1849. * from the register 0x1C bit 4
  1850. * flag is associated with a specific interrupt function.
  1851. * It is set when the single tab interrupt triggers. The
  1852. * setting of INT_LATCH controls if the interrupt
  1853. * signal and hence the
  1854. * respective interrupt flag will be
  1855. * permanently latched, temporarily latched
  1856. * or not latched.
  1857. *
  1858. *
  1859. *
  1860. *
  1861. * @param v_double_tap_intr_u8 :The status of double tab interrupt
  1862. *
  1863. * @note Double tap interrupt can be configured by the following functions
  1864. * @note INTERRUPT MAPPING
  1865. * @note bmi160_set_intr_double_tap()
  1866. * @note AXIS MAPPING
  1867. * @note bmi160_get_stat2_tap_first_x()
  1868. * @note bmi160_get_stat2_tap_first_y()
  1869. * @note bmi160_get_stat2_tap_first_z()
  1870. * @note DURATION
  1871. * @note bmi160_set_intr_tap_durn()
  1872. * @note THRESHOLD
  1873. * @note bmi160_set_intr_tap_thres()
  1874. * @note TAP QUIET
  1875. * @note bmi160_set_intr_tap_quiet()
  1876. * @note TAP SHOCK
  1877. * @note bmi160_set_intr_tap_shock()
  1878. * @note TAP SOURCE
  1879. * @note bmi160_set_intr_tap_source()
  1880. *
  1881. * @return results of bus communication function
  1882. * @retval 0 -> Success
  1883. * @retval -1 -> Error
  1884. *
  1885. *
  1886. */
  1887. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_double_tap_intr(u8
  1888. *v_double_tap_intr_u8)
  1889. {
  1890. /* variable used for return the status of communication result*/
  1891. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1892. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  1893. /* check the p_bmi160 structure as NULL*/
  1894. if (p_bmi160 == BMI160_NULL) {
  1895. return E_BMI160_NULL_PTR;
  1896. } else {
  1897. com_rslt =
  1898. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1899. BMI160_USER_INTR_STAT_0_DOUBLE_TAP_INTR__REG,
  1900. &v_data_u8, C_BMI160_ONE_U8X);
  1901. *v_double_tap_intr_u8 = BMI160_GET_BITSLICE(v_data_u8,
  1902. BMI160_USER_INTR_STAT_0_DOUBLE_TAP_INTR);
  1903. }
  1904. return com_rslt;
  1905. }
  1906. /*!
  1907. * @brief This API reads the single tab status
  1908. * from the register 0x1C bit 5
  1909. * flag is associated with a specific interrupt function.
  1910. * It is set when the single tab interrupt triggers. The
  1911. * setting of INT_LATCH controls if the interrupt
  1912. * signal and hence the
  1913. * respective interrupt flag will be
  1914. * permanently latched, temporarily latched
  1915. * or not latched.
  1916. *
  1917. *
  1918. *
  1919. *
  1920. * @param v_single_tap_intr_u8 :The status of single tap interrupt
  1921. *
  1922. * @note Single tap interrupt can be configured by the following functions
  1923. * @note INTERRUPT MAPPING
  1924. * @note bmi160_set_intr_single_tap()
  1925. * @note AXIS MAPPING
  1926. * @note bmi160_get_stat2_tap_first_x()
  1927. * @note bmi160_get_stat2_tap_first_y()
  1928. * @note bmi160_get_stat2_tap_first_z()
  1929. * @note DURATION
  1930. * @note bmi160_set_intr_tap_durn()
  1931. * @note THRESHOLD
  1932. * @note bmi160_set_intr_tap_thres()
  1933. * @note TAP QUIET
  1934. * @note bmi160_set_intr_tap_quiet()
  1935. * @note TAP SHOCK
  1936. * @note bmi160_set_intr_tap_shock()
  1937. * @note TAP SOURCE
  1938. * @note bmi160_set_intr_tap_source()
  1939. *
  1940. * @return results of bus communication function
  1941. * @retval 0 -> Success
  1942. * @retval -1 -> Error
  1943. *
  1944. *
  1945. */
  1946. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_single_tap_intr(u8
  1947. *v_single_tap_intr_u8)
  1948. {
  1949. /* variable used for return the status of communication result*/
  1950. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  1951. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  1952. /* check the p_bmi160 structure as NULL*/
  1953. if (p_bmi160 == BMI160_NULL) {
  1954. return E_BMI160_NULL_PTR;
  1955. } else {
  1956. com_rslt =
  1957. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  1958. BMI160_USER_INTR_STAT_0_SINGLE_TAP_INTR__REG,
  1959. &v_data_u8, C_BMI160_ONE_U8X);
  1960. *v_single_tap_intr_u8 =
  1961. BMI160_GET_BITSLICE(v_data_u8,
  1962. BMI160_USER_INTR_STAT_0_SINGLE_TAP_INTR);
  1963. }
  1964. return com_rslt;
  1965. }
  1966. /*!
  1967. * @brief This API reads the orient status
  1968. * from the register 0x1C bit 6
  1969. * flag is associated with a specific interrupt function.
  1970. * It is set when the orient interrupt triggers. The
  1971. * setting of INT_LATCH controls if the
  1972. * interrupt signal and hence the
  1973. * respective interrupt flag will be
  1974. * permanently latched, temporarily latched
  1975. * or not latched.
  1976. *
  1977. *
  1978. *
  1979. *
  1980. * @param v_orient_intr_u8 : The status of orient interrupt
  1981. *
  1982. * @note For orient interrupt configuration use the following functions
  1983. * @note STATUS
  1984. * @note bmi160_get_stat0_orient_intr()
  1985. * @note AXIS MAPPING
  1986. * @note bmi160_get_stat3_orient_xy()
  1987. * @note bmi160_get_stat3_orient_z()
  1988. * @note bmi160_set_intr_orient_axes_enable()
  1989. * @note INTERRUPT MAPPING
  1990. * @note bmi160_set_intr_orient()
  1991. * @note INTERRUPT OUTPUT
  1992. * @note bmi160_set_intr_orient_ud_enable()
  1993. * @note THETA
  1994. * @note bmi160_set_intr_orient_theta()
  1995. * @note HYSTERESIS
  1996. * @note bmi160_set_intr_orient_hyst()
  1997. * @note BLOCKING
  1998. * @note bmi160_set_intr_orient_blocking()
  1999. * @note MODE
  2000. * @note bmi160_set_intr_orient_mode()
  2001. *
  2002. * @return results of bus communication function
  2003. * @retval 0 -> Success
  2004. * @retval -1 -> Error
  2005. *
  2006. *
  2007. */
  2008. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_orient_intr(u8
  2009. *v_orient_intr_u8)
  2010. {
  2011. /* variable used for return the status of communication result*/
  2012. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2013. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2014. /* check the p_bmi160 structure as NULL*/
  2015. if (p_bmi160 == BMI160_NULL) {
  2016. return E_BMI160_NULL_PTR;
  2017. } else {
  2018. com_rslt =
  2019. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2020. BMI160_USER_INTR_STAT_0_ORIENT__REG, &v_data_u8,
  2021. C_BMI160_ONE_U8X);
  2022. *v_orient_intr_u8 =
  2023. BMI160_GET_BITSLICE(v_data_u8,
  2024. BMI160_USER_INTR_STAT_0_ORIENT);
  2025. }
  2026. return com_rslt;
  2027. }
  2028. /*!
  2029. * @brief This API reads the flat interrupt status
  2030. * from the register 0x1C bit 7
  2031. * flag is associated with a specific interrupt function.
  2032. * It is set when the flat interrupt triggers. The
  2033. * setting of INT_LATCH controls if the
  2034. * interrupt signal and hence the
  2035. * respective interrupt flag will be
  2036. * permanently latched, temporarily latched
  2037. * or not latched.
  2038. *
  2039. *
  2040. *
  2041. *
  2042. * @param v_flat_intr_u8 : The status of flat interrupt
  2043. *
  2044. * @note For flat configuration use the following functions
  2045. * @note STATS
  2046. * @note bmi160_get_stat0_flat_intr()
  2047. * @note bmi160_get_stat3_flat()
  2048. * @note INTERRUPT MAPPING
  2049. * @note bmi160_set_intr_flat()
  2050. * @note THETA
  2051. * @note bmi160_set_intr_flat_theta()
  2052. * @note HOLD TIME
  2053. * @note bmi160_set_intr_flat_hold()
  2054. * @note HYSTERESIS
  2055. * @note bmi160_set_intr_flat_hyst()
  2056. *
  2057. * @return results of bus communication function
  2058. * @retval 0 -> Success
  2059. * @retval -1 -> Error
  2060. *
  2061. *
  2062. */
  2063. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat0_flat_intr(u8
  2064. *v_flat_intr_u8)
  2065. {
  2066. /* variable used for return the status of communication result*/
  2067. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2068. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2069. /* check the p_bmi160 structure as NULL*/
  2070. if (p_bmi160 == BMI160_NULL) {
  2071. return E_BMI160_NULL_PTR;
  2072. } else {
  2073. com_rslt =
  2074. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2075. BMI160_USER_INTR_STAT_0_FLAT__REG, &v_data_u8,
  2076. C_BMI160_ONE_U8X);
  2077. *v_flat_intr_u8 =
  2078. BMI160_GET_BITSLICE(v_data_u8,
  2079. BMI160_USER_INTR_STAT_0_FLAT);
  2080. }
  2081. return com_rslt;
  2082. }
  2083. /*!
  2084. * @brief This API reads the high_g interrupt status
  2085. * from the register 0x1D bit 2
  2086. * flag is associated with a specific interrupt function.
  2087. * It is set when the high g interrupt triggers. The
  2088. * setting of INT_LATCH controls if the interrupt signal and hence the
  2089. * respective interrupt flag will be permanently
  2090. * latched, temporarily latched
  2091. * or not latched.
  2092. *
  2093. *
  2094. *
  2095. *
  2096. * @param v_high_g_intr_u8 : The status of high_g interrupt
  2097. *
  2098. * @note High_g interrupt configured by following functions
  2099. * @note STATUS
  2100. * @note bmi160_get_stat1_high_g_intr()
  2101. * @note AXIS MAPPING
  2102. * @note bmi160_get_stat3_high_g_first_x()
  2103. * @note bmi160_get_stat3_high_g_first_y()
  2104. * @note bmi160_get_stat3_high_g_first_z()
  2105. * @note SIGN MAPPING
  2106. * @note bmi160_get_stat3_high_g_first_sign()
  2107. * @note INTERRUPT MAPPING
  2108. * @note bmi160_set_intr_high_g()
  2109. * @note HYSTERESIS
  2110. * @note bmi160_set_intr_high_g_hyst()
  2111. * @note DURATION
  2112. * @note bmi160_set_intr_high_g_durn()
  2113. * @note THRESHOLD
  2114. * @note bmi160_set_intr_high_g_thres()
  2115. * @note SOURCE
  2116. * @note bmi160_set_intr_low_high_source()
  2117. *
  2118. * @return results of bus communication function
  2119. * @retval 0 -> Success
  2120. * @retval -1 -> Error
  2121. *
  2122. */
  2123. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat1_high_g_intr(u8
  2124. *v_high_g_intr_u8)
  2125. {
  2126. /* variable used for return the status of communication result*/
  2127. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2128. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2129. /* check the p_bmi160 structure as NULL*/
  2130. if (p_bmi160 == BMI160_NULL) {
  2131. return E_BMI160_NULL_PTR;
  2132. } else {
  2133. com_rslt =
  2134. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2135. BMI160_USER_INTR_STAT_1_HIGH_G_INTR__REG,
  2136. &v_data_u8, C_BMI160_ONE_U8X);
  2137. *v_high_g_intr_u8 =
  2138. BMI160_GET_BITSLICE(v_data_u8,
  2139. BMI160_USER_INTR_STAT_1_HIGH_G_INTR);
  2140. }
  2141. return com_rslt;
  2142. }
  2143. /*!
  2144. * @brief This API reads the low g interrupt status
  2145. * from the register 0x1D bit 3
  2146. * flag is associated with a specific interrupt function.
  2147. * It is set when the low g interrupt triggers. The
  2148. * setting of INT_LATCH controls if the interrupt signal and hence the
  2149. * respective interrupt flag will be
  2150. * permanently latched, temporarily latched
  2151. * or not latched.
  2152. *
  2153. *
  2154. *
  2155. *
  2156. * @param v_low_g_intr_u8 : The status of low_g interrupt
  2157. *
  2158. * @note Low_g interrupt configured by following functions
  2159. * @note STATUS
  2160. * @note bmi160_get_stat1_low_g_intr()
  2161. * @note INTERRUPT MAPPING
  2162. * @note bmi160_set_intr_low_g()
  2163. * @note SOURCE
  2164. * @note bmi160_set_intr_low_high_source()
  2165. * @note DURATION
  2166. * @note bmi160_set_intr_low_g_durn()
  2167. * @note THRESHOLD
  2168. * @note bmi160_set_intr_low_g_thres()
  2169. * @note HYSTERESIS
  2170. * @note bmi160_set_intr_low_g_hyst()
  2171. * @note MODE
  2172. * @note bmi160_set_intr_low_g_mode()
  2173. *
  2174. * @return results of bus communication function
  2175. * @retval 0 -> Success
  2176. * @retval -1 -> Error
  2177. *
  2178. *
  2179. */
  2180. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat1_low_g_intr(u8
  2181. *v_low_g_intr_u8)
  2182. {
  2183. /* variable used for return the status of communication result*/
  2184. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2185. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2186. /* check the p_bmi160 structure as NULL*/
  2187. if (p_bmi160 == BMI160_NULL) {
  2188. return E_BMI160_NULL_PTR;
  2189. } else {
  2190. com_rslt =
  2191. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2192. BMI160_USER_INTR_STAT_1_LOW_G_INTR__REG, &v_data_u8,
  2193. C_BMI160_ONE_U8X);
  2194. *v_low_g_intr_u8 =
  2195. BMI160_GET_BITSLICE(v_data_u8,
  2196. BMI160_USER_INTR_STAT_1_LOW_G_INTR);
  2197. }
  2198. return com_rslt;
  2199. }
  2200. /*!
  2201. * @brief This API reads data ready interrupt status
  2202. * from the register 0x1D bit 4
  2203. * flag is associated with a specific interrupt function.
  2204. * It is set when the data ready interrupt triggers. The
  2205. * setting of INT_LATCH controls if the interrupt signal and hence the
  2206. * respective interrupt flag will be
  2207. * permanently latched, temporarily latched
  2208. * or not latched.
  2209. *
  2210. *
  2211. *
  2212. *
  2213. * @param v_data_rdy_intr_u8 : The status of data ready interrupt
  2214. *
  2215. * @note Data ready interrupt configured by following functions
  2216. * @note STATUS
  2217. * @note bmi160_get_stat1_data_rdy_intr()
  2218. * @note INTERRUPT MAPPING
  2219. * @note bmi160_set_intr_data_rdy()
  2220. *
  2221. * @return results of bus communication function
  2222. * @retval 0 -> Success
  2223. * @retval -1 -> Error
  2224. *
  2225. *
  2226. */
  2227. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat1_data_rdy_intr(u8
  2228. *v_data_rdy_intr_u8)
  2229. {
  2230. /* variable used for return the status of communication result*/
  2231. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2232. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2233. /* check the p_bmi160 structure as NULL*/
  2234. if (p_bmi160 == BMI160_NULL) {
  2235. return E_BMI160_NULL_PTR;
  2236. } else {
  2237. com_rslt =
  2238. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2239. BMI160_USER_INTR_STAT_1_DATA_RDY_INTR__REG,
  2240. &v_data_u8, C_BMI160_ONE_U8X);
  2241. *v_data_rdy_intr_u8 = BMI160_GET_BITSLICE(v_data_u8,
  2242. BMI160_USER_INTR_STAT_1_DATA_RDY_INTR);
  2243. }
  2244. return com_rslt;
  2245. }
  2246. /*!
  2247. * @brief This API reads data ready FIFO full interrupt status
  2248. * from the register 0x1D bit 5
  2249. * flag is associated with a specific interrupt function.
  2250. * It is set when the FIFO full interrupt triggers. The
  2251. * setting of INT_LATCH controls if the
  2252. * interrupt signal and hence the
  2253. * respective interrupt flag will
  2254. * be permanently latched, temporarily latched
  2255. * or not latched.
  2256. *
  2257. *
  2258. *
  2259. *
  2260. * @param v_fifo_full_intr_u8 : The status of fifo full interrupt
  2261. *
  2262. * @note FIFO full interrupt can be configured by following functions
  2263. * @note bmi160_set_intr_fifo_full()
  2264. *
  2265. * @return results of bus communication function
  2266. * @retval 0 -> Success
  2267. * @retval -1 -> Error
  2268. *
  2269. *
  2270. */
  2271. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat1_fifo_full_intr(u8
  2272. *v_fifo_full_intr_u8)
  2273. {
  2274. /* variable used for return the status of communication result*/
  2275. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2276. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2277. /* check the p_bmi160 structure as NULL*/
  2278. if (p_bmi160 == BMI160_NULL) {
  2279. return E_BMI160_NULL_PTR;
  2280. } else {
  2281. com_rslt =
  2282. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2283. BMI160_USER_INTR_STAT_1_FIFO_FULL_INTR__REG,
  2284. &v_data_u8, C_BMI160_ONE_U8X);
  2285. *v_fifo_full_intr_u8 =
  2286. BMI160_GET_BITSLICE(v_data_u8,
  2287. BMI160_USER_INTR_STAT_1_FIFO_FULL_INTR);
  2288. }
  2289. return com_rslt;
  2290. }
  2291. /*!
  2292. * @brief This API reads data
  2293. * ready FIFO watermark interrupt status
  2294. * from the register 0x1D bit 6
  2295. * flag is associated with a specific interrupt function.
  2296. * It is set when the FIFO watermark interrupt triggers. The
  2297. * setting of INT_LATCH controls if the
  2298. * interrupt signal and hence the
  2299. * respective interrupt flag will be
  2300. * permanently latched, temporarily latched
  2301. * or not latched.
  2302. *
  2303. *
  2304. *
  2305. *
  2306. * @param v_fifo_wm_intr_u8 : The status of fifo water mark interrupt
  2307. *
  2308. * @note FIFO full interrupt can be configured by following functions
  2309. * @note bmi160_set_intr_fifo_wm()
  2310. *
  2311. * @return results of bus communication function
  2312. * @retval 0 -> Success
  2313. * @retval -1 -> Error
  2314. *
  2315. *
  2316. */
  2317. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat1_fifo_wm_intr(u8
  2318. *v_fifo_wm_intr_u8)
  2319. {
  2320. /* variable used for return the status of communication result*/
  2321. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2322. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2323. /* check the p_bmi160 structure as NULL*/
  2324. if (p_bmi160 == BMI160_NULL) {
  2325. return E_BMI160_NULL_PTR;
  2326. } else {
  2327. com_rslt =
  2328. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2329. BMI160_USER_INTR_STAT_1_FIFO_WM_INTR__REG,
  2330. &v_data_u8, C_BMI160_ONE_U8X);
  2331. *v_fifo_wm_intr_u8 =
  2332. BMI160_GET_BITSLICE(v_data_u8,
  2333. BMI160_USER_INTR_STAT_1_FIFO_WM_INTR);
  2334. }
  2335. return com_rslt;
  2336. }
  2337. /*!
  2338. * @brief This API reads data ready no motion interrupt status
  2339. * from the register 0x1D bit 7
  2340. * flag is associated with a specific interrupt function.
  2341. * It is set when the no motion interrupt triggers. The
  2342. * setting of INT_LATCH controls if the interrupt signal and hence the
  2343. * respective interrupt flag will be permanently
  2344. * latched, temporarily latched
  2345. * or not latched.
  2346. *
  2347. *
  2348. *
  2349. *
  2350. * @param v_nomotion_intr_u8 : The status of no motion interrupt
  2351. *
  2352. * @note No motion interrupt can be configured by following function
  2353. * @note STATUS
  2354. * @note bmi160_get_stat1_nomotion_intr()
  2355. * @note INTERRUPT MAPPING
  2356. * @note bmi160_set_intr_nomotion()
  2357. * @note DURATION
  2358. * @note bmi160_set_intr_slow_no_motion_durn()
  2359. * @note THRESHOLD
  2360. * @note bmi160_set_intr_slow_no_motion_thres()
  2361. * @note SLOW/NO MOTION SELECT
  2362. * @note bmi160_set_intr_slow_no_motion_select()
  2363. *
  2364. * @return results of bus communication function
  2365. * @retval 0 -> Success
  2366. * @retval -1 -> Error
  2367. *
  2368. *
  2369. */
  2370. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat1_nomotion_intr(u8
  2371. *v_nomotion_intr_u8)
  2372. {
  2373. /* variable used for return the status of communication result*/
  2374. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2375. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2376. /* check the p_bmi160 structure as NULL*/
  2377. if (p_bmi160 == BMI160_NULL) {
  2378. return E_BMI160_NULL_PTR;
  2379. } else {
  2380. /* read the no motion interrupt*/
  2381. com_rslt =
  2382. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2383. BMI160_USER_INTR_STAT_1_NOMOTION_INTR__REG,
  2384. &v_data_u8, C_BMI160_ONE_U8X);
  2385. *v_nomotion_intr_u8 =
  2386. BMI160_GET_BITSLICE(v_data_u8,
  2387. BMI160_USER_INTR_STAT_1_NOMOTION_INTR);
  2388. }
  2389. return com_rslt;
  2390. }
  2391. /*!
  2392. *@brief This API reads the status of any motion first x
  2393. * from the register 0x1E bit 0
  2394. *
  2395. *
  2396. *@param v_anymotion_first_x_u8 : The status of any motion first x interrupt
  2397. * value | status
  2398. * -----------|-------------
  2399. * 0 | not triggered
  2400. * 1 | triggered by x axis
  2401. *
  2402. * @return results of bus communication function
  2403. * @retval 0 -> Success
  2404. * @retval -1 -> Error
  2405. *
  2406. *
  2407. */
  2408. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_any_motion_first_x(u8
  2409. *v_anymotion_first_x_u8)
  2410. {
  2411. /* variable used for return the status of communication result*/
  2412. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2413. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2414. /* check the p_bmi160 structure as NULL*/
  2415. if (p_bmi160 == BMI160_NULL) {
  2416. return E_BMI160_NULL_PTR;
  2417. } else {
  2418. /* read the any motion first x interrupt*/
  2419. com_rslt =
  2420. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2421. BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_X__REG,
  2422. &v_data_u8, C_BMI160_ONE_U8X);
  2423. *v_anymotion_first_x_u8 =
  2424. BMI160_GET_BITSLICE(v_data_u8,
  2425. BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_X);
  2426. }
  2427. return com_rslt;
  2428. }
  2429. /*!
  2430. * @brief This API reads the status of any motion first y interrupt
  2431. * from the register 0x1E bit 1
  2432. *
  2433. *
  2434. *
  2435. *@param v_any_motion_first_y_u8 : The status of any motion first y interrupt
  2436. * value | status
  2437. * -----------|-------------
  2438. * 0 | not triggered
  2439. * 1 | triggered by y axis
  2440. *
  2441. *
  2442. *
  2443. * @return results of bus communication function
  2444. * @retval 0 -> Success
  2445. * @retval -1 -> Error
  2446. *
  2447. *
  2448. */
  2449. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_any_motion_first_y(u8
  2450. *v_any_motion_first_y_u8)
  2451. {
  2452. /* variable used for return the status of communication result*/
  2453. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2454. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2455. /* check the p_bmi160 structure as NULL*/
  2456. if (p_bmi160 == BMI160_NULL) {
  2457. return E_BMI160_NULL_PTR;
  2458. } else {
  2459. /* read the any motion first y interrupt*/
  2460. com_rslt =
  2461. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2462. BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_Y__REG,
  2463. &v_data_u8, C_BMI160_ONE_U8X);
  2464. *v_any_motion_first_y_u8 =
  2465. BMI160_GET_BITSLICE(v_data_u8,
  2466. BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_Y);
  2467. }
  2468. return com_rslt;
  2469. }
  2470. /*!
  2471. * @brief This API reads the status of any motion first z interrupt
  2472. * from the register 0x1E bit 2
  2473. *
  2474. *
  2475. *
  2476. *
  2477. *@param v_any_motion_first_z_u8 : The status of any motion first z interrupt
  2478. * value | status
  2479. * -----------|-------------
  2480. * 0 | not triggered
  2481. * 1 | triggered by y axis
  2482. *
  2483. *
  2484. *
  2485. * @return results of bus communication function
  2486. * @retval 0 -> Success
  2487. * @retval -1 -> Error
  2488. *
  2489. *
  2490. */
  2491. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_any_motion_first_z(u8
  2492. *v_any_motion_first_z_u8)
  2493. {
  2494. /* variable used for return the status of communication result*/
  2495. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2496. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2497. /* check the p_bmi160 structure as NULL*/
  2498. if (p_bmi160 == BMI160_NULL) {
  2499. return E_BMI160_NULL_PTR;
  2500. } else {
  2501. /* read the any motion first z interrupt*/
  2502. com_rslt =
  2503. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2504. BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_Z__REG,
  2505. &v_data_u8, C_BMI160_ONE_U8X);
  2506. *v_any_motion_first_z_u8 =
  2507. BMI160_GET_BITSLICE(v_data_u8,
  2508. BMI160_USER_INTR_STAT_2_ANY_MOTION_FIRST_Z);
  2509. }
  2510. return com_rslt;
  2511. }
  2512. /*!
  2513. * @brief This API reads the any motion sign status from the
  2514. * register 0x1E bit 3
  2515. *
  2516. *
  2517. *
  2518. *
  2519. * @param v_anymotion_sign_u8 : The status of any motion sign
  2520. * value | sign
  2521. * -----------|-------------
  2522. * 0 | positive
  2523. * 1 | negative
  2524. *
  2525. *
  2526. * @return results of bus communication function
  2527. * @retval 0 -> Success
  2528. * @retval -1 -> Error
  2529. *
  2530. *
  2531. */
  2532. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_any_motion_sign(u8
  2533. *v_anymotion_sign_u8)
  2534. {
  2535. /* variable used for return the status of communication result*/
  2536. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2537. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2538. /* check the p_bmi160 structure as NULL*/
  2539. if (p_bmi160 == BMI160_NULL) {
  2540. return E_BMI160_NULL_PTR;
  2541. } else {
  2542. /* read any motion sign interrupt status */
  2543. com_rslt =
  2544. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2545. BMI160_USER_INTR_STAT_2_ANY_MOTION_SIGN__REG,
  2546. &v_data_u8, C_BMI160_ONE_U8X);
  2547. *v_anymotion_sign_u8 =
  2548. BMI160_GET_BITSLICE(v_data_u8,
  2549. BMI160_USER_INTR_STAT_2_ANY_MOTION_SIGN);
  2550. }
  2551. return com_rslt;
  2552. }
  2553. /*!
  2554. * @brief This API reads the any motion tap first x status from the
  2555. * register 0x1E bit 4
  2556. *
  2557. *
  2558. *
  2559. *
  2560. * @param v_tap_first_x_u8 :The status of any motion tap first x
  2561. * value | status
  2562. * -----------|-------------
  2563. * 0 | not triggered
  2564. * 1 | triggered by x axis
  2565. *
  2566. * @return results of bus communication function
  2567. * @retval 0 -> Success
  2568. * @retval -1 -> Error
  2569. *
  2570. *
  2571. */
  2572. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_tap_first_x(u8
  2573. *v_tap_first_x_u8)
  2574. {
  2575. /* variable used for return the status of communication result*/
  2576. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2577. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2578. /* check the p_bmi160 structure as NULL*/
  2579. if (p_bmi160 == BMI160_NULL) {
  2580. return E_BMI160_NULL_PTR;
  2581. } else {
  2582. /* read tap first x interrupt status */
  2583. com_rslt =
  2584. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2585. BMI160_USER_INTR_STAT_2_TAP_FIRST_X__REG,
  2586. &v_data_u8, C_BMI160_ONE_U8X);
  2587. *v_tap_first_x_u8 =
  2588. BMI160_GET_BITSLICE(v_data_u8,
  2589. BMI160_USER_INTR_STAT_2_TAP_FIRST_X);
  2590. }
  2591. return com_rslt;
  2592. }
  2593. /*!
  2594. * @brief This API reads the tap first y interrupt status from the
  2595. * register 0x1E bit 5
  2596. *
  2597. *
  2598. *
  2599. *
  2600. * @param v_tap_first_y_u8 :The status of tap first y interrupt
  2601. * value | status
  2602. * -----------|-------------
  2603. * 0 | not triggered
  2604. * 1 | triggered by y axis
  2605. *
  2606. *
  2607. *
  2608. * @return results of bus communication function
  2609. * @retval 0 -> Success
  2610. * @retval -1 -> Error
  2611. *
  2612. *
  2613. */
  2614. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_tap_first_y(u8
  2615. *v_tap_first_y_u8)
  2616. {
  2617. /* variable used for return the status of communication result*/
  2618. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2619. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2620. /* check the p_bmi160 structure as NULL*/
  2621. if (p_bmi160 == BMI160_NULL) {
  2622. return E_BMI160_NULL_PTR;
  2623. } else {
  2624. /* read tap first y interrupt status */
  2625. com_rslt =
  2626. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2627. BMI160_USER_INTR_STAT_2_TAP_FIRST_Y__REG,
  2628. &v_data_u8, C_BMI160_ONE_U8X);
  2629. *v_tap_first_y_u8 =
  2630. BMI160_GET_BITSLICE(v_data_u8,
  2631. BMI160_USER_INTR_STAT_2_TAP_FIRST_Y);
  2632. }
  2633. return com_rslt;
  2634. }
  2635. /*!
  2636. * @brief This API reads the tap first z interrupt status from the
  2637. * register 0x1E bit 6
  2638. *
  2639. *
  2640. *
  2641. *
  2642. * @param v_tap_first_z_u8 :The status of tap first z interrupt
  2643. * value | status
  2644. * -----------|-------------
  2645. * 0 | not triggered
  2646. * 1 | triggered by z axis
  2647. *
  2648. *
  2649. *
  2650. * @return results of bus communication function
  2651. * @retval 0 -> Success
  2652. * @retval -1 -> Error
  2653. *
  2654. *
  2655. */
  2656. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_tap_first_z(u8
  2657. *v_tap_first_z_u8)
  2658. {
  2659. /* variable used for return the status of communication result*/
  2660. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2661. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2662. /* check the p_bmi160 structure as NULL*/
  2663. if (p_bmi160 == BMI160_NULL) {
  2664. return E_BMI160_NULL_PTR;
  2665. } else {
  2666. /* read tap first z interrupt status */
  2667. com_rslt =
  2668. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2669. BMI160_USER_INTR_STAT_2_TAP_FIRST_Z__REG,
  2670. &v_data_u8, C_BMI160_ONE_U8X);
  2671. *v_tap_first_z_u8 =
  2672. BMI160_GET_BITSLICE(v_data_u8,
  2673. BMI160_USER_INTR_STAT_2_TAP_FIRST_Z);
  2674. }
  2675. return com_rslt;
  2676. }
  2677. /*!
  2678. * @brief This API reads the tap sign status from the
  2679. * register 0x1E bit 7
  2680. *
  2681. *
  2682. *
  2683. *
  2684. * @param v_tap_sign_u8 : The status of tap sign
  2685. * value | sign
  2686. * -----------|-------------
  2687. * 0 | positive
  2688. * 1 | negative
  2689. *
  2690. *
  2691. * @return results of bus communication function
  2692. * @retval 0 -> Success
  2693. * @retval -1 -> Error
  2694. *
  2695. *
  2696. */
  2697. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat2_tap_sign(u8
  2698. *v_tap_sign_u8)
  2699. {
  2700. /* variable used for return the status of communication result*/
  2701. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2702. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2703. /* check the p_bmi160 structure as NULL*/
  2704. if (p_bmi160 == BMI160_NULL) {
  2705. return E_BMI160_NULL_PTR;
  2706. } else {
  2707. /* read tap_sign interrupt status */
  2708. com_rslt =
  2709. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2710. BMI160_USER_INTR_STAT_2_TAP_SIGN__REG, &v_data_u8,
  2711. C_BMI160_ONE_U8X);
  2712. *v_tap_sign_u8 =
  2713. BMI160_GET_BITSLICE(v_data_u8,
  2714. BMI160_USER_INTR_STAT_2_TAP_SIGN);
  2715. }
  2716. return com_rslt;
  2717. }
  2718. /*!
  2719. * @brief This API reads the high_g first x status from the
  2720. * register 0x1F bit 0
  2721. *
  2722. *
  2723. *
  2724. *
  2725. * @param v_high_g_first_x_u8 :The status of high_g first x
  2726. * value | status
  2727. * -----------|-------------
  2728. * 0 | not triggered
  2729. * 1 | triggered by x axis
  2730. *
  2731. *
  2732. *
  2733. * @return results of bus communication function
  2734. * @retval 0 -> Success
  2735. * @retval -1 -> Error
  2736. *
  2737. *
  2738. */
  2739. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat3_high_g_first_x(u8
  2740. *v_high_g_first_x_u8)
  2741. {
  2742. /* variable used for return the status of communication result*/
  2743. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2744. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2745. /* check the p_bmi160 structure as NULL*/
  2746. if (p_bmi160 == BMI160_NULL) {
  2747. return E_BMI160_NULL_PTR;
  2748. } else {
  2749. /* read highg_x interrupt status */
  2750. com_rslt =
  2751. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2752. BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_X__REG,
  2753. &v_data_u8, C_BMI160_ONE_U8X);
  2754. *v_high_g_first_x_u8 =
  2755. BMI160_GET_BITSLICE(v_data_u8,
  2756. BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_X);
  2757. }
  2758. return com_rslt;
  2759. }
  2760. /*!
  2761. * @brief This API reads the high_g first y status from the
  2762. * register 0x1F bit 1
  2763. *
  2764. *
  2765. *
  2766. *
  2767. * @param v_high_g_first_y_u8 : The status of high_g first y
  2768. * value | status
  2769. * -----------|-------------
  2770. * 0 | not triggered
  2771. * 1 | triggered by y axis
  2772. *
  2773. *
  2774. *
  2775. * @return results of bus communication function
  2776. * @retval 0 -> Success
  2777. * @retval -1 -> Error
  2778. *
  2779. *
  2780. */
  2781. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat3_high_g_first_y(u8
  2782. *v_high_g_first_y_u8)
  2783. {
  2784. /* variable used for return the status of communication result*/
  2785. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2786. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2787. /* check the p_bmi160 structure as NULL*/
  2788. if (p_bmi160 == BMI160_NULL) {
  2789. return E_BMI160_NULL_PTR;
  2790. } else {
  2791. /* read highg_y interrupt status */
  2792. com_rslt =
  2793. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2794. BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_Y__REG,
  2795. &v_data_u8, C_BMI160_ONE_U8X);
  2796. *v_high_g_first_y_u8 =
  2797. BMI160_GET_BITSLICE(v_data_u8,
  2798. BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_Y);
  2799. }
  2800. return com_rslt;
  2801. }
  2802. /*!
  2803. * @brief This API reads the high_g first z status from the
  2804. * register 0x1F bit 3
  2805. *
  2806. *
  2807. *
  2808. *
  2809. * @param v_high_g_first_z_u8 : The status of high_g first z
  2810. * value | status
  2811. * -----------|-------------
  2812. * 0 | not triggered
  2813. * 1 | triggered by z axis
  2814. *
  2815. *
  2816. *
  2817. * @return results of bus communication function
  2818. * @retval 0 -> Success
  2819. * @retval -1 -> Error
  2820. *
  2821. *
  2822. */
  2823. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat3_high_g_first_z(u8
  2824. *v_high_g_first_z_u8)
  2825. {
  2826. /* variable used for return the status of communication result*/
  2827. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2828. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2829. /* check the p_bmi160 structure as NULL*/
  2830. if (p_bmi160 == BMI160_NULL) {
  2831. return E_BMI160_NULL_PTR;
  2832. } else {
  2833. /* read highg_z interrupt status */
  2834. com_rslt =
  2835. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2836. BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_Z__REG,
  2837. &v_data_u8, C_BMI160_ONE_U8X);
  2838. *v_high_g_first_z_u8 =
  2839. BMI160_GET_BITSLICE(v_data_u8,
  2840. BMI160_USER_INTR_STAT_3_HIGH_G_FIRST_Z);
  2841. }
  2842. return com_rslt;
  2843. }
  2844. /*!
  2845. * @brief This API reads the high sign status from the
  2846. * register 0x1F bit 3
  2847. *
  2848. *
  2849. *
  2850. *
  2851. * @param v_high_g_sign_u8 :The status of high sign
  2852. * value | sign
  2853. * -----------|-------------
  2854. * 0 | positive
  2855. * 1 | negative
  2856. *
  2857. *
  2858. *
  2859. * @return results of bus communication function
  2860. * @retval 0 -> Success
  2861. * @retval -1 -> Error
  2862. *
  2863. *
  2864. */
  2865. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat3_high_g_sign(u8
  2866. *v_high_g_sign_u8)
  2867. {
  2868. /* variable used for return the status of communication result*/
  2869. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2870. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2871. /* check the p_bmi160 structure as NULL*/
  2872. if (p_bmi160 == BMI160_NULL) {
  2873. return E_BMI160_NULL_PTR;
  2874. } else {
  2875. /* read highg_sign interrupt status */
  2876. com_rslt =
  2877. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2878. BMI160_USER_INTR_STAT_3_HIGH_G_SIGN__REG,
  2879. &v_data_u8, C_BMI160_ONE_U8X);
  2880. *v_high_g_sign_u8 =
  2881. BMI160_GET_BITSLICE(v_data_u8,
  2882. BMI160_USER_INTR_STAT_3_HIGH_G_SIGN);
  2883. }
  2884. return com_rslt;
  2885. }
  2886. /*!
  2887. * @brief This API reads the status of orient_xy plane
  2888. * from the register 0x1F bit 4 and 5
  2889. *
  2890. *
  2891. * @param v_orient_xy_u8 :The status of orient_xy plane
  2892. * value | status
  2893. * -----------|-------------
  2894. * 0x00 | portrait upright
  2895. * 0x01 | portrait upside down
  2896. * 0x02 | landscape left
  2897. * 0x03 | landscape right
  2898. *
  2899. *
  2900. * @return results of bus communication function
  2901. * @retval 0 -> Success
  2902. * @retval -1 -> Error
  2903. *
  2904. *
  2905. */
  2906. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat3_orient_xy(u8
  2907. *v_orient_xy_u8)
  2908. {
  2909. /* variable used for return the status of communication result*/
  2910. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2911. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2912. /* check the p_bmi160 structure as NULL*/
  2913. if (p_bmi160 == BMI160_NULL) {
  2914. return E_BMI160_NULL_PTR;
  2915. } else {
  2916. /* read orient plane xy interrupt status */
  2917. com_rslt =
  2918. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2919. BMI160_USER_INTR_STAT_3_ORIENT_XY__REG,
  2920. &v_data_u8, C_BMI160_ONE_U8X);
  2921. *v_orient_xy_u8 =
  2922. BMI160_GET_BITSLICE(v_data_u8,
  2923. BMI160_USER_INTR_STAT_3_ORIENT_XY);
  2924. }
  2925. return com_rslt;
  2926. }
  2927. /*!
  2928. * @brief This API reads the status of orient z plane
  2929. * from the register 0x1F bit 6
  2930. *
  2931. *
  2932. * @param v_orient_z_u8 :The status of orient z
  2933. * value | status
  2934. * -----------|-------------
  2935. * 0x00 | upward looking
  2936. * 0x01 | downward looking
  2937. *
  2938. * @return results of bus communication function
  2939. * @retval 0 -> Success
  2940. * @retval -1 -> Error
  2941. *
  2942. *
  2943. */
  2944. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat3_orient_z(u8
  2945. *v_orient_z_u8)
  2946. {
  2947. /* variable used for return the status of communication result*/
  2948. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2949. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2950. /* check the p_bmi160 structure as NULL*/
  2951. if (p_bmi160 == BMI160_NULL) {
  2952. return E_BMI160_NULL_PTR;
  2953. } else {
  2954. /* read orient z plane interrupt status */
  2955. com_rslt =
  2956. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2957. BMI160_USER_INTR_STAT_3_ORIENT_Z__REG, &v_data_u8,
  2958. C_BMI160_ONE_U8X);
  2959. *v_orient_z_u8 =
  2960. BMI160_GET_BITSLICE(v_data_u8,
  2961. BMI160_USER_INTR_STAT_3_ORIENT_Z);
  2962. }
  2963. return com_rslt;
  2964. }
  2965. /*!
  2966. * @brief This API reads the flat status from the register
  2967. * 0x1F bit 7
  2968. *
  2969. *
  2970. * @param v_flat_u8 : The status of flat interrupt
  2971. * value | status
  2972. * -----------|-------------
  2973. * 0x00 | non flat
  2974. * 0x01 | flat position
  2975. *
  2976. *
  2977. * @return results of bus communication function
  2978. * @retval 0 -> Success
  2979. * @retval -1 -> Error
  2980. *
  2981. *
  2982. */
  2983. BMI160_RETURN_FUNCTION_TYPE bmi160_get_stat3_flat(u8
  2984. *v_flat_u8)
  2985. {
  2986. /* variable used for return the status of communication result*/
  2987. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  2988. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  2989. /* check the p_bmi160 structure as NULL*/
  2990. if (p_bmi160 == BMI160_NULL) {
  2991. return E_BMI160_NULL_PTR;
  2992. } else {
  2993. /* read flat interrupt status */
  2994. com_rslt =
  2995. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  2996. BMI160_USER_INTR_STAT_3_FLAT__REG, &v_data_u8,
  2997. C_BMI160_ONE_U8X);
  2998. *v_flat_u8 = BMI160_GET_BITSLICE(v_data_u8,
  2999. BMI160_USER_INTR_STAT_3_FLAT);
  3000. }
  3001. return com_rslt;
  3002. }
  3003. /*!
  3004. * @brief This API reads the temperature of the sensor
  3005. * from the register 0x21 bit 0 to 7
  3006. *
  3007. *
  3008. *
  3009. * @param v_temp_s16 : The value of temperature
  3010. *
  3011. *
  3012. *
  3013. * @return results of bus communication function
  3014. * @retval 0 -> Success
  3015. * @retval -1 -> Error
  3016. *
  3017. *
  3018. */
  3019. BMI160_RETURN_FUNCTION_TYPE bmi160_get_temp(s16
  3020. *v_temp_s16)
  3021. {
  3022. /* variable used for return the status of communication result*/
  3023. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3024. /* Array contains the temperature lSB and MSB data
  3025. v_data_u8[0] - LSB
  3026. v_data_u8[1] - MSB*/
  3027. u8 v_data_u8[ARRAY_SIZE_TWO] = {C_BMI160_ZERO_U8X,
  3028. C_BMI160_ZERO_U8X};
  3029. /* check the p_bmi160 structure as NULL*/
  3030. if (p_bmi160 == BMI160_NULL) {
  3031. return E_BMI160_NULL_PTR;
  3032. } else {
  3033. /* read temperature data */
  3034. com_rslt =
  3035. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3036. BMI160_USER_TEMP_LSB_VALUE__REG, v_data_u8,
  3037. C_BMI160_TWO_U8X);
  3038. *v_temp_s16 =
  3039. (s16)(((s32)((s8) (v_data_u8[MSB_ONE]) <<
  3040. BMI160_SHIFT_8_POSITION))|v_data_u8[LSB_ZERO]);
  3041. }
  3042. return com_rslt;
  3043. }
  3044. /*!
  3045. * @brief This API reads the of the sensor
  3046. * form the register 0x23 and 0x24 bit 0 to 7 and 0 to 2
  3047. * @brief this byte counter is updated each time a complete frame
  3048. * was read or writtern
  3049. *
  3050. *
  3051. * @param v_fifo_length_u32 : The value of fifo byte counter
  3052. *
  3053. *
  3054. * @return results of bus communication function
  3055. * @retval 0 -> Success
  3056. * @retval -1 -> Error
  3057. *
  3058. *
  3059. */
  3060. BMI160_RETURN_FUNCTION_TYPE bmi160_fifo_length(u32 *v_fifo_length_u32)
  3061. {
  3062. /* variable used for return the status of communication result*/
  3063. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3064. /* Array contains the fifo length data
  3065. v_data_u8[0] - fifo length
  3066. v_data_u8[1] - fifo length*/
  3067. u8 a_data_u8r[ARRAY_SIZE_TWO] = {C_BMI160_ZERO_U8X,
  3068. C_BMI160_ZERO_U8X};
  3069. /* check the p_bmi160 structure as NULL*/
  3070. if (p_bmi160 == BMI160_NULL) {
  3071. return E_BMI160_NULL_PTR;
  3072. } else {
  3073. /* read fifo length*/
  3074. com_rslt =
  3075. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3076. BMI160_USER_FIFO_BYTE_COUNTER_LSB__REG, a_data_u8r,
  3077. C_BMI160_TWO_U8X);
  3078. a_data_u8r[MSB_ONE] =
  3079. BMI160_GET_BITSLICE(a_data_u8r[MSB_ONE],
  3080. BMI160_USER_FIFO_BYTE_COUNTER_MSB);
  3081. *v_fifo_length_u32 =
  3082. (u32)(((u32)((u8) (a_data_u8r[MSB_ONE]) <<
  3083. BMI160_SHIFT_8_POSITION))|a_data_u8r[LSB_ZERO]);
  3084. }
  3085. return com_rslt;
  3086. }
  3087. /*!
  3088. * @brief This API reads the fifo data of the sensor
  3089. * from the register 0x24
  3090. * @brief Data format depends on the setting of register FIFO_CONFIG
  3091. *
  3092. *
  3093. *
  3094. * @param v_fifo_data_u8 : Pointer holding the fifo data
  3095. *
  3096. * @note For reading FIFO data use the following functions
  3097. *
  3098. * @return results of bus communication function
  3099. * @retval 0 -> Success
  3100. * @retval -1 -> Error
  3101. *
  3102. *
  3103. */
  3104. BMI160_RETURN_FUNCTION_TYPE bmi160_fifo_data(
  3105. u8 *v_fifo_data_u8)
  3106. {
  3107. /* variable used for return the status of communication result*/
  3108. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3109. /* check the p_bmi160 structure as NULL*/
  3110. if (p_bmi160 == BMI160_NULL) {
  3111. return E_BMI160_NULL_PTR;
  3112. } else {
  3113. /* read fifo data*/
  3114. com_rslt =
  3115. p_bmi160->BMI160_BURST_READ_FUNC(p_bmi160->dev_addr,
  3116. BMI160_USER_FIFO_DATA__REG, v_fifo_data_u8, FIFO_FRAME);
  3117. }
  3118. return com_rslt;
  3119. }
  3120. //add by lwy
  3121. BMI160_RETURN_FUNCTION_TYPE bmi160_fifo_data_get_set_integration(
  3122. u8 *v_fifo_data_u8, u32 *fifo_len_u32)
  3123. {
  3124. u32 v_fifo_length_u32=0,i;
  3125. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3126. u8 mag_en = C_BMI160_ZERO_U8X;
  3127. u8 accel_en = C_BMI160_ZERO_U8X;
  3128. u8 gyro_en = C_BMI160_ZERO_U8X;
  3129. u8 read_size = 128;
  3130. /* read the mag enable status*/
  3131. com_rslt += bmi160_get_fifo_mag_enable(&mag_en);
  3132. /* read the accel enable status*/
  3133. com_rslt += bmi160_get_fifo_accel_enable(&accel_en);
  3134. /* read the gyro enable status*/
  3135. com_rslt += bmi160_get_fifo_gyro_enable(&gyro_en);
  3136. /* condition for mag, gyro and accel enable*/
  3137. if ((mag_en == C_BMI160_ONE_U8X) &&
  3138. (gyro_en == C_BMI160_ONE_U8X)
  3139. && (accel_en == C_BMI160_ONE_U8X)) {
  3140. read_size = C_BMI160_ONE_U8X + C_BMI160_TWENTY_U8X;
  3141. }
  3142. /* condition for mag and gyro enable*/
  3143. else if ((mag_en == C_BMI160_ONE_U8X) &&
  3144. (gyro_en == C_BMI160_ONE_U8X)
  3145. && (accel_en == C_BMI160_ZERO_U8X)) {
  3146. read_size = C_BMI160_ONE_U8X + C_BMI160_FOURTEEN_U8X;
  3147. }
  3148. /* condition for mag and accel enable*/
  3149. else if ((mag_en == C_BMI160_ONE_U8X) &&
  3150. (accel_en == C_BMI160_ONE_U8X)
  3151. && (gyro_en == C_BMI160_ZERO_U8X)) {
  3152. read_size = C_BMI160_ONE_U8X + C_BMI160_FOURTEEN_U8X;
  3153. }
  3154. /* condition for gyro and accel enable*/
  3155. else if ((gyro_en == C_BMI160_ONE_U8X) &&
  3156. (accel_en == C_BMI160_ONE_U8X)
  3157. && (mag_en == C_BMI160_ZERO_U8X)) {
  3158. read_size = C_BMI160_ONE_U8X + C_BMI160_TWELVE_U8X;
  3159. }
  3160. /* condition for gyro enable*/
  3161. else if ((gyro_en == C_BMI160_ONE_U8X) &&
  3162. (accel_en == C_BMI160_ZERO_U8X)
  3163. && (mag_en == C_BMI160_ZERO_U8X)) {
  3164. read_size = C_BMI160_ONE_U8X + C_BMI160_SIX_U8X;
  3165. }
  3166. /* condition for accel enable*/
  3167. else if ((gyro_en == C_BMI160_ZERO_U8X) &&
  3168. (accel_en == C_BMI160_ONE_U8X)
  3169. && (mag_en == C_BMI160_ZERO_U8X)) {
  3170. read_size = C_BMI160_ONE_U8X + C_BMI160_SIX_U8X;
  3171. }
  3172. /* condition for mag enable*/
  3173. else if ((gyro_en == C_BMI160_ZERO_U8X) &&
  3174. (accel_en == C_BMI160_ZERO_U8X)
  3175. && (mag_en == C_BMI160_ONE_U8X)) {
  3176. read_size = C_BMI160_ONE_U8X + C_BMI160_EIGHT_U8X;
  3177. }
  3178. com_rslt = bmi160_fifo_length(&v_fifo_length_u32);
  3179. /* check the p_bmi160 structure as NULL*/
  3180. if (p_bmi160 == BMI160_NULL) {
  3181. *fifo_len_u32 = C_BMI160_ZERO_U8X;
  3182. return E_BMI160_NULL_PTR;
  3183. } else {
  3184. /* read fifo data*/
  3185. if(v_fifo_length_u32 != C_BMI160_ZERO_U8X){
  3186. // SEGGER_RTT_printf(0,"read v_fifo_length_u32 before:%d\r\n",v_fifo_length_u32);
  3187. *fifo_len_u32 = v_fifo_length_u32;
  3188. for(i=0;i<v_fifo_length_u32;i+=read_size)
  3189. {
  3190. com_rslt +=
  3191. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3192. BMI160_USER_FIFO_DATA__REG, &v_fifo_data_u8[i], read_size);
  3193. }
  3194. com_rslt = bmi160_fifo_length(&v_fifo_length_u32);
  3195. // SEGGER_RTT_printf(0,"read v_fifo_length_u32 after:%d\r\n",v_fifo_length_u32);
  3196. }else{
  3197. *fifo_len_u32 = C_BMI160_ZERO_U8X;
  3198. }
  3199. }
  3200. return com_rslt;
  3201. }
  3202. /*!
  3203. * @brief This API is used to get the
  3204. * accel output date rate form the register 0x40 bit 0 to 3
  3205. *
  3206. *
  3207. * @param v_output_data_rate_u8 :The value of accel output date rate
  3208. * value | output data rate
  3209. * -------|--------------------------
  3210. * 0 | BMI160_ACCEL_OUTPUT_DATA_RATE_RESERVED
  3211. * 1 | BMI160_ACCEL_OUTPUT_DATA_RATE_0_78HZ
  3212. * 2 | BMI160_ACCEL_OUTPUT_DATA_RATE_1_56HZ
  3213. * 3 | BMI160_ACCEL_OUTPUT_DATA_RATE_3_12HZ
  3214. * 4 | BMI160_ACCEL_OUTPUT_DATA_RATE_6_25HZ
  3215. * 5 | BMI160_ACCEL_OUTPUT_DATA_RATE_12_5HZ
  3216. * 6 | BMI160_ACCEL_OUTPUT_DATA_RATE_25HZ
  3217. * 7 | BMI160_ACCEL_OUTPUT_DATA_RATE_50HZ
  3218. * 8 | BMI160_ACCEL_OUTPUT_DATA_RATE_100HZ
  3219. * 9 | BMI160_ACCEL_OUTPUT_DATA_RATE_200HZ
  3220. * 10 | BMI160_ACCEL_OUTPUT_DATA_RATE_400HZ
  3221. * 11 | BMI160_ACCEL_OUTPUT_DATA_RATE_800HZ
  3222. * 12 | BMI160_ACCEL_OUTPUT_DATA_RATE_1600HZ
  3223. *
  3224. *
  3225. * @return results of bus communication function
  3226. * @retval 0 -> Success
  3227. * @retval -1 -> Error
  3228. *
  3229. *
  3230. */
  3231. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_output_data_rate(
  3232. u8 *v_output_data_rate_u8)
  3233. {
  3234. /* variable used for return the status of communication result*/
  3235. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3236. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  3237. /* check the p_bmi160 structure as NULL*/
  3238. if (p_bmi160 == BMI160_NULL) {
  3239. return E_BMI160_NULL_PTR;
  3240. } else {
  3241. /* read the accel output data rate*/
  3242. com_rslt =
  3243. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3244. BMI160_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE__REG,
  3245. &v_data_u8, C_BMI160_ONE_U8X);
  3246. *v_output_data_rate_u8 = BMI160_GET_BITSLICE(v_data_u8,
  3247. BMI160_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE);
  3248. }
  3249. return com_rslt;
  3250. }
  3251. /*!
  3252. * @brief This API is used to set the
  3253. * accel output date rate form the register 0x40 bit 0 to 3
  3254. *
  3255. *
  3256. * @param v_output_data_rate_u8 :The value of accel output date rate
  3257. * value | output data rate
  3258. * -------|--------------------------
  3259. * 0 | BMI160_ACCEL_OUTPUT_DATA_RATE_RESERVED
  3260. * 1 | BMI160_ACCEL_OUTPUT_DATA_RATE_0_78HZ
  3261. * 2 | BMI160_ACCEL_OUTPUT_DATA_RATE_1_56HZ
  3262. * 3 | BMI160_ACCEL_OUTPUT_DATA_RATE_3_12HZ
  3263. * 4 | BMI160_ACCEL_OUTPUT_DATA_RATE_6_25HZ
  3264. * 5 | BMI160_ACCEL_OUTPUT_DATA_RATE_12_5HZ
  3265. * 6 | BMI160_ACCEL_OUTPUT_DATA_RATE_25HZ
  3266. * 7 | BMI160_ACCEL_OUTPUT_DATA_RATE_50HZ
  3267. * 8 | BMI160_ACCEL_OUTPUT_DATA_RATE_100HZ
  3268. * 9 | BMI160_ACCEL_OUTPUT_DATA_RATE_200HZ
  3269. * 10 | BMI160_ACCEL_OUTPUT_DATA_RATE_400HZ
  3270. * 11 | BMI160_ACCEL_OUTPUT_DATA_RATE_800HZ
  3271. * 12 | BMI160_ACCEL_OUTPUT_DATA_RATE_1600HZ
  3272. *
  3273. *
  3274. * @return results of bus communication function
  3275. * @retval 0 -> Success
  3276. * @retval -1 -> Error
  3277. *
  3278. *
  3279. */
  3280. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_output_data_rate(
  3281. u8 v_output_data_rate_u8)
  3282. {
  3283. /* variable used for return the status of communication result*/
  3284. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3285. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  3286. /* check the p_bmi160 structure as NULL*/
  3287. if (p_bmi160 == BMI160_NULL) {
  3288. return E_BMI160_NULL_PTR;
  3289. } else {
  3290. /* accel output data rate selection */
  3291. if ((v_output_data_rate_u8 != C_BMI160_ZERO_U8X) &&
  3292. (v_output_data_rate_u8 < C_BMI160_THIRTEEN_U8X)) {
  3293. /* write accel output data rate */
  3294. com_rslt =
  3295. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3296. BMI160_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE__REG,
  3297. &v_data_u8, C_BMI160_ONE_U8X);
  3298. if (com_rslt == SUCCESS) {
  3299. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  3300. BMI160_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE,
  3301. v_output_data_rate_u8);
  3302. com_rslt +=
  3303. p_bmi160->BMI160_BUS_WRITE_FUNC(
  3304. p_bmi160->dev_addr,
  3305. BMI160_USER_ACCEL_CONFIG_OUTPUT_DATA_RATE__REG,
  3306. &v_data_u8, C_BMI160_ONE_U8X);
  3307. }
  3308. } else {
  3309. com_rslt = E_BMI160_OUT_OF_RANGE;
  3310. }
  3311. }
  3312. return com_rslt;
  3313. }
  3314. /*!
  3315. * @brief This API is used to get the
  3316. * accel bandwidth from the register 0x40 bit 4 to 6
  3317. * @brief bandwidth parameter determines filter configuration(acc_us=0)
  3318. * and averaging for under sampling mode(acc_us=1)
  3319. *
  3320. *
  3321. * @param v_bw_u8 : The value of accel bandwidth
  3322. *
  3323. * @note accel bandwidth depends on under sampling parameter
  3324. * @note under sampling parameter cab be set by the function
  3325. * "BMI160_SET_ACCEL_UNDER_SAMPLING_PARAMETER"
  3326. *
  3327. * @note Filter configuration
  3328. * accel_us | Filter configuration
  3329. * -----------|---------------------
  3330. * 0x00 | OSR4 mode
  3331. * 0x01 | OSR2 mode
  3332. * 0x02 | normal mode
  3333. * 0x03 | CIC mode
  3334. * 0x04 | Reserved
  3335. * 0x05 | Reserved
  3336. * 0x06 | Reserved
  3337. * 0x07 | Reserved
  3338. *
  3339. * @note accel under sampling mode
  3340. * accel_us | Under sampling mode
  3341. * -----------|---------------------
  3342. * 0x00 | no averaging
  3343. * 0x01 | average 2 samples
  3344. * 0x02 | average 4 samples
  3345. * 0x03 | average 8 samples
  3346. * 0x04 | average 16 samples
  3347. * 0x05 | average 32 samples
  3348. * 0x06 | average 64 samples
  3349. * 0x07 | average 128 samples
  3350. *
  3351. *
  3352. *
  3353. * @return results of bus communication function
  3354. * @retval 0 -> Success
  3355. * @retval -1 -> Error
  3356. *
  3357. *
  3358. */
  3359. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_bw(u8 *v_bw_u8)
  3360. {
  3361. /* variable used for return the status of communication result*/
  3362. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3363. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  3364. /* check the p_bmi160 structure as NULL*/
  3365. if (p_bmi160 == BMI160_NULL) {
  3366. return E_BMI160_NULL_PTR;
  3367. } else {
  3368. /* read the accel bandwidth */
  3369. com_rslt =
  3370. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3371. BMI160_USER_ACCEL_CONFIG_ACCEL_BW__REG, &v_data_u8,
  3372. C_BMI160_ONE_U8X);
  3373. *v_bw_u8 = BMI160_GET_BITSLICE(v_data_u8,
  3374. BMI160_USER_ACCEL_CONFIG_ACCEL_BW);
  3375. }
  3376. return com_rslt;
  3377. }
  3378. /*!
  3379. * @brief This API is used to set the
  3380. * accel bandwidth from the register 0x40 bit 4 to 6
  3381. * @brief bandwidth parameter determines filter configuration(acc_us=0)
  3382. * and averaging for under sampling mode(acc_us=1)
  3383. *
  3384. *
  3385. * @param v_bw_u8 : The value of accel bandwidth
  3386. *
  3387. * @note accel bandwidth depends on under sampling parameter
  3388. * @note under sampling parameter cab be set by the function
  3389. * "BMI160_SET_ACCEL_UNDER_SAMPLING_PARAMETER"
  3390. *
  3391. * @note Filter configuration
  3392. * accel_us | Filter configuration
  3393. * -----------|---------------------
  3394. * 0x00 | OSR4 mode
  3395. * 0x01 | OSR2 mode
  3396. * 0x02 | normal mode
  3397. * 0x03 | CIC mode
  3398. * 0x04 | Reserved
  3399. * 0x05 | Reserved
  3400. * 0x06 | Reserved
  3401. * 0x07 | Reserved
  3402. *
  3403. * @note accel under sampling mode
  3404. * accel_us | Under sampling mode
  3405. * -----------|---------------------
  3406. * 0x00 | no averaging
  3407. * 0x01 | average 2 samples
  3408. * 0x02 | average 4 samples
  3409. * 0x03 | average 8 samples
  3410. * 0x04 | average 16 samples
  3411. * 0x05 | average 32 samples
  3412. * 0x06 | average 64 samples
  3413. * 0x07 | average 128 samples
  3414. *
  3415. *
  3416. *
  3417. * @return results of bus communication function
  3418. * @retval 0 -> Success
  3419. * @retval -1 -> Error
  3420. *
  3421. *
  3422. */
  3423. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_bw(u8 v_bw_u8)
  3424. {
  3425. /* variable used for return the status of communication result*/
  3426. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3427. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  3428. /* check the p_bmi160 structure as NULL*/
  3429. if (p_bmi160 == BMI160_NULL) {
  3430. return E_BMI160_NULL_PTR;
  3431. } else {
  3432. /* select accel bandwidth*/
  3433. if (v_bw_u8 < C_BMI160_EIGHT_U8X) {
  3434. /* write accel bandwidth*/
  3435. com_rslt =
  3436. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3437. BMI160_USER_ACCEL_CONFIG_ACCEL_BW__REG, &v_data_u8,
  3438. C_BMI160_ONE_U8X);
  3439. if (com_rslt == SUCCESS) {
  3440. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  3441. BMI160_USER_ACCEL_CONFIG_ACCEL_BW,
  3442. v_bw_u8);
  3443. com_rslt +=
  3444. p_bmi160->BMI160_BUS_WRITE_FUNC(
  3445. p_bmi160->dev_addr,
  3446. BMI160_USER_ACCEL_CONFIG_ACCEL_BW__REG,
  3447. &v_data_u8, C_BMI160_ONE_U8X);
  3448. }
  3449. } else {
  3450. com_rslt = E_BMI160_OUT_OF_RANGE;
  3451. }
  3452. }
  3453. return com_rslt;
  3454. }
  3455. /*!
  3456. * @brief This API is used to get the accel
  3457. * under sampling parameter form the register 0x40 bit 7
  3458. *
  3459. *
  3460. *
  3461. *
  3462. * @param v_accel_under_sampling_u8 : The value of accel under sampling
  3463. * value | under_sampling
  3464. * ----------|---------------
  3465. * 0x01 | BMI160_ENABLE
  3466. * 0x00 | BMI160_DISABLE
  3467. *
  3468. *
  3469. *
  3470. * @return results of bus communication function
  3471. * @retval 0 -> Success
  3472. * @retval -1 -> Error
  3473. *
  3474. *
  3475. */
  3476. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_under_sampling_parameter(
  3477. u8 *v_accel_under_sampling_u8)
  3478. {
  3479. /* variable used for return the status of communication result*/
  3480. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3481. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  3482. /* check the p_bmi160 structure as NULL*/
  3483. if (p_bmi160 == BMI160_NULL) {
  3484. return E_BMI160_NULL_PTR;
  3485. } else {
  3486. /* read the accel under sampling parameter */
  3487. com_rslt =
  3488. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3489. BMI160_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING__REG,
  3490. &v_data_u8, C_BMI160_ONE_U8X);
  3491. *v_accel_under_sampling_u8 =
  3492. BMI160_GET_BITSLICE(v_data_u8,
  3493. BMI160_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING);
  3494. }
  3495. return com_rslt;
  3496. }
  3497. /*!
  3498. * @brief This API is used to set the accel
  3499. * under sampling parameter form the register 0x40 bit 7
  3500. *
  3501. *
  3502. *
  3503. *
  3504. * @param v_accel_under_sampling_u8 : The value of accel under sampling
  3505. * value | under_sampling
  3506. * ----------|---------------
  3507. * 0x01 | BMI160_ENABLE
  3508. * 0x00 | BMI160_DISABLE
  3509. *
  3510. *
  3511. *
  3512. * @return results of bus communication function
  3513. * @retval 0 -> Success
  3514. * @retval -1 -> Error
  3515. *
  3516. *
  3517. */
  3518. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_under_sampling_parameter(
  3519. u8 v_accel_under_sampling_u8)
  3520. {
  3521. /* variable used for return the status of communication result*/
  3522. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3523. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  3524. /* check the p_bmi160 structure as NULL*/
  3525. if (p_bmi160 == BMI160_NULL) {
  3526. return E_BMI160_NULL_PTR;
  3527. } else {
  3528. if (v_accel_under_sampling_u8 < C_BMI160_EIGHT_U8X) {
  3529. com_rslt =
  3530. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3531. BMI160_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING__REG,
  3532. &v_data_u8, C_BMI160_ONE_U8X);
  3533. if (com_rslt == SUCCESS) {
  3534. /* write the accel under sampling parameter */
  3535. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  3536. BMI160_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING,
  3537. v_accel_under_sampling_u8);
  3538. com_rslt +=
  3539. p_bmi160->BMI160_BUS_WRITE_FUNC(
  3540. p_bmi160->dev_addr,
  3541. BMI160_USER_ACCEL_CONFIG_ACCEL_UNDER_SAMPLING__REG,
  3542. &v_data_u8, C_BMI160_ONE_U8X);
  3543. }
  3544. } else {
  3545. com_rslt = E_BMI160_OUT_OF_RANGE;
  3546. }
  3547. }
  3548. return com_rslt;
  3549. }
  3550. /*!
  3551. * @brief This API is used to get the ranges
  3552. * (g values) of the accel from the register 0x41 bit 0 to 3
  3553. *
  3554. *
  3555. *
  3556. *
  3557. * @param v_range_u8 : The value of accel g range
  3558. * value | g_range
  3559. * ----------|-----------
  3560. * 0x03 | BMI160_ACCEL_RANGE_2G
  3561. * 0x05 | BMI160_ACCEL_RANGE_4G
  3562. * 0x08 | BMI160_ACCEL_RANGE_8G
  3563. * 0x0C | BMI160_ACCEL_RANGE_16G
  3564. *
  3565. *
  3566. *
  3567. * @return results of bus communication function
  3568. * @retval 0 -> Success
  3569. * @retval -1 -> Error
  3570. *
  3571. *
  3572. */
  3573. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_range(
  3574. u8 *v_range_u8)
  3575. {
  3576. /* variable used for return the status of communication result*/
  3577. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3578. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  3579. /* check the p_bmi160 structure as NULL*/
  3580. if (p_bmi160 == BMI160_NULL) {
  3581. return E_BMI160_NULL_PTR;
  3582. } else {
  3583. /* read the accel range*/
  3584. com_rslt =
  3585. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3586. BMI160_USER_ACCEL_RANGE__REG, &v_data_u8,
  3587. C_BMI160_ONE_U8X);
  3588. *v_range_u8 = BMI160_GET_BITSLICE(v_data_u8,
  3589. BMI160_USER_ACCEL_RANGE);
  3590. }
  3591. return com_rslt;
  3592. }
  3593. /*!
  3594. * @brief This API is used to set the ranges
  3595. * (g values) of the accel from the register 0x41 bit 0 to 3
  3596. *
  3597. *
  3598. *
  3599. *
  3600. * @param v_range_u8 : The value of accel g range
  3601. * value | g_range
  3602. * ----------|-----------
  3603. * 0x03 | BMI160_ACCEL_RANGE_2G
  3604. * 0x05 | BMI160_ACCEL_RANGE_4G
  3605. * 0x08 | BMI160_ACCEL_RANGE_8G
  3606. * 0x0C | BMI160_ACCEL_RANGE_16G
  3607. *
  3608. *
  3609. *
  3610. * @return results of bus communication function
  3611. * @retval 0 -> Success
  3612. * @retval -1 -> Error
  3613. *
  3614. *
  3615. */
  3616. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_range(u8 v_range_u8)
  3617. {
  3618. /* variable used for return the status of communication result*/
  3619. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3620. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  3621. /* check the p_bmi160 structure as NULL*/
  3622. if (p_bmi160 == BMI160_NULL) {
  3623. return E_BMI160_NULL_PTR;
  3624. } else {
  3625. if ((v_range_u8 == C_BMI160_THREE_U8X) ||
  3626. (v_range_u8 == C_BMI160_FIVE_U8X) ||
  3627. (v_range_u8 == C_BMI160_EIGHT_U8X) ||
  3628. (v_range_u8 == C_BMI160_TWELVE_U8X)) {
  3629. com_rslt =
  3630. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3631. BMI160_USER_ACCEL_RANGE__REG,
  3632. &v_data_u8, C_BMI160_ONE_U8X);
  3633. if (com_rslt == SUCCESS) {
  3634. v_data_u8 = BMI160_SET_BITSLICE(
  3635. v_data_u8, BMI160_USER_ACCEL_RANGE,
  3636. v_range_u8);
  3637. /* write the accel range*/
  3638. com_rslt +=
  3639. p_bmi160->BMI160_BUS_WRITE_FUNC(
  3640. p_bmi160->dev_addr,
  3641. BMI160_USER_ACCEL_RANGE__REG,
  3642. &v_data_u8, C_BMI160_ONE_U8X);
  3643. }
  3644. } else {
  3645. com_rslt = E_BMI160_OUT_OF_RANGE;
  3646. }
  3647. }
  3648. return com_rslt;
  3649. }
  3650. /*!
  3651. * @brief This API is used to get the
  3652. * gyroscope output data rate from the register 0x42 bit 0 to 3
  3653. *
  3654. *
  3655. *
  3656. *
  3657. * @param v_output_data_rate_u8 :The value of gyro output data rate
  3658. * value | gyro output data rate
  3659. * -----------|-----------------------------
  3660. * 0x00 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3661. * 0x01 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3662. * 0x02 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3663. * 0x03 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3664. * 0x04 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3665. * 0x05 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3666. * 0x06 | BMI160_GYRO_OUTPUT_DATA_RATE_25HZ
  3667. * 0x07 | BMI160_GYRO_OUTPUT_DATA_RATE_50HZ
  3668. * 0x08 | BMI160_GYRO_OUTPUT_DATA_RATE_100HZ
  3669. * 0x09 | BMI160_GYRO_OUTPUT_DATA_RATE_200HZ
  3670. * 0x0A | BMI160_GYRO_OUTPUT_DATA_RATE_400HZ
  3671. * 0x0B | BMI160_GYRO_OUTPUT_DATA_RATE_800HZ
  3672. * 0x0C | BMI160_GYRO_OUTPUT_DATA_RATE_1600HZ
  3673. * 0x0D | BMI160_GYRO_OUTPUT_DATA_RATE_3200HZ
  3674. * 0x0E | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3675. * 0x0F | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3676. *
  3677. * @return results of bus communication function
  3678. * @retval 0 -> Success
  3679. * @retval -1 -> Error
  3680. *
  3681. *
  3682. */
  3683. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_output_data_rate(
  3684. u8 *v_output_data_rate_u8)
  3685. {
  3686. /* variable used for return the status of communication result*/
  3687. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3688. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  3689. /* check the p_bmi160 structure as NULL*/
  3690. if (p_bmi160 == BMI160_NULL) {
  3691. return E_BMI160_NULL_PTR;
  3692. } else {
  3693. /* read the gyro output data rate*/
  3694. com_rslt =
  3695. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3696. BMI160_USER_GYRO_CONFIG_OUTPUT_DATA_RATE__REG,
  3697. &v_data_u8, C_BMI160_ONE_U8X);
  3698. *v_output_data_rate_u8 = BMI160_GET_BITSLICE(v_data_u8,
  3699. BMI160_USER_GYRO_CONFIG_OUTPUT_DATA_RATE);
  3700. }
  3701. return com_rslt;
  3702. }
  3703. /*!
  3704. * @brief This API is used to set the
  3705. * gyroscope output data rate from the register 0x42 bit 0 to 3
  3706. *
  3707. *
  3708. *
  3709. *
  3710. * @param v_output_data_rate_u8 :The value of gyro output data rate
  3711. * value | gyro output data rate
  3712. * -----------|-----------------------------
  3713. * 0x00 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3714. * 0x01 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3715. * 0x02 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3716. * 0x03 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3717. * 0x04 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3718. * 0x05 | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3719. * 0x06 | BMI160_GYRO_OUTPUT_DATA_RATE_25HZ
  3720. * 0x07 | BMI160_GYRO_OUTPUT_DATA_RATE_50HZ
  3721. * 0x08 | BMI160_GYRO_OUTPUT_DATA_RATE_100HZ
  3722. * 0x09 | BMI160_GYRO_OUTPUT_DATA_RATE_200HZ
  3723. * 0x0A | BMI160_GYRO_OUTPUT_DATA_RATE_400HZ
  3724. * 0x0B | BMI160_GYRO_OUTPUT_DATA_RATE_800HZ
  3725. * 0x0C | BMI160_GYRO_OUTPUT_DATA_RATE_1600HZ
  3726. * 0x0D | BMI160_GYRO_OUTPUT_DATA_RATE_3200HZ
  3727. * 0x0E | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3728. * 0x0F | BMI160_GYRO_OUTPUT_DATA_RATE_RESERVED
  3729. *
  3730. * @return results of bus communication function
  3731. * @retval 0 -> Success
  3732. * @retval -1 -> Error
  3733. *
  3734. *
  3735. */
  3736. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_output_data_rate(
  3737. u8 v_output_data_rate_u8)
  3738. {
  3739. /* variable used for return the status of communication result*/
  3740. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3741. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  3742. /* check the p_bmi160 structure as NULL*/
  3743. if (p_bmi160 == BMI160_NULL) {
  3744. return E_BMI160_NULL_PTR;
  3745. } else {
  3746. /* select the gyro output data rate*/
  3747. if ((v_output_data_rate_u8 < C_BMI160_FOURTEEN_U8X) &&
  3748. (v_output_data_rate_u8 != C_BMI160_ZERO_U8X)
  3749. && (v_output_data_rate_u8 != C_BMI160_ONE_U8X)
  3750. && (v_output_data_rate_u8 != C_BMI160_TWO_U8X)
  3751. && (v_output_data_rate_u8 != C_BMI160_THREE_U8X)
  3752. && (v_output_data_rate_u8 != C_BMI160_FOUR_U8X)
  3753. && (v_output_data_rate_u8 != C_BMI160_FIVE_U8X)
  3754. && (v_output_data_rate_u8 != C_BMI160_FOURTEEN_U8X)
  3755. && (v_output_data_rate_u8 != C_BMI160_FIVETEEN_U8X)) {
  3756. /* write the gyro output data rate */
  3757. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  3758. (p_bmi160->dev_addr,
  3759. BMI160_USER_GYRO_CONFIG_OUTPUT_DATA_RATE__REG,
  3760. &v_data_u8, C_BMI160_ONE_U8X);
  3761. if (com_rslt == SUCCESS) {
  3762. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  3763. BMI160_USER_GYRO_CONFIG_OUTPUT_DATA_RATE,
  3764. v_output_data_rate_u8);
  3765. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  3766. (p_bmi160->dev_addr,
  3767. BMI160_USER_GYRO_CONFIG_OUTPUT_DATA_RATE__REG,
  3768. &v_data_u8, C_BMI160_ONE_U8X);
  3769. }
  3770. } else {
  3771. com_rslt = E_BMI160_OUT_OF_RANGE;
  3772. }
  3773. }
  3774. return com_rslt;
  3775. }
  3776. /*!
  3777. * @brief This API is used to get the
  3778. * data of gyro from the register 0x42 bit 4 to 5
  3779. *
  3780. *
  3781. *
  3782. *
  3783. * @param v_bw_u8 : The value of gyro bandwidth
  3784. * value | gyro bandwidth
  3785. * ----------|----------------
  3786. * 0x00 | BMI160_GYRO_OSR4_MODE
  3787. * 0x01 | BMI160_GYRO_OSR2_MODE
  3788. * 0x02 | BMI160_GYRO_NORMAL_MODE
  3789. * 0x03 | BMI160_GYRO_CIC_MODE
  3790. *
  3791. *
  3792. * @return results of bus communication function
  3793. * @retval 0 -> Success
  3794. * @retval -1 -> Error
  3795. *
  3796. *
  3797. */
  3798. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_bw(u8 *v_bw_u8)
  3799. {
  3800. /* variable used for return the status of communication result*/
  3801. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3802. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  3803. /* check the p_bmi160 structure as NULL*/
  3804. if (p_bmi160 == BMI160_NULL) {
  3805. return E_BMI160_NULL_PTR;
  3806. } else {
  3807. /* read gyro bandwidth*/
  3808. com_rslt =
  3809. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3810. BMI160_USER_GYRO_CONFIG_BW__REG, &v_data_u8,
  3811. C_BMI160_ONE_U8X);
  3812. *v_bw_u8 = BMI160_GET_BITSLICE(v_data_u8,
  3813. BMI160_USER_GYRO_CONFIG_BW);
  3814. }
  3815. return com_rslt;
  3816. }
  3817. /*!
  3818. * @brief This API is used to set the
  3819. * data of gyro from the register 0x42 bit 4 to 5
  3820. *
  3821. *
  3822. *
  3823. *
  3824. * @param v_bw_u8 : The value of gyro bandwidth
  3825. * value | gyro bandwidth
  3826. * ----------|----------------
  3827. * 0x00 | BMI160_GYRO_OSR4_MODE
  3828. * 0x01 | BMI160_GYRO_OSR2_MODE
  3829. * 0x02 | BMI160_GYRO_NORMAL_MODE
  3830. * 0x03 | BMI160_GYRO_CIC_MODE
  3831. *
  3832. *
  3833. * @return results of bus communication function
  3834. * @retval 0 -> Success
  3835. * @retval -1 -> Error
  3836. *
  3837. *
  3838. */
  3839. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_bw(u8 v_bw_u8)
  3840. {
  3841. /* variable used for return the status of communication result*/
  3842. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3843. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  3844. /* check the p_bmi160 structure as NULL*/
  3845. if (p_bmi160 == BMI160_NULL) {
  3846. return E_BMI160_NULL_PTR;
  3847. } else {
  3848. if (v_bw_u8 < C_BMI160_FOUR_U8X) {
  3849. /* write the gyro bandwidth*/
  3850. com_rslt =
  3851. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  3852. BMI160_USER_GYRO_CONFIG_BW__REG,
  3853. &v_data_u8, C_BMI160_ONE_U8X);
  3854. if (com_rslt == SUCCESS) {
  3855. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  3856. BMI160_USER_GYRO_CONFIG_BW, v_bw_u8);
  3857. com_rslt +=
  3858. p_bmi160->BMI160_BUS_WRITE_FUNC(
  3859. p_bmi160->dev_addr,
  3860. BMI160_USER_GYRO_CONFIG_BW__REG,
  3861. &v_data_u8, C_BMI160_ONE_U8X);
  3862. }
  3863. } else {
  3864. com_rslt = E_BMI160_OUT_OF_RANGE;
  3865. }
  3866. }
  3867. return com_rslt;
  3868. }
  3869. /*!
  3870. * @brief This API reads the range
  3871. * of gyro from the register 0x43 bit 0 to 2
  3872. *
  3873. * @param v_range_u8 : The value of gyro range
  3874. * value | range
  3875. * ----------|-------------------------------
  3876. * 0x00 | BMI160_GYRO_RANGE_2000_DEG_SEC
  3877. * 0x01 | BMI160_GYRO_RANGE_1000_DEG_SEC
  3878. * 0x02 | BMI160_GYRO_RANGE_500_DEG_SEC
  3879. * 0x03 | BMI160_GYRO_RANGE_250_DEG_SEC
  3880. * 0x04 | BMI160_GYRO_RANGE_125_DEG_SEC
  3881. *
  3882. * @return results of bus communication function
  3883. * @retval 0 -> Success
  3884. * @retval -1 -> Error
  3885. *
  3886. *
  3887. */
  3888. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_range(u8 *v_range_u8)
  3889. {
  3890. /* variable used for return the status of communication result*/
  3891. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3892. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  3893. /* check the p_bmi160 structure as NULL*/
  3894. if (p_bmi160 == BMI160_NULL) {
  3895. return E_BMI160_NULL_PTR;
  3896. } else {
  3897. /* read the gyro range */
  3898. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  3899. (p_bmi160->dev_addr,
  3900. BMI160_USER_GYRO_RANGE__REG,
  3901. &v_data_u8, C_BMI160_ONE_U8X);
  3902. *v_range_u8 =
  3903. BMI160_GET_BITSLICE(v_data_u8,
  3904. BMI160_USER_GYRO_RANGE);
  3905. }
  3906. return com_rslt;
  3907. }
  3908. /*!
  3909. * @brief This API set the range
  3910. * of gyro from the register 0x43 bit 0 to 2
  3911. *
  3912. * @param v_range_u8 : The value of gyro range
  3913. * value | range
  3914. * ----------|-------------------------------
  3915. * 0x00 | BMI160_GYRO_RANGE_2000_DEG_SEC
  3916. * 0x01 | BMI160_GYRO_RANGE_1000_DEG_SEC
  3917. * 0x02 | BMI160_GYRO_RANGE_500_DEG_SEC
  3918. * 0x03 | BMI160_GYRO_RANGE_250_DEG_SEC
  3919. * 0x04 | BMI160_GYRO_RANGE_125_DEG_SEC
  3920. *
  3921. * @return results of bus communication function
  3922. * @retval 0 -> Success
  3923. * @retval -1 -> Error
  3924. *
  3925. *
  3926. */
  3927. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_range(u8 v_range_u8)
  3928. {
  3929. /* variable used for return the status of communication result*/
  3930. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3931. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  3932. /* check the p_bmi160 structure as NULL*/
  3933. if (p_bmi160 == BMI160_NULL) {
  3934. return E_BMI160_NULL_PTR;
  3935. } else {
  3936. if (v_range_u8 < C_BMI160_FIVE_U8X) {
  3937. /* write the gyro range value */
  3938. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  3939. (p_bmi160->dev_addr,
  3940. BMI160_USER_GYRO_RANGE__REG,
  3941. &v_data_u8, C_BMI160_ONE_U8X);
  3942. if (com_rslt == SUCCESS) {
  3943. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  3944. BMI160_USER_GYRO_RANGE,
  3945. v_range_u8);
  3946. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  3947. (p_bmi160->dev_addr,
  3948. BMI160_USER_GYRO_RANGE__REG,
  3949. &v_data_u8, C_BMI160_ONE_U8X);
  3950. }
  3951. } else {
  3952. com_rslt = E_BMI160_OUT_OF_RANGE;
  3953. }
  3954. }
  3955. return com_rslt;
  3956. }
  3957. /*!
  3958. * @brief This API is used to get the
  3959. * output data rate of magnetometer from the register 0x44 bit 0 to 3
  3960. *
  3961. *
  3962. *
  3963. *
  3964. * @param v_output_data_rat_u8e : The value of mag output data rate
  3965. * value | mag output data rate
  3966. * ---------|---------------------------
  3967. * 0x00 |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED
  3968. * 0x01 |BMI160_MAG_OUTPUT_DATA_RATE_0_78HZ
  3969. * 0x02 |BMI160_MAG_OUTPUT_DATA_RATE_1_56HZ
  3970. * 0x03 |BMI160_MAG_OUTPUT_DATA_RATE_3_12HZ
  3971. * 0x04 |BMI160_MAG_OUTPUT_DATA_RATE_6_25HZ
  3972. * 0x05 |BMI160_MAG_OUTPUT_DATA_RATE_12_5HZ
  3973. * 0x06 |BMI160_MAG_OUTPUT_DATA_RATE_25HZ
  3974. * 0x07 |BMI160_MAG_OUTPUT_DATA_RATE_50HZ
  3975. * 0x08 |BMI160_MAG_OUTPUT_DATA_RATE_100HZ
  3976. * 0x09 |BMI160_MAG_OUTPUT_DATA_RATE_200HZ
  3977. * 0x0A |BMI160_MAG_OUTPUT_DATA_RATE_400HZ
  3978. * 0x0B |BMI160_MAG_OUTPUT_DATA_RATE_800HZ
  3979. * 0x0C |BMI160_MAG_OUTPUT_DATA_RATE_1600HZ
  3980. * 0x0D |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED0
  3981. * 0x0E |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED1
  3982. * 0x0F |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED2
  3983. *
  3984. *
  3985. *
  3986. * @return results of bus communication function
  3987. * @retval 0 -> Success
  3988. * @retval -1 -> Error
  3989. *
  3990. *
  3991. */
  3992. BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_output_data_rate(
  3993. u8 *v_output_data_rat_u8e)
  3994. {
  3995. /* variable used for return the status of communication result*/
  3996. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  3997. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  3998. /* check the p_bmi160 structure as NULL*/
  3999. if (p_bmi160 == BMI160_NULL) {
  4000. return E_BMI160_NULL_PTR;
  4001. } else {
  4002. /* read the mag data output rate*/
  4003. com_rslt =
  4004. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4005. BMI160_USER_MAG_CONFIG_OUTPUT_DATA_RATE__REG,
  4006. &v_data_u8, C_BMI160_ONE_U8X);
  4007. *v_output_data_rat_u8e = BMI160_GET_BITSLICE(v_data_u8,
  4008. BMI160_USER_MAG_CONFIG_OUTPUT_DATA_RATE);
  4009. }
  4010. return com_rslt;
  4011. }
  4012. /*!
  4013. * @brief This API is used to set the
  4014. * output data rate of magnetometer from the register 0x44 bit 0 to 3
  4015. *
  4016. *
  4017. *
  4018. *
  4019. * @param v_output_data_rat_u8e : The value of mag output data rate
  4020. * value | mag output data rate
  4021. * ---------|---------------------------
  4022. * 0x00 |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED
  4023. * 0x01 |BMI160_MAG_OUTPUT_DATA_RATE_0_78HZ
  4024. * 0x02 |BMI160_MAG_OUTPUT_DATA_RATE_1_56HZ
  4025. * 0x03 |BMI160_MAG_OUTPUT_DATA_RATE_3_12HZ
  4026. * 0x04 |BMI160_MAG_OUTPUT_DATA_RATE_6_25HZ
  4027. * 0x05 |BMI160_MAG_OUTPUT_DATA_RATE_12_5HZ
  4028. * 0x06 |BMI160_MAG_OUTPUT_DATA_RATE_25HZ
  4029. * 0x07 |BMI160_MAG_OUTPUT_DATA_RATE_50HZ
  4030. * 0x08 |BMI160_MAG_OUTPUT_DATA_RATE_100HZ
  4031. * 0x09 |BMI160_MAG_OUTPUT_DATA_RATE_200HZ
  4032. * 0x0A |BMI160_MAG_OUTPUT_DATA_RATE_400HZ
  4033. * 0x0B |BMI160_MAG_OUTPUT_DATA_RATE_800HZ
  4034. * 0x0C |BMI160_MAG_OUTPUT_DATA_RATE_1600HZ
  4035. * 0x0D |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED0
  4036. * 0x0E |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED1
  4037. * 0x0F |BMI160_MAG_OUTPUT_DATA_RATE_RESERVED2
  4038. *
  4039. *
  4040. *
  4041. * @return results of bus communication function
  4042. * @retval 0 -> Success
  4043. * @retval -1 -> Error
  4044. *
  4045. *
  4046. */
  4047. BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_output_data_rate(
  4048. u8 v_output_data_rat_u8e)
  4049. {
  4050. /* variable used for return the status of communication result*/
  4051. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4052. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  4053. /* check the p_bmi160 structure as NULL*/
  4054. if (p_bmi160 == BMI160_NULL) {
  4055. return E_BMI160_NULL_PTR;
  4056. } else {
  4057. /* select the mag data output rate*/
  4058. if ((v_output_data_rat_u8e < C_BMI160_THIRTEEN_U8X)
  4059. && (v_output_data_rat_u8e != C_BMI160_ZERO_U8X)
  4060. && (v_output_data_rat_u8e != C_BMI160_FOURTEEN_U8X)
  4061. && (v_output_data_rat_u8e != C_BMI160_FIVETEEN_U8X)) {
  4062. /* write the mag data output rate*/
  4063. com_rslt =
  4064. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4065. BMI160_USER_MAG_CONFIG_OUTPUT_DATA_RATE__REG,
  4066. &v_data_u8, C_BMI160_ONE_U8X);
  4067. if (com_rslt == SUCCESS) {
  4068. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  4069. BMI160_USER_MAG_CONFIG_OUTPUT_DATA_RATE,
  4070. v_output_data_rat_u8e);
  4071. com_rslt +=
  4072. p_bmi160->BMI160_BUS_WRITE_FUNC(
  4073. p_bmi160->dev_addr,
  4074. BMI160_USER_MAG_CONFIG_OUTPUT_DATA_RATE__REG,
  4075. &v_data_u8, C_BMI160_ONE_U8X);
  4076. }
  4077. } else {
  4078. com_rslt = E_BMI160_OUT_OF_RANGE;
  4079. }
  4080. }
  4081. return com_rslt;
  4082. }
  4083. /*!
  4084. * @brief This API is used to read Down sampling
  4085. * for gyro (2**downs_gyro) in the register 0x45 bit 0 to 2
  4086. *
  4087. *
  4088. *
  4089. *
  4090. * @param v_fifo_down_gyro_u8 :The value of gyro fifo down
  4091. *
  4092. *
  4093. * @return results of bus communication function
  4094. * @retval 0 -> Success
  4095. * @retval -1 -> Error
  4096. *
  4097. *
  4098. */
  4099. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_down_gyro(
  4100. u8 *v_fifo_down_gyro_u8)
  4101. {
  4102. /* variable used for return the status of communication result*/
  4103. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4104. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  4105. /* check the p_bmi160 structure as NULL*/
  4106. if (p_bmi160 == BMI160_NULL) {
  4107. return E_BMI160_NULL_PTR;
  4108. } else {
  4109. /* read the gyro fifo down*/
  4110. com_rslt =
  4111. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4112. BMI160_USER_FIFO_DOWN_GYRO__REG,
  4113. &v_data_u8, C_BMI160_ONE_U8X);
  4114. *v_fifo_down_gyro_u8 = BMI160_GET_BITSLICE(v_data_u8,
  4115. BMI160_USER_FIFO_DOWN_GYRO);
  4116. }
  4117. return com_rslt;
  4118. }
  4119. /*!
  4120. * @brief This API is used to set Down sampling
  4121. * for gyro (2**downs_gyro) in the register 0x45 bit 0 to 2
  4122. *
  4123. *
  4124. *
  4125. *
  4126. * @param v_fifo_down_gyro_u8 :The value of gyro fifo down
  4127. *
  4128. *
  4129. * @return results of bus communication function
  4130. * @retval 0 -> Success
  4131. * @retval -1 -> Error
  4132. *
  4133. *
  4134. */
  4135. BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_down_gyro(
  4136. u8 v_fifo_down_gyro_u8)
  4137. {
  4138. /* variable used for return the status of communication result*/
  4139. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4140. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  4141. /* check the p_bmi160 structure as NULL*/
  4142. if (p_bmi160 == BMI160_NULL) {
  4143. return E_BMI160_NULL_PTR;
  4144. } else {
  4145. /* write the gyro fifo down*/
  4146. com_rslt =
  4147. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4148. BMI160_USER_FIFO_DOWN_GYRO__REG,
  4149. &v_data_u8, C_BMI160_ONE_U8X);
  4150. if (com_rslt == SUCCESS) {
  4151. v_data_u8 = BMI160_SET_BITSLICE(
  4152. v_data_u8,
  4153. BMI160_USER_FIFO_DOWN_GYRO,
  4154. v_fifo_down_gyro_u8);
  4155. com_rslt +=
  4156. p_bmi160->BMI160_BUS_WRITE_FUNC(
  4157. p_bmi160->dev_addr,
  4158. BMI160_USER_FIFO_DOWN_GYRO__REG,
  4159. &v_data_u8, C_BMI160_ONE_U8X);
  4160. }
  4161. }
  4162. return com_rslt;
  4163. }
  4164. /*!
  4165. * @brief This API is used to read gyro fifo filter data
  4166. * from the register 0x45 bit 3
  4167. *
  4168. *
  4169. *
  4170. * @param v_gyro_fifo_filter_data_u8 :The value of gyro filter data
  4171. * value | gyro_fifo_filter_data
  4172. * ------------|-------------------------
  4173. * 0x00 | Unfiltered data
  4174. * 0x01 | Filtered data
  4175. *
  4176. * @return results of bus communication function
  4177. * @retval 0 -> Success
  4178. * @retval -1 -> Error
  4179. *
  4180. *
  4181. */
  4182. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_fifo_filter_data(
  4183. u8 *v_gyro_fifo_filter_data_u8)
  4184. {
  4185. /* variable used for return the status of communication result*/
  4186. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4187. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  4188. /* check the p_bmi160 structure as NULL*/
  4189. if (p_bmi160 == BMI160_NULL) {
  4190. return E_BMI160_NULL_PTR;
  4191. } else {
  4192. /* read the gyro fifo filter data */
  4193. com_rslt =
  4194. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4195. BMI160_USER_FIFO_FILTER_GYRO__REG, &v_data_u8,
  4196. C_BMI160_ONE_U8X);
  4197. *v_gyro_fifo_filter_data_u8 =
  4198. BMI160_GET_BITSLICE(v_data_u8,
  4199. BMI160_USER_FIFO_FILTER_GYRO);
  4200. }
  4201. return com_rslt;
  4202. }
  4203. /*!
  4204. * @brief This API is used to set gyro fifo filter data
  4205. * from the register 0x45 bit 3
  4206. *
  4207. *
  4208. *
  4209. * @param v_gyro_fifo_filter_data_u8 :The value of gyro filter data
  4210. * value | gyro_fifo_filter_data
  4211. * ------------|-------------------------
  4212. * 0x00 | Unfiltered data
  4213. * 0x01 | Filtered data
  4214. *
  4215. * @return results of bus communication function
  4216. * @retval 0 -> Success
  4217. * @retval -1 -> Error
  4218. *
  4219. *
  4220. */
  4221. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_fifo_filter_data(
  4222. u8 v_gyro_fifo_filter_data_u8)
  4223. {
  4224. /* variable used for return the status of communication result*/
  4225. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4226. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  4227. /* check the p_bmi160 structure as NULL*/
  4228. if (p_bmi160 == BMI160_NULL) {
  4229. return E_BMI160_NULL_PTR;
  4230. } else {
  4231. if (v_gyro_fifo_filter_data_u8 < C_BMI160_TWO_U8X) {
  4232. /* write the gyro fifo filter data */
  4233. com_rslt =
  4234. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4235. BMI160_USER_FIFO_FILTER_GYRO__REG,
  4236. &v_data_u8, C_BMI160_ONE_U8X);
  4237. if (com_rslt == SUCCESS) {
  4238. v_data_u8 = BMI160_SET_BITSLICE(
  4239. v_data_u8,
  4240. BMI160_USER_FIFO_FILTER_GYRO,
  4241. v_gyro_fifo_filter_data_u8);
  4242. com_rslt +=
  4243. p_bmi160->BMI160_BUS_WRITE_FUNC(
  4244. p_bmi160->dev_addr,
  4245. BMI160_USER_FIFO_FILTER_GYRO__REG,
  4246. &v_data_u8, C_BMI160_ONE_U8X);
  4247. }
  4248. } else {
  4249. com_rslt = E_BMI160_OUT_OF_RANGE;
  4250. }
  4251. }
  4252. return com_rslt;
  4253. }
  4254. /*!
  4255. * @brief This API is used to read Down sampling
  4256. * for accel (2*downs_accel) from the register 0x45 bit 4 to 6
  4257. *
  4258. *
  4259. *
  4260. *
  4261. * @param v_fifo_down_u8 :The value of accel fifo down
  4262. *
  4263. *
  4264. *
  4265. * @return results of bus communication function
  4266. * @retval 0 -> Success
  4267. * @retval -1 -> Error
  4268. *
  4269. *
  4270. */
  4271. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_down_accel(
  4272. u8 *v_fifo_down_u8)
  4273. {
  4274. /* variable used for return the status of communication result*/
  4275. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4276. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  4277. /* check the p_bmi160 structure as NULL*/
  4278. if (p_bmi160 == BMI160_NULL) {
  4279. return E_BMI160_NULL_PTR;
  4280. } else {
  4281. /* read the accel fifo down data */
  4282. com_rslt =
  4283. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4284. BMI160_USER_FIFO_DOWN_ACCEL__REG, &v_data_u8,
  4285. C_BMI160_ONE_U8X);
  4286. *v_fifo_down_u8 = BMI160_GET_BITSLICE(v_data_u8,
  4287. BMI160_USER_FIFO_DOWN_ACCEL);
  4288. }
  4289. return com_rslt;
  4290. }
  4291. /*!
  4292. * @brief This API is used to set Down sampling
  4293. * for accel (2*downs_accel) from the register 0x45 bit 4 to 6
  4294. *
  4295. *
  4296. *
  4297. *
  4298. * @param v_fifo_down_u8 :The value of accel fifo down
  4299. *
  4300. *
  4301. *
  4302. * @return results of bus communication function
  4303. * @retval 0 -> Success
  4304. * @retval -1 -> Error
  4305. *
  4306. *
  4307. */
  4308. BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_down_accel(
  4309. u8 v_fifo_down_u8)
  4310. {
  4311. /* variable used for return the status of communication result*/
  4312. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4313. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  4314. /* check the p_bmi160 structure as NULL*/
  4315. if (p_bmi160 == BMI160_NULL) {
  4316. return E_BMI160_NULL_PTR;
  4317. } else {
  4318. /* write the accel fifo down data */
  4319. com_rslt =
  4320. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4321. BMI160_USER_FIFO_DOWN_ACCEL__REG, &v_data_u8,
  4322. C_BMI160_ONE_U8X);
  4323. if (com_rslt == SUCCESS) {
  4324. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  4325. BMI160_USER_FIFO_DOWN_ACCEL, v_fifo_down_u8);
  4326. com_rslt +=
  4327. p_bmi160->BMI160_BUS_WRITE_FUNC(
  4328. p_bmi160->dev_addr,
  4329. BMI160_USER_FIFO_DOWN_ACCEL__REG,
  4330. &v_data_u8, C_BMI160_ONE_U8X);
  4331. }
  4332. }
  4333. return com_rslt;
  4334. }
  4335. /*!
  4336. * @brief This API is used to read accel fifo filter data
  4337. * from the register 0x45 bit 7
  4338. *
  4339. *
  4340. *
  4341. * @param v_accel_fifo_filter_u8 :The value of accel filter data
  4342. * value | accel_fifo_filter_data
  4343. * ------------|-------------------------
  4344. * 0x00 | Unfiltered data
  4345. * 0x01 | Filtered data
  4346. *
  4347. *
  4348. * @return results of bus communication function
  4349. * @retval 0 -> Success
  4350. * @retval -1 -> Error
  4351. *
  4352. *
  4353. */
  4354. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_fifo_filter_data(
  4355. u8 *v_accel_fifo_filter_u8)
  4356. {
  4357. /* variable used for return the status of communication result*/
  4358. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4359. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  4360. /* check the p_bmi160 structure as NULL*/
  4361. if (p_bmi160 == BMI160_NULL) {
  4362. return E_BMI160_NULL_PTR;
  4363. } else {
  4364. /* read the accel fifo filter data */
  4365. com_rslt =
  4366. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4367. BMI160_USER_FIFO_FILTER_ACCEL__REG, &v_data_u8,
  4368. C_BMI160_ONE_U8X);
  4369. *v_accel_fifo_filter_u8 = BMI160_GET_BITSLICE(v_data_u8,
  4370. BMI160_USER_FIFO_FILTER_ACCEL);
  4371. }
  4372. return com_rslt;
  4373. }
  4374. /*!
  4375. * @brief This API is used to set accel fifo filter data
  4376. * from the register 0x45 bit 7
  4377. *
  4378. *
  4379. *
  4380. * @param v_accel_fifo_filter_u8 :The value of accel filter data
  4381. * value | accel_fifo_filter_data
  4382. * ------------|-------------------------
  4383. * 0x00 | Unfiltered data
  4384. * 0x01 | Filtered data
  4385. *
  4386. *
  4387. * @return results of bus communication function
  4388. * @retval 0 -> Success
  4389. * @retval -1 -> Error
  4390. *
  4391. *
  4392. */
  4393. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_fifo_filter_data(
  4394. u8 v_accel_fifo_filter_u8)
  4395. {
  4396. /* variable used for return the status of communication result*/
  4397. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4398. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  4399. /* check the p_bmi160 structure as NULL*/
  4400. if (p_bmi160 == BMI160_NULL) {
  4401. return E_BMI160_NULL_PTR;
  4402. } else {
  4403. if (v_accel_fifo_filter_u8 < C_BMI160_TWO_U8X) {
  4404. com_rslt =
  4405. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4406. BMI160_USER_FIFO_FILTER_ACCEL__REG,
  4407. &v_data_u8, C_BMI160_ONE_U8X);
  4408. if (com_rslt == SUCCESS) {
  4409. /* write accel fifo filter data */
  4410. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  4411. BMI160_USER_FIFO_FILTER_ACCEL,
  4412. v_accel_fifo_filter_u8);
  4413. com_rslt +=
  4414. p_bmi160->BMI160_BUS_WRITE_FUNC(
  4415. p_bmi160->dev_addr,
  4416. BMI160_USER_FIFO_FILTER_ACCEL__REG,
  4417. &v_data_u8, C_BMI160_ONE_U8X);
  4418. }
  4419. } else {
  4420. com_rslt = E_BMI160_OUT_OF_RANGE;
  4421. }
  4422. }
  4423. return com_rslt;
  4424. }
  4425. /*!
  4426. * @brief This API is used to Trigger an interrupt
  4427. * when FIFO contains water mark level from the register 0x46 bit 0 to 7
  4428. *
  4429. *
  4430. *
  4431. * @param v_fifo_wm_u8 : The value of fifo water mark level
  4432. *
  4433. *
  4434. *
  4435. * @return results of bus communication function
  4436. * @retval 0 -> Success
  4437. * @retval -1 -> Error
  4438. *
  4439. *
  4440. */
  4441. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_wm(
  4442. u8 *v_fifo_wm_u8)
  4443. {
  4444. /* variable used for return the status of communication result*/
  4445. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4446. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  4447. /* check the p_bmi160 structure as NULL*/
  4448. if (p_bmi160 == BMI160_NULL) {
  4449. return E_BMI160_NULL_PTR;
  4450. } else {
  4451. /* read the fifo water mark level*/
  4452. com_rslt =
  4453. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4454. BMI160_USER_FIFO_WM__REG,
  4455. &v_data_u8, C_BMI160_ONE_U8X);
  4456. *v_fifo_wm_u8 = BMI160_GET_BITSLICE(v_data_u8,
  4457. BMI160_USER_FIFO_WM);
  4458. }
  4459. return com_rslt;
  4460. }
  4461. /*!
  4462. * @brief This API is used to Trigger an interrupt
  4463. * when FIFO contains water mark level from the register 0x46 bit 0 to 7
  4464. *
  4465. *
  4466. *
  4467. * @param v_fifo_wm_u8 : The value of fifo water mark level
  4468. *
  4469. *
  4470. *
  4471. * @return results of bus communication function
  4472. * @retval 0 -> Success
  4473. * @retval -1 -> Error
  4474. *
  4475. *
  4476. */
  4477. BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_wm(
  4478. u8 v_fifo_wm_u8)
  4479. {
  4480. /* variable used for return the status of communication result*/
  4481. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4482. /* check the p_bmi160 structure as NULL*/
  4483. if (p_bmi160 == BMI160_NULL) {
  4484. return E_BMI160_NULL_PTR;
  4485. } else {
  4486. /* write the fifo water mark level*/
  4487. com_rslt =
  4488. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->dev_addr,
  4489. BMI160_USER_FIFO_WM__REG,
  4490. &v_fifo_wm_u8, C_BMI160_ONE_U8X);
  4491. }
  4492. return com_rslt;
  4493. }
  4494. /*!
  4495. * @brief This API reads the fifo stop on full in the register 0x47 bit 0
  4496. * @brief It stop writing samples into FIFO when FIFO is full
  4497. *
  4498. *
  4499. *
  4500. * @param v_fifo_stop_on_full_u8 :The value of fifo stop on full
  4501. * value | fifo stop on full
  4502. * ------------|-------------------------
  4503. * 0x00 | do not stop writing to FIFO when full
  4504. * 0x01 | Stop writing into FIFO when full.
  4505. *
  4506. * @return results of bus communication function
  4507. * @retval 0 -> Success
  4508. * @retval -1 -> Error
  4509. *
  4510. *
  4511. */
  4512. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_stop_on_full(
  4513. u8 *v_fifo_stop_on_full_u8)
  4514. {
  4515. /* variable used for return the status of communication result*/
  4516. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4517. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  4518. /* check the p_bmi160 structure as NULL*/
  4519. if (p_bmi160 == BMI160_NULL) {
  4520. return E_BMI160_NULL_PTR;
  4521. } else {
  4522. /* read the fifo stop on full data */
  4523. com_rslt =
  4524. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4525. BMI160_USER_FIFO_STOP_ON_FULL__REG, &v_data_u8,
  4526. C_BMI160_ONE_U8X);
  4527. *v_fifo_stop_on_full_u8 = BMI160_GET_BITSLICE(v_data_u8,
  4528. BMI160_USER_FIFO_STOP_ON_FULL);
  4529. }
  4530. return com_rslt;
  4531. }
  4532. /*!
  4533. * @brief This API sey the fifo stop on full in the register 0x47 bit 0
  4534. * @brief It stop writing samples into FIFO when FIFO is full
  4535. *
  4536. *
  4537. *
  4538. * @param v_fifo_stop_on_full_u8 :The value of fifo stop on full
  4539. * value | fifo stop on full
  4540. * ------------|-------------------------
  4541. * 0x00 | do not stop writing to FIFO when full
  4542. * 0x01 | Stop writing into FIFO when full.
  4543. *
  4544. * @return results of bus communication function
  4545. * @retval 0 -> Success
  4546. * @retval -1 -> Error
  4547. *
  4548. *
  4549. */
  4550. BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_stop_on_full(
  4551. u8 v_fifo_stop_on_full_u8)
  4552. {
  4553. /* variable used for return the status of communication result*/
  4554. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4555. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  4556. /* check the p_bmi160 structure as NULL*/
  4557. if (p_bmi160 == BMI160_NULL) {
  4558. return E_BMI160_NULL_PTR;
  4559. } else {
  4560. if (v_fifo_stop_on_full_u8 < C_BMI160_TWO_U8X) {
  4561. /* write fifo stop on full data */
  4562. com_rslt =
  4563. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4564. BMI160_USER_FIFO_STOP_ON_FULL__REG, &v_data_u8,
  4565. C_BMI160_ONE_U8X);
  4566. if (com_rslt == SUCCESS) {
  4567. v_data_u8 =
  4568. BMI160_SET_BITSLICE(v_data_u8,
  4569. BMI160_USER_FIFO_STOP_ON_FULL,
  4570. v_fifo_stop_on_full_u8);
  4571. com_rslt +=
  4572. p_bmi160->BMI160_BUS_WRITE_FUNC
  4573. (p_bmi160->dev_addr,
  4574. BMI160_USER_FIFO_STOP_ON_FULL__REG,
  4575. &v_data_u8, C_BMI160_ONE_U8X);
  4576. }
  4577. } else {
  4578. com_rslt = E_BMI160_OUT_OF_RANGE;
  4579. }
  4580. }
  4581. return com_rslt;
  4582. }
  4583. /*!
  4584. * @brief This API reads fifo sensor time
  4585. * frame after the last valid data frame form the register 0x47 bit 1
  4586. *
  4587. *
  4588. *
  4589. *
  4590. * @param v_fifo_time_enable_u8 : The value of sensor time
  4591. * value | fifo sensor time
  4592. * ------------|-------------------------
  4593. * 0x00 | do not return sensortime frame
  4594. * 0x01 | return sensortime frame
  4595. *
  4596. * @return results of bus communication function
  4597. * @retval 0 -> Success
  4598. * @retval -1 -> Error
  4599. *
  4600. *
  4601. */
  4602. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_time_enable(
  4603. u8 *v_fifo_time_enable_u8)
  4604. {
  4605. /* variable used for return the status of communication result*/
  4606. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4607. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  4608. /* check the p_bmi160 structure as NULL*/
  4609. if (p_bmi160 == BMI160_NULL) {
  4610. return E_BMI160_NULL_PTR;
  4611. } else {
  4612. /* read the fifo sensor time*/
  4613. com_rslt =
  4614. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4615. BMI160_USER_FIFO_TIME_ENABLE__REG, &v_data_u8,
  4616. C_BMI160_ONE_U8X);
  4617. *v_fifo_time_enable_u8 = BMI160_GET_BITSLICE(v_data_u8,
  4618. BMI160_USER_FIFO_TIME_ENABLE);
  4619. }
  4620. return com_rslt;
  4621. }
  4622. /*!
  4623. * @brief This API set fifo sensor time
  4624. * frame after the last valid data frame form the register 0x47 bit 1
  4625. *
  4626. *
  4627. *
  4628. *
  4629. * @param v_fifo_time_enable_u8 : The value of sensor time
  4630. * value | fifo sensor time
  4631. * ------------|-------------------------
  4632. * 0x00 | do not return sensortime frame
  4633. * 0x01 | return sensortime frame
  4634. *
  4635. * @return results of bus communication function
  4636. * @retval 0 -> Success
  4637. * @retval -1 -> Error
  4638. *
  4639. *
  4640. */
  4641. BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_time_enable(
  4642. u8 v_fifo_time_enable_u8)
  4643. {
  4644. /* variable used for return the status of communication result*/
  4645. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4646. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  4647. /* check the p_bmi160 structure as NULL*/
  4648. if (p_bmi160 == BMI160_NULL) {
  4649. return E_BMI160_NULL_PTR;
  4650. } else {
  4651. if (v_fifo_time_enable_u8 < C_BMI160_TWO_U8X) {
  4652. /* write the fifo sensor time*/
  4653. com_rslt =
  4654. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4655. BMI160_USER_FIFO_TIME_ENABLE__REG, &v_data_u8,
  4656. C_BMI160_ONE_U8X);
  4657. if (com_rslt == SUCCESS) {
  4658. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  4659. BMI160_USER_FIFO_TIME_ENABLE,
  4660. v_fifo_time_enable_u8);
  4661. com_rslt +=
  4662. p_bmi160->BMI160_BUS_WRITE_FUNC(
  4663. p_bmi160->dev_addr,
  4664. BMI160_USER_FIFO_TIME_ENABLE__REG,
  4665. &v_data_u8, C_BMI160_ONE_U8X);
  4666. }
  4667. } else {
  4668. com_rslt = E_BMI160_OUT_OF_RANGE;
  4669. }
  4670. }
  4671. return com_rslt;
  4672. }
  4673. /*!
  4674. * @brief This API reads FIFO tag interrupt2 enable status
  4675. * from the resister 0x47 bit 2
  4676. *
  4677. * @param v_fifo_tag_intr2_u8 : The value of fifo tag interrupt
  4678. * value | fifo tag interrupt
  4679. * ----------|-------------------
  4680. * 0x01 | BMI160_ENABLE
  4681. * 0x00 | BMI160_DISABLE
  4682. *
  4683. *
  4684. *
  4685. *
  4686. * @return results of bus communication function
  4687. * @retval 0 -> Success
  4688. * @retval -1 -> Error
  4689. *
  4690. *
  4691. */
  4692. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_tag_intr2_enable(
  4693. u8 *v_fifo_tag_intr2_u8)
  4694. {
  4695. /* variable used for return the status of communication result*/
  4696. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4697. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  4698. /* check the p_bmi160 structure as NULL*/
  4699. if (p_bmi160 == BMI160_NULL) {
  4700. return E_BMI160_NULL_PTR;
  4701. } else {
  4702. /* read the fifo tag interrupt2*/
  4703. com_rslt =
  4704. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4705. BMI160_USER_FIFO_TAG_INTR2_ENABLE__REG, &v_data_u8,
  4706. C_BMI160_ONE_U8X);
  4707. *v_fifo_tag_intr2_u8 = BMI160_GET_BITSLICE(v_data_u8,
  4708. BMI160_USER_FIFO_TAG_INTR2_ENABLE);
  4709. }
  4710. return com_rslt;
  4711. }
  4712. /*!
  4713. * @brief This API set FIFO tag interrupt2 enable status
  4714. * from the resister 0x47 bit 2
  4715. *
  4716. * @param v_fifo_tag_intr2_u8 : The value of fifo tag interrupt
  4717. * value | fifo tag interrupt
  4718. * ----------|-------------------
  4719. * 0x01 | BMI160_ENABLE
  4720. * 0x00 | BMI160_DISABLE
  4721. *
  4722. *
  4723. *
  4724. *
  4725. * @return results of bus communication function
  4726. * @retval 0 -> Success
  4727. * @retval -1 -> Error
  4728. *
  4729. *
  4730. */
  4731. BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_tag_intr2_enable(
  4732. u8 v_fifo_tag_intr2_u8)
  4733. {
  4734. /* variable used for return the status of communication result*/
  4735. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4736. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  4737. /* check the p_bmi160 structure as NULL*/
  4738. if (p_bmi160 == BMI160_NULL) {
  4739. return E_BMI160_NULL_PTR;
  4740. } else {
  4741. if (v_fifo_tag_intr2_u8 < C_BMI160_TWO_U8X) {
  4742. /* write the fifo tag interrupt2*/
  4743. com_rslt = bmi160_set_input_enable(1,
  4744. v_fifo_tag_intr2_u8);
  4745. com_rslt +=
  4746. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4747. BMI160_USER_FIFO_TAG_INTR2_ENABLE__REG, &v_data_u8,
  4748. C_BMI160_ONE_U8X);
  4749. if (com_rslt == SUCCESS) {
  4750. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  4751. BMI160_USER_FIFO_TAG_INTR2_ENABLE,
  4752. v_fifo_tag_intr2_u8);
  4753. com_rslt +=
  4754. p_bmi160->BMI160_BUS_WRITE_FUNC(
  4755. p_bmi160->dev_addr,
  4756. BMI160_USER_FIFO_TAG_INTR2_ENABLE__REG,
  4757. &v_data_u8, C_BMI160_ONE_U8X);
  4758. }
  4759. } else {
  4760. com_rslt = E_BMI160_OUT_OF_RANGE;
  4761. }
  4762. }
  4763. return com_rslt;
  4764. }
  4765. /*!
  4766. * @brief This API get FIFO tag interrupt1 enable status
  4767. * from the resister 0x47 bit 3
  4768. *
  4769. * @param v_fifo_tag_intr1_u8 :The value of fifo tag interrupt1
  4770. * value | fifo tag interrupt
  4771. * ----------|-------------------
  4772. * 0x01 | BMI160_ENABLE
  4773. * 0x00 | BMI160_DISABLE
  4774. *
  4775. * @return results of bus communication function
  4776. * @retval 0 -> Success
  4777. * @retval -1 -> Error
  4778. *
  4779. *
  4780. */
  4781. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_tag_intr1_enable(
  4782. u8 *v_fifo_tag_intr1_u8)
  4783. {
  4784. /* variable used for return the status of communication result*/
  4785. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4786. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  4787. /* check the p_bmi160 structure as NULL*/
  4788. if (p_bmi160 == BMI160_NULL) {
  4789. return E_BMI160_NULL_PTR;
  4790. } else {
  4791. /* read fifo tag interrupt*/
  4792. com_rslt =
  4793. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4794. BMI160_USER_FIFO_TAG_INTR1_ENABLE__REG, &v_data_u8,
  4795. C_BMI160_ONE_U8X);
  4796. *v_fifo_tag_intr1_u8 = BMI160_GET_BITSLICE(v_data_u8,
  4797. BMI160_USER_FIFO_TAG_INTR1_ENABLE);
  4798. }
  4799. return com_rslt;
  4800. }
  4801. /*!
  4802. * @brief This API set FIFO tag interrupt1 enable status
  4803. * from the resister 0x47 bit 3
  4804. *
  4805. * @param v_fifo_tag_intr1_u8 :The value of fifo tag interrupt1
  4806. * value | fifo tag interrupt
  4807. * ----------|-------------------
  4808. * 0x01 | BMI160_ENABLE
  4809. * 0x00 | BMI160_DISABLE
  4810. *
  4811. * @return results of bus communication function
  4812. * @retval 0 -> Success
  4813. * @retval -1 -> Error
  4814. *
  4815. *
  4816. */
  4817. BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_tag_intr1_enable(
  4818. u8 v_fifo_tag_intr1_u8)
  4819. {
  4820. /* variable used for return the status of communication result*/
  4821. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4822. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  4823. /* check the p_bmi160 structure as NULL*/
  4824. if (p_bmi160 == BMI160_NULL) {
  4825. return E_BMI160_NULL_PTR;
  4826. } else {
  4827. if (v_fifo_tag_intr1_u8 < C_BMI160_TWO_U8X) {
  4828. /* write the fifo tag interrupt*/
  4829. com_rslt = bmi160_set_input_enable(C_BMI160_ZERO_U8X,
  4830. v_fifo_tag_intr1_u8);
  4831. com_rslt +=
  4832. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4833. BMI160_USER_FIFO_TAG_INTR1_ENABLE__REG, &v_data_u8,
  4834. C_BMI160_ONE_U8X);
  4835. if (com_rslt == SUCCESS) {
  4836. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  4837. BMI160_USER_FIFO_TAG_INTR1_ENABLE,
  4838. v_fifo_tag_intr1_u8);
  4839. com_rslt +=
  4840. p_bmi160->BMI160_BUS_WRITE_FUNC(
  4841. p_bmi160->dev_addr,
  4842. BMI160_USER_FIFO_TAG_INTR1_ENABLE__REG,
  4843. &v_data_u8, C_BMI160_ONE_U8X);
  4844. }
  4845. } else {
  4846. com_rslt = E_BMI160_OUT_OF_RANGE;
  4847. }
  4848. }
  4849. return com_rslt;
  4850. }
  4851. /*!
  4852. * @brief This API reads FIFO frame
  4853. * header enable from the register 0x47 bit 4
  4854. *
  4855. * @param v_fifo_header_u8 :The value of fifo header
  4856. * value | fifo header
  4857. * ----------|-------------------
  4858. * 0x01 | BMI160_ENABLE
  4859. * 0x00 | BMI160_DISABLE
  4860. *
  4861. * @return results of bus communication function
  4862. * @retval 0 -> Success
  4863. * @retval -1 -> Error
  4864. *
  4865. *
  4866. */
  4867. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_header_enable(
  4868. u8 *v_fifo_header_u8)
  4869. {
  4870. /* variable used for return the status of communication result*/
  4871. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4872. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  4873. /* check the p_bmi160 structure as NULL*/
  4874. if (p_bmi160 == BMI160_NULL) {
  4875. return E_BMI160_NULL_PTR;
  4876. } else {
  4877. /* read fifo header */
  4878. com_rslt =
  4879. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4880. BMI160_USER_FIFO_HEADER_ENABLE__REG, &v_data_u8,
  4881. C_BMI160_ONE_U8X);
  4882. *v_fifo_header_u8 = BMI160_GET_BITSLICE(v_data_u8,
  4883. BMI160_USER_FIFO_HEADER_ENABLE);
  4884. }
  4885. return com_rslt;
  4886. }
  4887. /*!
  4888. * @brief This API set FIFO frame
  4889. * header enable from the register 0x47 bit 4
  4890. *
  4891. * @param v_fifo_header_u8 :The value of fifo header
  4892. * value | fifo header
  4893. * ----------|-------------------
  4894. * 0x01 | BMI160_ENABLE
  4895. * 0x00 | BMI160_DISABLE
  4896. *
  4897. * @return results of bus communication function
  4898. * @retval 0 -> Success
  4899. * @retval -1 -> Error
  4900. *
  4901. *
  4902. */
  4903. BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_header_enable(
  4904. u8 v_fifo_header_u8)
  4905. {
  4906. /* variable used for return the status of communication result*/
  4907. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4908. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  4909. /* check the p_bmi160 structure as NULL*/
  4910. if (p_bmi160 == BMI160_NULL) {
  4911. return E_BMI160_NULL_PTR;
  4912. } else {
  4913. if (v_fifo_header_u8 < C_BMI160_TWO_U8X) {
  4914. /* write the fifo header */
  4915. com_rslt =
  4916. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4917. BMI160_USER_FIFO_HEADER_ENABLE__REG, &v_data_u8,
  4918. C_BMI160_ONE_U8X);
  4919. if (com_rslt == SUCCESS) {
  4920. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  4921. BMI160_USER_FIFO_HEADER_ENABLE,
  4922. v_fifo_header_u8);
  4923. com_rslt +=
  4924. p_bmi160->BMI160_BUS_WRITE_FUNC(
  4925. p_bmi160->dev_addr,
  4926. BMI160_USER_FIFO_HEADER_ENABLE__REG,
  4927. &v_data_u8, C_BMI160_ONE_U8X);
  4928. }
  4929. } else {
  4930. com_rslt = E_BMI160_OUT_OF_RANGE;
  4931. }
  4932. }
  4933. return com_rslt;
  4934. }
  4935. /*!
  4936. * @brief This API is used to read stored
  4937. * magnetometer data in FIFO (all 3 axes) from the register 0x47 bit 5
  4938. *
  4939. * @param v_fifo_mag_u8 : The value of fifo mag enble
  4940. * value | fifo mag
  4941. * ----------|-------------------
  4942. * 0x00 | no magnetometer data is stored
  4943. * 0x01 | magnetometer data is stored
  4944. *
  4945. * @return results of bus communication function
  4946. * @retval 0 -> Success
  4947. * @retval -1 -> Error
  4948. *
  4949. *
  4950. */
  4951. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_mag_enable(
  4952. u8 *v_fifo_mag_u8)
  4953. {
  4954. /* variable used for return the status of communication result*/
  4955. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4956. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  4957. /* check the p_bmi160 structure as NULL*/
  4958. if (p_bmi160 == BMI160_NULL) {
  4959. return E_BMI160_NULL_PTR;
  4960. } else {
  4961. /* read the fifo mag enable*/
  4962. com_rslt =
  4963. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  4964. BMI160_USER_FIFO_MAG_ENABLE__REG, &v_data_u8,
  4965. C_BMI160_ONE_U8X);
  4966. *v_fifo_mag_u8 = BMI160_GET_BITSLICE(v_data_u8,
  4967. BMI160_USER_FIFO_MAG_ENABLE);
  4968. }
  4969. return com_rslt;
  4970. }
  4971. /*!
  4972. * @brief This API is used to set stored
  4973. * magnetometer data in FIFO (all 3 axes) from the register 0x47 bit 5
  4974. *
  4975. * @param v_fifo_mag_u8 : The value of fifo mag enble
  4976. * value | fifo mag
  4977. * ----------|-------------------
  4978. * 0x00 | no magnetometer data is stored
  4979. * 0x01 | magnetometer data is stored
  4980. *
  4981. * @return results of bus communication function
  4982. * @retval 0 -> Success
  4983. * @retval -1 -> Error
  4984. *
  4985. *
  4986. */
  4987. BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_mag_enable(
  4988. u8 v_fifo_mag_u8)
  4989. {
  4990. /* variable used for return the status of communication result*/
  4991. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  4992. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  4993. /* check the p_bmi160 structure as NULL*/
  4994. if (p_bmi160 == BMI160_NULL) {
  4995. return E_BMI160_NULL_PTR;
  4996. } else {
  4997. if (v_fifo_mag_u8 < C_BMI160_TWO_U8X) {
  4998. /* write the fifo mag enable*/
  4999. com_rslt =
  5000. p_bmi160->BMI160_BUS_READ_FUNC
  5001. (p_bmi160->dev_addr,
  5002. BMI160_USER_FIFO_MAG_ENABLE__REG,
  5003. &v_data_u8, C_BMI160_ONE_U8X);
  5004. if (com_rslt == SUCCESS) {
  5005. v_data_u8 =
  5006. BMI160_SET_BITSLICE(v_data_u8,
  5007. BMI160_USER_FIFO_MAG_ENABLE,
  5008. v_fifo_mag_u8);
  5009. com_rslt +=
  5010. p_bmi160->BMI160_BUS_WRITE_FUNC
  5011. (p_bmi160->dev_addr,
  5012. BMI160_USER_FIFO_MAG_ENABLE__REG,
  5013. &v_data_u8, C_BMI160_ONE_U8X);
  5014. }
  5015. } else {
  5016. com_rslt = E_BMI160_OUT_OF_RANGE;
  5017. }
  5018. }
  5019. return com_rslt;
  5020. }
  5021. /*!
  5022. * @brief This API is used to read stored
  5023. * accel data in FIFO (all 3 axes) from the register 0x47 bit 6
  5024. *
  5025. * @param v_fifo_accel_u8 : The value of fifo accel enble
  5026. * value | fifo accel
  5027. * ----------|-------------------
  5028. * 0x00 | no accel data is stored
  5029. * 0x01 | accel data is stored
  5030. *
  5031. *
  5032. *
  5033. * @return results of bus communication function
  5034. * @retval 0 -> Success
  5035. * @retval -1 -> Error
  5036. *
  5037. *
  5038. */
  5039. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_accel_enable(
  5040. u8 *v_fifo_accel_u8)
  5041. {
  5042. /* variable used for return the status of communication result*/
  5043. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5044. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  5045. /* check the p_bmi160 structure as NULL*/
  5046. if (p_bmi160 == BMI160_NULL) {
  5047. return E_BMI160_NULL_PTR;
  5048. } else {
  5049. /* read the accel fifo enable*/
  5050. com_rslt =
  5051. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5052. BMI160_USER_FIFO_ACCEL_ENABLE__REG, &v_data_u8,
  5053. C_BMI160_ONE_U8X);
  5054. *v_fifo_accel_u8 =
  5055. BMI160_GET_BITSLICE(v_data_u8,
  5056. BMI160_USER_FIFO_ACCEL_ENABLE);
  5057. }
  5058. return com_rslt;
  5059. }
  5060. /*!
  5061. * @brief This API is used to set stored
  5062. * accel data in FIFO (all 3 axes) from the register 0x47 bit 6
  5063. *
  5064. * @param v_fifo_accel_u8 : The value of fifo accel enble
  5065. * value | fifo accel
  5066. * ----------|-------------------
  5067. * 0x00 | no accel data is stored
  5068. * 0x01 | accel data is stored
  5069. *
  5070. *
  5071. *
  5072. * @return results of bus communication function
  5073. * @retval 0 -> Success
  5074. * @retval -1 -> Error
  5075. *
  5076. *
  5077. */
  5078. BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_accel_enable(
  5079. u8 v_fifo_accel_u8)
  5080. {
  5081. /* variable used for return the status of communication result*/
  5082. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5083. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  5084. /* check the p_bmi160 structure as NULL*/
  5085. if (p_bmi160 == BMI160_NULL) {
  5086. return E_BMI160_NULL_PTR;
  5087. } else {
  5088. if (v_fifo_accel_u8 < C_BMI160_TWO_U8X) {
  5089. /* write the fifo mag enables*/
  5090. com_rslt =
  5091. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5092. BMI160_USER_FIFO_ACCEL_ENABLE__REG, &v_data_u8,
  5093. C_BMI160_ONE_U8X);
  5094. if (com_rslt == SUCCESS) {
  5095. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  5096. BMI160_USER_FIFO_ACCEL_ENABLE, v_fifo_accel_u8);
  5097. com_rslt +=
  5098. p_bmi160->BMI160_BUS_WRITE_FUNC(
  5099. p_bmi160->dev_addr,
  5100. BMI160_USER_FIFO_ACCEL_ENABLE__REG,
  5101. &v_data_u8, C_BMI160_ONE_U8X);
  5102. }
  5103. } else {
  5104. com_rslt = E_BMI160_OUT_OF_RANGE;
  5105. }
  5106. }
  5107. return com_rslt;
  5108. }
  5109. /*!
  5110. * @brief This API is used to read stored
  5111. * gyro data in FIFO (all 3 axes) from the resister 0x47 bit 7
  5112. *
  5113. *
  5114. * @param v_fifo_gyro_u8 : The value of fifo gyro enble
  5115. * value | fifo gyro
  5116. * ----------|-------------------
  5117. * 0x00 | no gyro data is stored
  5118. * 0x01 | gyro data is stored
  5119. *
  5120. *
  5121. * @return results of bus communication function
  5122. * @retval 0 -> Success
  5123. * @retval -1 -> Error
  5124. *
  5125. *
  5126. */
  5127. BMI160_RETURN_FUNCTION_TYPE bmi160_get_fifo_gyro_enable(
  5128. u8 *v_fifo_gyro_u8)
  5129. {
  5130. /* variable used for return the status of communication result*/
  5131. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5132. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  5133. /* check the p_bmi160 structure as NULL*/
  5134. if (p_bmi160 == BMI160_NULL) {
  5135. return E_BMI160_NULL_PTR;
  5136. } else {
  5137. /* read fifo gyro enable */
  5138. com_rslt =
  5139. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5140. BMI160_USER_FIFO_GYRO_ENABLE__REG, &v_data_u8,
  5141. C_BMI160_ONE_U8X);
  5142. *v_fifo_gyro_u8 = BMI160_GET_BITSLICE(v_data_u8,
  5143. BMI160_USER_FIFO_GYRO_ENABLE);
  5144. }
  5145. return com_rslt;
  5146. }
  5147. /*!
  5148. * @brief This API is used to set stored
  5149. * gyro data in FIFO (all 3 axes) from the resister 0x47 bit 7
  5150. *
  5151. *
  5152. * @param v_fifo_gyro_u8 : The value of fifo gyro enble
  5153. * value | fifo gyro
  5154. * ----------|-------------------
  5155. * 0x00 | no gyro data is stored
  5156. * 0x01 | gyro data is stored
  5157. *
  5158. *
  5159. * @return results of bus communication function
  5160. * @retval 0 -> Success
  5161. * @retval -1 -> Error
  5162. *
  5163. *
  5164. */
  5165. BMI160_RETURN_FUNCTION_TYPE bmi160_set_fifo_gyro_enable(
  5166. u8 v_fifo_gyro_u8)
  5167. {
  5168. /* variable used for return the status of communication result*/
  5169. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5170. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  5171. /* check the p_bmi160 structure as NULL*/
  5172. if (p_bmi160 == BMI160_NULL) {
  5173. return E_BMI160_NULL_PTR;
  5174. } else {
  5175. if (v_fifo_gyro_u8 < C_BMI160_TWO_U8X) {
  5176. /* write fifo gyro enable*/
  5177. com_rslt =
  5178. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5179. BMI160_USER_FIFO_GYRO_ENABLE__REG, &v_data_u8,
  5180. C_BMI160_ONE_U8X);
  5181. if (com_rslt == SUCCESS) {
  5182. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  5183. BMI160_USER_FIFO_GYRO_ENABLE, v_fifo_gyro_u8);
  5184. com_rslt +=
  5185. p_bmi160->BMI160_BUS_WRITE_FUNC(
  5186. p_bmi160->dev_addr,
  5187. BMI160_USER_FIFO_GYRO_ENABLE__REG,
  5188. &v_data_u8, C_BMI160_ONE_U8X);
  5189. }
  5190. } else {
  5191. com_rslt = E_BMI160_OUT_OF_RANGE;
  5192. }
  5193. }
  5194. return com_rslt;
  5195. }
  5196. /*!
  5197. * @brief This API is used to read
  5198. * I2C device address of auxiliary mag from the register 0x4B bit 1 to 7
  5199. *
  5200. *
  5201. *
  5202. *
  5203. * @param v_i2c_device_addr_u8 : The value of mag I2C device address
  5204. *
  5205. *
  5206. * @return results of bus communication function
  5207. * @retval 0 -> Success
  5208. * @retval -1 -> Error
  5209. *
  5210. *
  5211. */
  5212. BMI160_RETURN_FUNCTION_TYPE bmi160_get_i2c_device_addr(
  5213. u8 *v_i2c_device_addr_u8)
  5214. {
  5215. /* variable used for return the status of communication result*/
  5216. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5217. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  5218. /* check the p_bmi160 structure as NULL*/
  5219. if (p_bmi160 == BMI160_NULL) {
  5220. return E_BMI160_NULL_PTR;
  5221. } else {
  5222. /* read the mag I2C device address*/
  5223. com_rslt =
  5224. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5225. BMI160_USER_I2C_DEVICE_ADDR__REG, &v_data_u8,
  5226. C_BMI160_ONE_U8X);
  5227. *v_i2c_device_addr_u8 = BMI160_GET_BITSLICE(v_data_u8,
  5228. BMI160_USER_I2C_DEVICE_ADDR);
  5229. }
  5230. return com_rslt;
  5231. }
  5232. /*!
  5233. * @brief This API is used to set
  5234. * I2C device address of auxiliary mag from the register 0x4B bit 1 to 7
  5235. *
  5236. *
  5237. *
  5238. *
  5239. * @param v_i2c_device_addr_u8 : The value of mag I2C device address
  5240. *
  5241. *
  5242. * @return results of bus communication function
  5243. * @retval 0 -> Success
  5244. * @retval -1 -> Error
  5245. *
  5246. *
  5247. */
  5248. BMI160_RETURN_FUNCTION_TYPE bmi160_set_i2c_device_addr(
  5249. u8 v_i2c_device_addr_u8)
  5250. {
  5251. /* variable used for return the status of communication result*/
  5252. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5253. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  5254. /* check the p_bmi160 structure as NULL*/
  5255. if (p_bmi160 == BMI160_NULL) {
  5256. return E_BMI160_NULL_PTR;
  5257. } else {
  5258. /* write the mag I2C device address*/
  5259. com_rslt =
  5260. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5261. BMI160_USER_I2C_DEVICE_ADDR__REG, &v_data_u8,
  5262. C_BMI160_ONE_U8X);
  5263. if (com_rslt == SUCCESS) {
  5264. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  5265. BMI160_USER_I2C_DEVICE_ADDR,
  5266. v_i2c_device_addr_u8);
  5267. com_rslt +=
  5268. p_bmi160->BMI160_BUS_WRITE_FUNC(
  5269. p_bmi160->dev_addr,
  5270. BMI160_USER_I2C_DEVICE_ADDR__REG,
  5271. &v_data_u8, C_BMI160_ONE_U8X);
  5272. }
  5273. }
  5274. return com_rslt;
  5275. }
  5276. /*!
  5277. * @brief This API is used to read
  5278. * Burst data length (1,2,6,8 byte) from the register 0x4C bit 0 to 1
  5279. *
  5280. *
  5281. *
  5282. *
  5283. * @param v_mag_burst_u8 : The data of mag burst read lenth
  5284. *
  5285. *
  5286. *
  5287. * @return results of bus communication function
  5288. * @retval 0 -> Success
  5289. * @retval -1 -> Error
  5290. *
  5291. *
  5292. */
  5293. BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_burst(
  5294. u8 *v_mag_burst_u8)
  5295. {
  5296. /* variable used for return the status of communication result*/
  5297. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5298. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  5299. /* check the p_bmi160 structure as NULL*/
  5300. if (p_bmi160 == BMI160_NULL) {
  5301. return E_BMI160_NULL_PTR;
  5302. } else {
  5303. /* read mag burst mode length*/
  5304. com_rslt =
  5305. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5306. BMI160_USER_MAG_BURST__REG,
  5307. &v_data_u8, C_BMI160_ONE_U8X);
  5308. *v_mag_burst_u8 = BMI160_GET_BITSLICE(v_data_u8,
  5309. BMI160_USER_MAG_BURST);
  5310. }
  5311. return com_rslt;
  5312. }
  5313. /*!
  5314. * @brief This API is used to set
  5315. * Burst data length (1,2,6,8 byte) from the register 0x4C bit 0 to 1
  5316. *
  5317. *
  5318. *
  5319. *
  5320. * @param v_mag_burst_u8 : The data of mag burst read lenth
  5321. *
  5322. *
  5323. *
  5324. * @return results of bus communication function
  5325. * @retval 0 -> Success
  5326. * @retval -1 -> Error
  5327. *
  5328. *
  5329. */
  5330. BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_burst(
  5331. u8 v_mag_burst_u8)
  5332. {
  5333. /* variable used for return the status of communication result*/
  5334. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5335. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  5336. /* check the p_bmi160 structure as NULL*/
  5337. if (p_bmi160 == BMI160_NULL) {
  5338. return E_BMI160_NULL_PTR;
  5339. } else {
  5340. /* write mag burst mode length*/
  5341. com_rslt =
  5342. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5343. BMI160_USER_MAG_BURST__REG,
  5344. &v_data_u8, C_BMI160_ONE_U8X);
  5345. if (com_rslt == SUCCESS) {
  5346. v_data_u8 =
  5347. BMI160_SET_BITSLICE(v_data_u8,
  5348. BMI160_USER_MAG_BURST, v_mag_burst_u8);
  5349. com_rslt +=
  5350. p_bmi160->BMI160_BUS_WRITE_FUNC(
  5351. p_bmi160->dev_addr,
  5352. BMI160_USER_MAG_BURST__REG, &v_data_u8,
  5353. C_BMI160_ONE_U8X);
  5354. }
  5355. }
  5356. return com_rslt;
  5357. }
  5358. /*!
  5359. * @brief This API is used to read
  5360. * trigger-readout offset in units of 2.5 ms. If set to zero,
  5361. * the offset is maximum, i.e. after readout a trigger
  5362. * is issued immediately. from the register 0x4C bit 2 to 5
  5363. *
  5364. *
  5365. *
  5366. *
  5367. * @param v_mag_offset_u8 : The value of mag offset
  5368. *
  5369. *
  5370. *
  5371. * @return results of bus communication function
  5372. * @retval 0 -> Success
  5373. * @retval -1 -> Error
  5374. *
  5375. *
  5376. */
  5377. BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_offset(
  5378. u8 *v_mag_offset_u8)
  5379. {
  5380. /* variable used for return the status of communication result*/
  5381. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5382. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  5383. /* check the p_bmi160 structure as NULL*/
  5384. if (p_bmi160 == BMI160_NULL) {
  5385. return E_BMI160_NULL_PTR;
  5386. } else {
  5387. com_rslt =
  5388. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5389. BMI160_USER_MAG_OFFSET__REG,
  5390. &v_data_u8, C_BMI160_ONE_U8X);
  5391. *v_mag_offset_u8 =
  5392. BMI160_GET_BITSLICE(v_data_u8,
  5393. BMI160_USER_MAG_OFFSET);
  5394. }
  5395. return com_rslt;
  5396. }
  5397. /*!
  5398. * @brief This API is used to set
  5399. * trigger-readout offset in units of 2.5 ms. If set to zero,
  5400. * the offset is maximum, i.e. after readout a trigger
  5401. * is issued immediately. from the register 0x4C bit 2 to 5
  5402. *
  5403. *
  5404. *
  5405. *
  5406. * @param v_mag_offset_u8 : The value of mag offset
  5407. *
  5408. *
  5409. *
  5410. * @return results of bus communication function
  5411. * @retval 0 -> Success
  5412. * @retval -1 -> Error
  5413. *
  5414. *
  5415. */
  5416. BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_offset(
  5417. u8 v_mag_offset_u8)
  5418. {
  5419. /* variable used for return the status of communication result*/
  5420. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5421. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  5422. /* check the p_bmi160 structure as NULL*/
  5423. if (p_bmi160 == BMI160_NULL) {
  5424. return E_BMI160_NULL_PTR;
  5425. } else {
  5426. com_rslt =
  5427. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5428. BMI160_USER_MAG_OFFSET__REG, &v_data_u8, C_BMI160_ONE_U8X);
  5429. if (com_rslt == SUCCESS) {
  5430. v_data_u8 =
  5431. BMI160_SET_BITSLICE(v_data_u8,
  5432. BMI160_USER_MAG_OFFSET, v_mag_offset_u8);
  5433. com_rslt +=
  5434. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->dev_addr,
  5435. BMI160_USER_MAG_OFFSET__REG,
  5436. &v_data_u8, C_BMI160_ONE_U8X);
  5437. }
  5438. }
  5439. return com_rslt;
  5440. }
  5441. /*!
  5442. * @brief This API is used to read
  5443. * Enable register access on MAG_IF[2] or MAG_IF[3] writes.
  5444. * This implies that the DATA registers are not updated with
  5445. * magnetometer values. Accessing magnetometer requires
  5446. * the magnetometer in normal mode in PMU_STATUS.
  5447. * from the register 0x4C bit 7
  5448. *
  5449. *
  5450. *
  5451. * @param v_mag_manual_u8 : The value of mag manual enable
  5452. * value | mag manual
  5453. * ----------|-------------------
  5454. * 0x01 | BMI160_ENABLE
  5455. * 0x00 | BMI160_DISABLE
  5456. *
  5457. *
  5458. *
  5459. * @return results of bus communication function
  5460. * @retval 0 -> Success
  5461. * @retval -1 -> Error
  5462. *
  5463. *
  5464. */
  5465. BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_manual_enable(
  5466. u8 *v_mag_manual_u8)
  5467. {
  5468. /* variable used for return the status of communication result*/
  5469. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5470. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  5471. /* check the p_bmi160 structure as NULL*/
  5472. if (p_bmi160 == BMI160_NULL) {
  5473. return E_BMI160_NULL_PTR;
  5474. } else {
  5475. /* read mag manual */
  5476. com_rslt =
  5477. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5478. BMI160_USER_MAG_MANUAL_ENABLE__REG, &v_data_u8,
  5479. C_BMI160_ONE_U8X);
  5480. *v_mag_manual_u8 =
  5481. BMI160_GET_BITSLICE(v_data_u8,
  5482. BMI160_USER_MAG_MANUAL_ENABLE);
  5483. }
  5484. return com_rslt;
  5485. }
  5486. /*!
  5487. * @brief This API is used to set
  5488. * Enable register access on MAG_IF[2] or MAG_IF[3] writes.
  5489. * This implies that the DATA registers are not updated with
  5490. * magnetometer values. Accessing magnetometer requires
  5491. * the magnetometer in normal mode in PMU_STATUS.
  5492. * from the register 0x4C bit 7
  5493. *
  5494. *
  5495. *
  5496. * @param v_mag_manual_u8 : The value of mag manual enable
  5497. * value | mag manual
  5498. * ----------|-------------------
  5499. * 0x01 | BMI160_ENABLE
  5500. * 0x00 | BMI160_DISABLE
  5501. *
  5502. *
  5503. *
  5504. * @return results of bus communication function
  5505. * @retval 0 -> Success
  5506. * @retval -1 -> Error
  5507. *
  5508. *
  5509. */
  5510. BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_manual_enable(
  5511. u8 v_mag_manual_u8)
  5512. {
  5513. /* variable used for return the status of communication result*/
  5514. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5515. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  5516. /* check the p_bmi160 structure as NULL*/
  5517. if (p_bmi160 == BMI160_NULL) {
  5518. return E_BMI160_NULL_PTR;
  5519. } else {
  5520. /* write the mag manual*/
  5521. com_rslt =
  5522. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5523. BMI160_USER_MAG_MANUAL_ENABLE__REG, &v_data_u8,
  5524. C_BMI160_ONE_U8X);
  5525. if (com_rslt == SUCCESS) {
  5526. /* set the bit of mag manual enable*/
  5527. v_data_u8 =
  5528. BMI160_SET_BITSLICE(v_data_u8,
  5529. BMI160_USER_MAG_MANUAL_ENABLE, v_mag_manual_u8);
  5530. com_rslt +=
  5531. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->dev_addr,
  5532. BMI160_USER_MAG_MANUAL_ENABLE__REG, &v_data_u8,
  5533. C_BMI160_ONE_U8X);
  5534. }
  5535. if (com_rslt == SUCCESS)
  5536. p_bmi160->mag_manual_enable = v_mag_manual_u8;
  5537. }
  5538. return com_rslt;
  5539. }
  5540. /*!
  5541. * @brief This API is used to read data
  5542. * magnetometer address to read from the register 0x4D bit 0 to 7
  5543. * @brief It used to provide mag read address of auxiliary mag
  5544. *
  5545. *
  5546. *
  5547. *
  5548. * @param v_mag_read_addr_u8 : The value of address need to be read
  5549. *
  5550. *
  5551. *
  5552. * @return results of bus communication function
  5553. * @retval 0 -> Success
  5554. * @retval -1 -> Error
  5555. *
  5556. *
  5557. */
  5558. BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_read_addr(
  5559. u8 *v_mag_read_addr_u8)
  5560. {
  5561. /* variable used for return the status of communication result*/
  5562. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5563. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  5564. /* check the p_bmi160 structure as NULL*/
  5565. if (p_bmi160 == BMI160_NULL) {
  5566. return E_BMI160_NULL_PTR;
  5567. } else {
  5568. /* read the written address*/
  5569. com_rslt =
  5570. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5571. BMI160_USER_READ_ADDR__REG,
  5572. &v_data_u8, C_BMI160_ONE_U8X);
  5573. *v_mag_read_addr_u8 =
  5574. BMI160_GET_BITSLICE(v_data_u8,
  5575. BMI160_USER_READ_ADDR);
  5576. }
  5577. return com_rslt;
  5578. }
  5579. /*!
  5580. * @brief This API is used to set
  5581. * magnetometer write address from the register 0x4D bit 0 to 7
  5582. * @brief mag write address writes the address of auxiliary mag to write
  5583. *
  5584. *
  5585. *
  5586. * @param v_mag_read_addr_u8:
  5587. * The data of auxiliary mag address to write data
  5588. *
  5589. *
  5590. * @return results of bus communication function
  5591. * @retval 0 -> Success
  5592. * @retval -1 -> Error
  5593. *
  5594. *
  5595. */
  5596. BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_read_addr(
  5597. u8 v_mag_read_addr_u8)
  5598. {
  5599. /* variable used for return the status of communication result*/
  5600. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5601. /* check the p_bmi160 structure as NULL*/
  5602. if (p_bmi160 == BMI160_NULL) {
  5603. return E_BMI160_NULL_PTR;
  5604. } else {
  5605. /* write the mag read address*/
  5606. com_rslt =
  5607. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->dev_addr,
  5608. BMI160_USER_READ_ADDR__REG, &v_mag_read_addr_u8,
  5609. C_BMI160_ONE_U8X);
  5610. }
  5611. return com_rslt;
  5612. }
  5613. /*!
  5614. * @brief This API is used to read
  5615. * magnetometer write address from the register 0x4E bit 0 to 7
  5616. * @brief mag write address writes the address of auxiliary mag to write
  5617. *
  5618. *
  5619. *
  5620. * @param v_mag_write_addr_u8:
  5621. * The data of auxiliary mag address to write data
  5622. *
  5623. *
  5624. * @return results of bus communication function
  5625. * @retval 0 -> Success
  5626. * @retval -1 -> Error
  5627. *
  5628. *
  5629. */
  5630. BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_write_addr(
  5631. u8 *v_mag_write_addr_u8)
  5632. {
  5633. /* variable used for return the status of communication result*/
  5634. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5635. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  5636. /* check the p_bmi160 structure as NULL*/
  5637. if (p_bmi160 == BMI160_NULL) {
  5638. return E_BMI160_NULL_PTR;
  5639. } else {
  5640. /* read the address of last written */
  5641. com_rslt =
  5642. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5643. BMI160_USER_WRITE_ADDR__REG,
  5644. &v_data_u8, C_BMI160_ONE_U8X);
  5645. *v_mag_write_addr_u8 =
  5646. BMI160_GET_BITSLICE(v_data_u8,
  5647. BMI160_USER_WRITE_ADDR);
  5648. }
  5649. return com_rslt;
  5650. }
  5651. /*!
  5652. * @brief This API is used to set
  5653. * magnetometer write address from the register 0x4E bit 0 to 7
  5654. * @brief mag write address writes the address of auxiliary mag to write
  5655. *
  5656. *
  5657. *
  5658. * @param v_mag_write_addr_u8:
  5659. * The data of auxiliary mag address to write data
  5660. *
  5661. *
  5662. * @return results of bus communication function
  5663. * @retval 0 -> Success
  5664. * @retval -1 -> Error
  5665. *
  5666. *
  5667. */
  5668. BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_write_addr(
  5669. u8 v_mag_write_addr_u8)
  5670. {
  5671. /* variable used for return the status of communication result*/
  5672. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5673. /* check the p_bmi160 structure as NULL*/
  5674. if (p_bmi160 == BMI160_NULL) {
  5675. return E_BMI160_NULL_PTR;
  5676. } else {
  5677. /* write the data of mag address to write data */
  5678. com_rslt =
  5679. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->dev_addr,
  5680. BMI160_USER_WRITE_ADDR__REG, &v_mag_write_addr_u8,
  5681. C_BMI160_ONE_U8X);
  5682. }
  5683. return com_rslt;
  5684. }
  5685. /*!
  5686. * @brief This API is used to read magnetometer write data
  5687. * form the resister 0x4F bit 0 to 7
  5688. * @brief This writes the data will be wrote to mag
  5689. *
  5690. *
  5691. *
  5692. * @param v_mag_write_data_u8: The value of mag data
  5693. *
  5694. *
  5695. *
  5696. * @return results of bus communication function
  5697. * @retval 0 -> Success
  5698. * @retval -1 -> Error
  5699. *
  5700. *
  5701. */
  5702. BMI160_RETURN_FUNCTION_TYPE bmi160_get_mag_write_data(
  5703. u8 *v_mag_write_data_u8)
  5704. {
  5705. /* variable used for return the status of communication result*/
  5706. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5707. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  5708. /* check the p_bmi160 structure as NULL*/
  5709. if (p_bmi160 == BMI160_NULL) {
  5710. return E_BMI160_NULL_PTR;
  5711. } else {
  5712. com_rslt =
  5713. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  5714. BMI160_USER_WRITE_DATA__REG, &v_data_u8,
  5715. C_BMI160_ONE_U8X);
  5716. *v_mag_write_data_u8 =
  5717. BMI160_GET_BITSLICE(v_data_u8,
  5718. BMI160_USER_WRITE_DATA);
  5719. }
  5720. return com_rslt;
  5721. }
  5722. /*!
  5723. * @brief This API is used to set magnetometer write data
  5724. * form the resister 0x4F bit 0 to 7
  5725. * @brief This writes the data will be wrote to mag
  5726. *
  5727. *
  5728. *
  5729. * @param v_mag_write_data_u8: The value of mag data
  5730. *
  5731. *
  5732. *
  5733. * @return results of bus communication function
  5734. * @retval 0 -> Success
  5735. * @retval -1 -> Error
  5736. *
  5737. *
  5738. */
  5739. BMI160_RETURN_FUNCTION_TYPE bmi160_set_mag_write_data(
  5740. u8 v_mag_write_data_u8)
  5741. {
  5742. /* variable used for return the status of communication result*/
  5743. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5744. /* check the p_bmi160 structure as NULL*/
  5745. if (p_bmi160 == BMI160_NULL) {
  5746. return E_BMI160_NULL_PTR;
  5747. } else {
  5748. com_rslt =
  5749. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->dev_addr,
  5750. BMI160_USER_WRITE_DATA__REG, &v_mag_write_data_u8,
  5751. C_BMI160_ONE_U8X);
  5752. }
  5753. return com_rslt;
  5754. }
  5755. /*!
  5756. * @brief This API is used to read
  5757. * interrupt enable from the register 0x50 bit 0 to 7
  5758. *
  5759. *
  5760. *
  5761. *
  5762. * @param v_enable_u8 : Value to decided to select interrupt
  5763. * v_enable_u8 | interrupt
  5764. * ---------------|---------------
  5765. * 0 | BMI160_ANY_MOTION_X_ENABLE
  5766. * 1 | BMI160_ANY_MOTION_Y_ENABLE
  5767. * 2 | BMI160_ANY_MOTION_Z_ENABLE
  5768. * 3 | BMI160_DOUBLE_TAP_ENABLE
  5769. * 4 | BMI160_SINGLE_TAP_ENABLE
  5770. * 5 | BMI160_ORIENT_ENABLE
  5771. * 6 | BMI160_FLAT_ENABLE
  5772. *
  5773. * @param v_intr_enable_zero_u8 : The interrupt enable value
  5774. * value | interrupt enable
  5775. * ----------|-------------------
  5776. * 0x01 | BMI160_ENABLE
  5777. * 0x00 | BMI160_DISABLE
  5778. *
  5779. *
  5780. *
  5781. * @return results of bus communication function
  5782. * @retval 0 -> Success
  5783. * @retval -1 -> Error
  5784. *
  5785. *
  5786. */
  5787. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_enable_0(
  5788. u8 v_enable_u8, u8 *v_intr_enable_zero_u8)
  5789. {
  5790. /* variable used for return the status of communication result*/
  5791. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5792. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  5793. /* check the p_bmi160 structure as NULL*/
  5794. if (p_bmi160 == BMI160_NULL) {
  5795. return E_BMI160_NULL_PTR;
  5796. } else {
  5797. /* select interrupt to read*/
  5798. switch (v_enable_u8) {
  5799. case BMI160_ANY_MOTION_X_ENABLE:
  5800. /* read the any motion interrupt x data */
  5801. com_rslt =
  5802. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  5803. dev_addr,
  5804. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE__REG,
  5805. &v_data_u8, C_BMI160_ONE_U8X);
  5806. *v_intr_enable_zero_u8 =
  5807. BMI160_GET_BITSLICE(v_data_u8,
  5808. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE);
  5809. break;
  5810. case BMI160_ANY_MOTION_Y_ENABLE:
  5811. /* read the any motion interrupt y data */
  5812. com_rslt =
  5813. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  5814. dev_addr,
  5815. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE__REG,
  5816. &v_data_u8, C_BMI160_ONE_U8X);
  5817. *v_intr_enable_zero_u8 =
  5818. BMI160_GET_BITSLICE(v_data_u8,
  5819. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE);
  5820. break;
  5821. case BMI160_ANY_MOTION_Z_ENABLE:
  5822. /* read the any motion interrupt z data */
  5823. com_rslt =
  5824. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  5825. dev_addr,
  5826. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE__REG,
  5827. &v_data_u8, C_BMI160_ONE_U8X);
  5828. *v_intr_enable_zero_u8 =
  5829. BMI160_GET_BITSLICE(v_data_u8,
  5830. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE);
  5831. break;
  5832. case BMI160_DOUBLE_TAP_ENABLE:
  5833. /* read the double tap interrupt data */
  5834. com_rslt =
  5835. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  5836. dev_addr,
  5837. BMI160_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE__REG,
  5838. &v_data_u8, C_BMI160_ONE_U8X);
  5839. *v_intr_enable_zero_u8 =
  5840. BMI160_GET_BITSLICE(v_data_u8,
  5841. BMI160_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE);
  5842. break;
  5843. case BMI160_SINGLE_TAP_ENABLE:
  5844. /* read the single tap interrupt data */
  5845. com_rslt =
  5846. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  5847. dev_addr,
  5848. BMI160_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE__REG,
  5849. &v_data_u8, C_BMI160_ONE_U8X);
  5850. *v_intr_enable_zero_u8 =
  5851. BMI160_GET_BITSLICE(v_data_u8,
  5852. BMI160_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE);
  5853. break;
  5854. case BMI160_ORIENT_ENABLE:
  5855. /* read the orient interrupt data */
  5856. com_rslt =
  5857. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  5858. dev_addr, BMI160_USER_INTR_ENABLE_0_ORIENT_ENABLE__REG,
  5859. &v_data_u8, C_BMI160_ONE_U8X);
  5860. *v_intr_enable_zero_u8 =
  5861. BMI160_GET_BITSLICE(v_data_u8,
  5862. BMI160_USER_INTR_ENABLE_0_ORIENT_ENABLE);
  5863. break;
  5864. case BMI160_FLAT_ENABLE:
  5865. /* read the flat interrupt data */
  5866. com_rslt =
  5867. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  5868. dev_addr, BMI160_USER_INTR_ENABLE_0_FLAT_ENABLE__REG,
  5869. &v_data_u8, C_BMI160_ONE_U8X);
  5870. *v_intr_enable_zero_u8 =
  5871. BMI160_GET_BITSLICE(v_data_u8,
  5872. BMI160_USER_INTR_ENABLE_0_FLAT_ENABLE);
  5873. break;
  5874. default:
  5875. com_rslt = E_BMI160_OUT_OF_RANGE;
  5876. break;
  5877. }
  5878. }
  5879. return com_rslt;
  5880. }
  5881. /*!
  5882. * @brief This API is used to set
  5883. * interrupt enable from the register 0x50 bit 0 to 7
  5884. *
  5885. *
  5886. *
  5887. *
  5888. * @param v_enable_u8 : Value to decided to select interrupt
  5889. * v_enable_u8 | interrupt
  5890. * ---------------|---------------
  5891. * 0 | BMI160_ANY_MOTION_X_ENABLE
  5892. * 1 | BMI160_ANY_MOTION_Y_ENABLE
  5893. * 2 | BMI160_ANY_MOTION_Z_ENABLE
  5894. * 3 | BMI160_DOUBLE_TAP_ENABLE
  5895. * 4 | BMI160_SINGLE_TAP_ENABLE
  5896. * 5 | BMI160_ORIENT_ENABLE
  5897. * 6 | BMI160_FLAT_ENABLE
  5898. *
  5899. * @param v_intr_enable_zero_u8 : The interrupt enable value
  5900. * value | interrupt enable
  5901. * ----------|-------------------
  5902. * 0x01 | BMI160_ENABLE
  5903. * 0x00 | BMI160_DISABLE
  5904. *
  5905. *
  5906. *
  5907. * @return results of bus communication function
  5908. * @retval 0 -> Success
  5909. * @retval -1 -> Error
  5910. *
  5911. *
  5912. */
  5913. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_enable_0(
  5914. u8 v_enable_u8, u8 v_intr_enable_zero_u8)
  5915. {
  5916. /* variable used for return the status of communication result*/
  5917. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  5918. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  5919. /* check the p_bmi160 structure as NULL*/
  5920. if (p_bmi160 == BMI160_NULL) {
  5921. return E_BMI160_NULL_PTR;
  5922. } else {
  5923. switch (v_enable_u8) {
  5924. case BMI160_ANY_MOTION_X_ENABLE:
  5925. /* write any motion x*/
  5926. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  5927. dev_addr, BMI160_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE__REG,
  5928. &v_data_u8, C_BMI160_ONE_U8X);
  5929. if (com_rslt == SUCCESS) {
  5930. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  5931. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE,
  5932. v_intr_enable_zero_u8);
  5933. com_rslt +=
  5934. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  5935. dev_addr,
  5936. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_X_ENABLE__REG,
  5937. &v_data_u8, C_BMI160_ONE_U8X);
  5938. }
  5939. break;
  5940. case BMI160_ANY_MOTION_Y_ENABLE:
  5941. /* write any motion y*/
  5942. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  5943. dev_addr, BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE__REG,
  5944. &v_data_u8, C_BMI160_ONE_U8X);
  5945. if (com_rslt == SUCCESS) {
  5946. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  5947. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE,
  5948. v_intr_enable_zero_u8);
  5949. com_rslt +=
  5950. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  5951. dev_addr,
  5952. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Y_ENABLE__REG,
  5953. &v_data_u8, C_BMI160_ONE_U8X);
  5954. }
  5955. break;
  5956. case BMI160_ANY_MOTION_Z_ENABLE:
  5957. /* write any motion z*/
  5958. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  5959. dev_addr, BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE__REG,
  5960. &v_data_u8, C_BMI160_ONE_U8X);
  5961. if (com_rslt == SUCCESS) {
  5962. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  5963. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE,
  5964. v_intr_enable_zero_u8);
  5965. com_rslt +=
  5966. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  5967. dev_addr,
  5968. BMI160_USER_INTR_ENABLE_0_ANY_MOTION_Z_ENABLE__REG,
  5969. &v_data_u8, C_BMI160_ONE_U8X);
  5970. }
  5971. break;
  5972. case BMI160_DOUBLE_TAP_ENABLE:
  5973. /* write double tap*/
  5974. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  5975. dev_addr, BMI160_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE__REG,
  5976. &v_data_u8, C_BMI160_ONE_U8X);
  5977. if (com_rslt == SUCCESS) {
  5978. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  5979. BMI160_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE,
  5980. v_intr_enable_zero_u8);
  5981. com_rslt +=
  5982. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  5983. dev_addr,
  5984. BMI160_USER_INTR_ENABLE_0_DOUBLE_TAP_ENABLE__REG,
  5985. &v_data_u8, C_BMI160_ONE_U8X);
  5986. }
  5987. break;
  5988. case BMI160_SINGLE_TAP_ENABLE:
  5989. /* write single tap */
  5990. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  5991. dev_addr, BMI160_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE__REG,
  5992. &v_data_u8, C_BMI160_ONE_U8X);
  5993. if (com_rslt == SUCCESS) {
  5994. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  5995. BMI160_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE,
  5996. v_intr_enable_zero_u8);
  5997. com_rslt +=
  5998. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  5999. dev_addr,
  6000. BMI160_USER_INTR_ENABLE_0_SINGLE_TAP_ENABLE__REG,
  6001. &v_data_u8, C_BMI160_ONE_U8X);
  6002. }
  6003. break;
  6004. case BMI160_ORIENT_ENABLE:
  6005. /* write orient interrupt*/
  6006. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6007. dev_addr, BMI160_USER_INTR_ENABLE_0_ORIENT_ENABLE__REG,
  6008. &v_data_u8, C_BMI160_ONE_U8X);
  6009. if (com_rslt == SUCCESS) {
  6010. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6011. BMI160_USER_INTR_ENABLE_0_ORIENT_ENABLE,
  6012. v_intr_enable_zero_u8);
  6013. com_rslt +=
  6014. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6015. dev_addr,
  6016. BMI160_USER_INTR_ENABLE_0_ORIENT_ENABLE__REG,
  6017. &v_data_u8, C_BMI160_ONE_U8X);
  6018. }
  6019. break;
  6020. case BMI160_FLAT_ENABLE:
  6021. /* write flat interrupt*/
  6022. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6023. dev_addr, BMI160_USER_INTR_ENABLE_0_FLAT_ENABLE__REG,
  6024. &v_data_u8, C_BMI160_ONE_U8X);
  6025. if (com_rslt == SUCCESS) {
  6026. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6027. BMI160_USER_INTR_ENABLE_0_FLAT_ENABLE,
  6028. v_intr_enable_zero_u8);
  6029. com_rslt +=
  6030. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6031. dev_addr,
  6032. BMI160_USER_INTR_ENABLE_0_FLAT_ENABLE__REG,
  6033. &v_data_u8, C_BMI160_ONE_U8X);
  6034. }
  6035. break;
  6036. default:
  6037. com_rslt = E_BMI160_OUT_OF_RANGE;
  6038. break;
  6039. }
  6040. }
  6041. return com_rslt;
  6042. }
  6043. /*!
  6044. * @brief This API is used to read
  6045. * interrupt enable byte1 from the register 0x51 bit 0 to 6
  6046. * @brief It read the high_g_x,high_g_y,high_g_z,low_g_enable
  6047. * data ready, fifo full and fifo water mark.
  6048. *
  6049. *
  6050. *
  6051. * @param v_enable_u8 : The value of interrupt enable
  6052. * @param v_enable_u8 : Value to decided to select interrupt
  6053. * v_enable_u8 | interrupt
  6054. * ---------------|---------------
  6055. * 0 | BMI160_HIGH_G_X_ENABLE
  6056. * 1 | BMI160_HIGH_G_Y_ENABLE
  6057. * 2 | BMI160_HIGH_G_Z_ENABLE
  6058. * 3 | BMI160_LOW_G_ENABLE
  6059. * 4 | BMI160_DATA_RDY_ENABLE
  6060. * 5 | BMI160_FIFO_FULL_ENABLE
  6061. * 6 | BMI160_FIFO_WM_ENABLE
  6062. *
  6063. * @param v_intr_enable_1_u8 : The interrupt enable value
  6064. * value | interrupt enable
  6065. * ----------|-------------------
  6066. * 0x01 | BMI160_ENABLE
  6067. * 0x00 | BMI160_DISABLE
  6068. *
  6069. *
  6070. *
  6071. * @return results of bus communication function
  6072. * @retval 0 -> Success
  6073. * @retval -1 -> Error
  6074. *
  6075. *
  6076. */
  6077. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_enable_1(
  6078. u8 v_enable_u8, u8 *v_intr_enable_1_u8)
  6079. {
  6080. /* variable used for return the status of communication result*/
  6081. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6082. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  6083. /* check the p_bmi160 structure as NULL*/
  6084. if (p_bmi160 == BMI160_NULL) {
  6085. return E_BMI160_NULL_PTR;
  6086. } else {
  6087. switch (v_enable_u8) {
  6088. case BMI160_HIGH_G_X_ENABLE:
  6089. /* read high_g_x interrupt*/
  6090. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6091. dev_addr,
  6092. BMI160_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE__REG,
  6093. &v_data_u8, C_BMI160_ONE_U8X);
  6094. *v_intr_enable_1_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6095. BMI160_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE);
  6096. break;
  6097. case BMI160_HIGH_G_Y_ENABLE:
  6098. /* read high_g_y interrupt*/
  6099. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6100. dev_addr,
  6101. BMI160_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE__REG,
  6102. &v_data_u8, C_BMI160_ONE_U8X);
  6103. *v_intr_enable_1_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6104. BMI160_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE);
  6105. break;
  6106. case BMI160_HIGH_G_Z_ENABLE:
  6107. /* read high_g_z interrupt*/
  6108. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6109. dev_addr,
  6110. BMI160_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE__REG,
  6111. &v_data_u8, C_BMI160_ONE_U8X);
  6112. *v_intr_enable_1_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6113. BMI160_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE);
  6114. break;
  6115. case BMI160_LOW_G_ENABLE:
  6116. /* read low_g interrupt */
  6117. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6118. dev_addr, BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG,
  6119. &v_data_u8, C_BMI160_ONE_U8X);
  6120. *v_intr_enable_1_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6121. BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE);
  6122. break;
  6123. case BMI160_DATA_RDY_ENABLE:
  6124. /* read data ready interrupt */
  6125. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6126. dev_addr,
  6127. BMI160_USER_INTR_ENABLE_1_DATA_RDY_ENABLE__REG,
  6128. &v_data_u8, C_BMI160_ONE_U8X);
  6129. *v_intr_enable_1_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6130. BMI160_USER_INTR_ENABLE_1_DATA_RDY_ENABLE);
  6131. break;
  6132. case BMI160_FIFO_FULL_ENABLE:
  6133. /* read fifo full interrupt */
  6134. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6135. dev_addr,
  6136. BMI160_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE__REG,
  6137. &v_data_u8, C_BMI160_ONE_U8X);
  6138. *v_intr_enable_1_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6139. BMI160_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE);
  6140. break;
  6141. case BMI160_FIFO_WM_ENABLE:
  6142. /* read fifo water mark interrupt */
  6143. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6144. dev_addr,
  6145. BMI160_USER_INTR_ENABLE_1_FIFO_WM_ENABLE__REG,
  6146. &v_data_u8, C_BMI160_ONE_U8X);
  6147. *v_intr_enable_1_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6148. BMI160_USER_INTR_ENABLE_1_FIFO_WM_ENABLE);
  6149. break;
  6150. default:
  6151. com_rslt = E_BMI160_OUT_OF_RANGE;
  6152. break;
  6153. }
  6154. }
  6155. return com_rslt;
  6156. }
  6157. /*!
  6158. * @brief This API is used to set
  6159. * interrupt enable byte1 from the register 0x51 bit 0 to 6
  6160. * @brief It read the high_g_x,high_g_y,high_g_z,low_g_enable
  6161. * data ready, fifo full and fifo water mark.
  6162. *
  6163. *
  6164. *
  6165. * @param v_enable_u8 : The value of interrupt enable
  6166. * @param v_enable_u8 : Value to decided to select interrupt
  6167. * v_enable_u8 | interrupt
  6168. * ---------------|---------------
  6169. * 0 | BMI160_HIGH_G_X_ENABLE
  6170. * 1 | BMI160_HIGH_G_Y_ENABLE
  6171. * 2 | BMI160_HIGH_G_Z_ENABLE
  6172. * 3 | BMI160_LOW_G_ENABLE
  6173. * 4 | BMI160_DATA_RDY_ENABLE
  6174. * 5 | BMI160_FIFO_FULL_ENABLE
  6175. * 6 | BMI160_FIFO_WM_ENABLE
  6176. *
  6177. * @param v_intr_enable_1_u8 : The interrupt enable value
  6178. * value | interrupt enable
  6179. * ----------|-------------------
  6180. * 0x01 | BMI160_ENABLE
  6181. * 0x00 | BMI160_DISABLE
  6182. *
  6183. *
  6184. *
  6185. * @return results of bus communication function
  6186. * @retval 0 -> Success
  6187. * @retval -1 -> Error
  6188. *
  6189. *
  6190. */
  6191. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_enable_1(
  6192. u8 v_enable_u8, u8 v_intr_enable_1_u8)
  6193. {
  6194. /* variable used for return the status of communication result*/
  6195. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6196. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  6197. /* check the p_bmi160 structure as NULL*/
  6198. if (p_bmi160 == BMI160_NULL) {
  6199. return E_BMI160_NULL_PTR;
  6200. } else {
  6201. switch (v_enable_u8) {
  6202. case BMI160_HIGH_G_X_ENABLE:
  6203. /* write high_g_x interrupt*/
  6204. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6205. dev_addr,
  6206. BMI160_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE__REG,
  6207. &v_data_u8, C_BMI160_ONE_U8X);
  6208. if (com_rslt == SUCCESS) {
  6209. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6210. BMI160_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE,
  6211. v_intr_enable_1_u8);
  6212. com_rslt +=
  6213. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6214. dev_addr,
  6215. BMI160_USER_INTR_ENABLE_1_HIGH_G_X_ENABLE__REG,
  6216. &v_data_u8, C_BMI160_ONE_U8X);
  6217. }
  6218. break;
  6219. case BMI160_HIGH_G_Y_ENABLE:
  6220. /* write high_g_y interrupt*/
  6221. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6222. dev_addr,
  6223. BMI160_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE__REG,
  6224. &v_data_u8, C_BMI160_ONE_U8X);
  6225. if (com_rslt == SUCCESS) {
  6226. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6227. BMI160_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE,
  6228. v_intr_enable_1_u8);
  6229. com_rslt +=
  6230. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6231. dev_addr,
  6232. BMI160_USER_INTR_ENABLE_1_HIGH_G_Y_ENABLE__REG,
  6233. &v_data_u8, C_BMI160_ONE_U8X);
  6234. }
  6235. break;
  6236. case BMI160_HIGH_G_Z_ENABLE:
  6237. /* write high_g_z interrupt*/
  6238. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6239. dev_addr,
  6240. BMI160_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE__REG,
  6241. &v_data_u8, C_BMI160_ONE_U8X);
  6242. if (com_rslt == SUCCESS) {
  6243. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6244. BMI160_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE,
  6245. v_intr_enable_1_u8);
  6246. com_rslt +=
  6247. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6248. dev_addr,
  6249. BMI160_USER_INTR_ENABLE_1_HIGH_G_Z_ENABLE__REG,
  6250. &v_data_u8, C_BMI160_ONE_U8X);
  6251. }
  6252. break;
  6253. case BMI160_LOW_G_ENABLE:
  6254. /* write low_g interrupt*/
  6255. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6256. dev_addr,
  6257. BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG,
  6258. &v_data_u8, C_BMI160_ONE_U8X);
  6259. if (com_rslt == SUCCESS) {
  6260. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6261. BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE,
  6262. v_intr_enable_1_u8);
  6263. com_rslt +=
  6264. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6265. dev_addr,
  6266. BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG,
  6267. &v_data_u8, C_BMI160_ONE_U8X);
  6268. }
  6269. break;
  6270. case BMI160_DATA_RDY_ENABLE:
  6271. /* write data ready interrupt*/
  6272. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6273. dev_addr,
  6274. BMI160_USER_INTR_ENABLE_1_DATA_RDY_ENABLE__REG,
  6275. &v_data_u8, C_BMI160_ONE_U8X);
  6276. if (com_rslt == SUCCESS) {
  6277. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6278. BMI160_USER_INTR_ENABLE_1_DATA_RDY_ENABLE,
  6279. v_intr_enable_1_u8);
  6280. com_rslt +=
  6281. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6282. dev_addr,
  6283. BMI160_USER_INTR_ENABLE_1_DATA_RDY_ENABLE__REG,
  6284. &v_data_u8, C_BMI160_ONE_U8X);
  6285. }
  6286. break;
  6287. case BMI160_FIFO_FULL_ENABLE:
  6288. /* write fifo full interrupt*/
  6289. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6290. dev_addr,
  6291. BMI160_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE__REG,
  6292. &v_data_u8, C_BMI160_ONE_U8X);
  6293. if (com_rslt == SUCCESS) {
  6294. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6295. BMI160_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE,
  6296. v_intr_enable_1_u8);
  6297. com_rslt +=
  6298. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6299. dev_addr,
  6300. BMI160_USER_INTR_ENABLE_1_FIFO_FULL_ENABLE__REG,
  6301. &v_data_u8, C_BMI160_ONE_U8X);
  6302. }
  6303. break;
  6304. case BMI160_FIFO_WM_ENABLE:
  6305. /* write fifo water mark interrupt*/
  6306. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6307. dev_addr, BMI160_USER_INTR_ENABLE_1_FIFO_WM_ENABLE__REG,
  6308. &v_data_u8, C_BMI160_ONE_U8X);
  6309. if (com_rslt == SUCCESS) {
  6310. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6311. BMI160_USER_INTR_ENABLE_1_FIFO_WM_ENABLE,
  6312. v_intr_enable_1_u8);
  6313. com_rslt +=
  6314. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6315. dev_addr,
  6316. BMI160_USER_INTR_ENABLE_1_FIFO_WM_ENABLE__REG,
  6317. &v_data_u8, C_BMI160_ONE_U8X);
  6318. }
  6319. break;
  6320. default:
  6321. com_rslt = E_BMI160_OUT_OF_RANGE;
  6322. break;
  6323. }
  6324. }
  6325. return com_rslt;
  6326. }
  6327. /*!
  6328. * @brief This API is used to read
  6329. * interrupt enable byte2 from the register bit 0x52 bit 0 to 3
  6330. * @brief It reads no motion x,y and z
  6331. *
  6332. *
  6333. *
  6334. * @param v_enable_u8: The value of interrupt enable
  6335. * v_enable_u8 | interrupt
  6336. * ---------------|---------------
  6337. * 0 | BMI160_NOMOTION_X_ENABLE
  6338. * 1 | BMI160_NOMOTION_Y_ENABLE
  6339. * 2 | BMI160_NOMOTION_Z_ENABLE
  6340. *
  6341. * @param v_intr_enable_2_u8 : The interrupt enable value
  6342. * value | interrupt enable
  6343. * ----------|-------------------
  6344. * 0x01 | BMI160_ENABLE
  6345. * 0x00 | BMI160_DISABLE
  6346. *
  6347. *
  6348. *
  6349. * @return results of bus communication function
  6350. * @retval 0 -> Success
  6351. * @retval -1 -> Error
  6352. *
  6353. *
  6354. */
  6355. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_enable_2(
  6356. u8 v_enable_u8, u8 *v_intr_enable_2_u8)
  6357. {
  6358. /* variable used for return the status of communication result*/
  6359. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6360. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  6361. /* check the p_bmi160 structure as NULL*/
  6362. if (p_bmi160 == BMI160_NULL) {
  6363. return E_BMI160_NULL_PTR;
  6364. } else {
  6365. switch (v_enable_u8) {
  6366. case BMI160_NOMOTION_X_ENABLE:
  6367. /* read no motion x */
  6368. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6369. dev_addr,
  6370. BMI160_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE__REG,
  6371. &v_data_u8, C_BMI160_ONE_U8X);
  6372. *v_intr_enable_2_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6373. BMI160_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE);
  6374. break;
  6375. case BMI160_NOMOTION_Y_ENABLE:
  6376. /* read no motion y */
  6377. com_rslt =
  6378. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6379. dev_addr,
  6380. BMI160_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE__REG,
  6381. &v_data_u8, C_BMI160_ONE_U8X);
  6382. *v_intr_enable_2_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6383. BMI160_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE);
  6384. break;
  6385. case BMI160_NOMOTION_Z_ENABLE:
  6386. /* read no motion z */
  6387. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6388. dev_addr,
  6389. BMI160_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE__REG,
  6390. &v_data_u8, C_BMI160_ONE_U8X);
  6391. *v_intr_enable_2_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6392. BMI160_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE);
  6393. break;
  6394. default:
  6395. com_rslt = E_BMI160_OUT_OF_RANGE;
  6396. break;
  6397. }
  6398. }
  6399. return com_rslt;
  6400. }
  6401. /*!
  6402. * @brief This API is used to set
  6403. * interrupt enable byte2 from the register bit 0x52 bit 0 to 3
  6404. * @brief It reads no motion x,y and z
  6405. *
  6406. *
  6407. *
  6408. * @param v_enable_u8: The value of interrupt enable
  6409. * v_enable_u8 | interrupt
  6410. * ---------------|---------------
  6411. * 0 | BMI160_NOMOTION_X_ENABLE
  6412. * 1 | BMI160_NOMOTION_Y_ENABLE
  6413. * 2 | BMI160_NOMOTION_Z_ENABLE
  6414. *
  6415. * @param v_intr_enable_2_u8 : The interrupt enable value
  6416. * value | interrupt enable
  6417. * ----------|-------------------
  6418. * 0x01 | BMI160_ENABLE
  6419. * 0x00 | BMI160_DISABLE
  6420. *
  6421. *
  6422. *
  6423. * @return results of bus communication function
  6424. * @retval 0 -> Success
  6425. * @retval -1 -> Error
  6426. *
  6427. *
  6428. */
  6429. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_enable_2(
  6430. u8 v_enable_u8, u8 v_intr_enable_2_u8)
  6431. {
  6432. /* variable used for return the status of communication result*/
  6433. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6434. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  6435. /* check the p_bmi160 structure as NULL*/
  6436. if (p_bmi160 == BMI160_NULL) {
  6437. return E_BMI160_NULL_PTR;
  6438. } else {
  6439. switch (v_enable_u8) {
  6440. case BMI160_NOMOTION_X_ENABLE:
  6441. /* write no motion x */
  6442. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6443. dev_addr,
  6444. BMI160_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE__REG,
  6445. &v_data_u8, C_BMI160_ONE_U8X);
  6446. if (com_rslt == SUCCESS) {
  6447. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6448. BMI160_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE,
  6449. v_intr_enable_2_u8);
  6450. com_rslt +=
  6451. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6452. dev_addr,
  6453. BMI160_USER_INTR_ENABLE_2_NOMOTION_X_ENABLE__REG,
  6454. &v_data_u8, C_BMI160_ONE_U8X);
  6455. }
  6456. break;
  6457. case BMI160_NOMOTION_Y_ENABLE:
  6458. /* write no motion y */
  6459. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6460. dev_addr,
  6461. BMI160_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE__REG,
  6462. &v_data_u8, C_BMI160_ONE_U8X);
  6463. if (com_rslt == SUCCESS) {
  6464. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6465. BMI160_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE,
  6466. v_intr_enable_2_u8);
  6467. com_rslt +=
  6468. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6469. dev_addr,
  6470. BMI160_USER_INTR_ENABLE_2_NOMOTION_Y_ENABLE__REG,
  6471. &v_data_u8, C_BMI160_ONE_U8X);
  6472. }
  6473. break;
  6474. case BMI160_NOMOTION_Z_ENABLE:
  6475. /* write no motion z */
  6476. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6477. dev_addr,
  6478. BMI160_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE__REG,
  6479. &v_data_u8, C_BMI160_ONE_U8X);
  6480. if (com_rslt == SUCCESS) {
  6481. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6482. BMI160_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE,
  6483. v_intr_enable_2_u8);
  6484. com_rslt +=
  6485. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6486. dev_addr,
  6487. BMI160_USER_INTR_ENABLE_2_NOMOTION_Z_ENABLE__REG,
  6488. &v_data_u8, C_BMI160_ONE_U8X);
  6489. }
  6490. break;
  6491. default:
  6492. com_rslt = E_BMI160_OUT_OF_RANGE;
  6493. break;
  6494. }
  6495. }
  6496. return com_rslt;
  6497. }
  6498. /*!
  6499. * @brief This API is used to read
  6500. * interrupt enable step detector interrupt from
  6501. * the register bit 0x52 bit 3
  6502. *
  6503. *
  6504. *
  6505. *
  6506. * @param v_step_intr_u8 : The value of step detector interrupt enable
  6507. *
  6508. *
  6509. *
  6510. * @return results of bus communication function
  6511. * @retval 0 -> Success
  6512. * @retval -1 -> Error
  6513. *
  6514. *
  6515. */
  6516. BMI160_RETURN_FUNCTION_TYPE bmi160_get_step_detector_enable(
  6517. u8 *v_step_intr_u8)
  6518. {
  6519. /* variable used for return the status of communication result*/
  6520. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6521. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  6522. /* check the p_bmi160 structure as NULL*/
  6523. if (p_bmi160 == BMI160_NULL) {
  6524. return E_BMI160_NULL_PTR;
  6525. } else {
  6526. /* read the step detector interrupt*/
  6527. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6528. dev_addr,
  6529. BMI160_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE__REG,
  6530. &v_data_u8, C_BMI160_ONE_U8X);
  6531. *v_step_intr_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6532. BMI160_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE);
  6533. }
  6534. return com_rslt;
  6535. }
  6536. /*!
  6537. * @brief This API is used to set
  6538. * interrupt enable step detector interrupt from
  6539. * the register bit 0x52 bit 3
  6540. *
  6541. *
  6542. *
  6543. *
  6544. * @param v_step_intr_u8 : The value of step detector interrupt enable
  6545. *
  6546. *
  6547. *
  6548. * @return results of bus communication function
  6549. * @retval 0 -> Success
  6550. * @retval -1 -> Error
  6551. *
  6552. *
  6553. */
  6554. BMI160_RETURN_FUNCTION_TYPE bmi160_set_step_detector_enable(
  6555. u8 v_step_intr_u8)
  6556. {
  6557. /* variable used for return the status of communication result*/
  6558. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6559. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  6560. /* check the p_bmi160 structure as NULL*/
  6561. if (p_bmi160 == BMI160_NULL) {
  6562. return E_BMI160_NULL_PTR;
  6563. } else {
  6564. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6565. dev_addr,
  6566. BMI160_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE__REG,
  6567. &v_data_u8, C_BMI160_ONE_U8X);
  6568. if (com_rslt == SUCCESS) {
  6569. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6570. BMI160_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE,
  6571. v_step_intr_u8);
  6572. com_rslt +=
  6573. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6574. dev_addr,
  6575. BMI160_USER_INTR_ENABLE_2_STEP_DETECTOR_ENABLE__REG,
  6576. &v_data_u8, C_BMI160_ONE_U8X);
  6577. }
  6578. }
  6579. return com_rslt;
  6580. }
  6581. /*!
  6582. * @brief Configure trigger condition of interrupt1
  6583. * and interrupt2 pin from the register 0x53
  6584. * @brief interrupt1 - bit 0
  6585. * @brief interrupt2 - bit 4
  6586. *
  6587. * @param v_channel_u8: The value of edge trigger selection
  6588. * v_channel_u8 | Edge trigger
  6589. * ---------------|---------------
  6590. * 0 | BMI160_INTR1_EDGE_CTRL
  6591. * 1 | BMI160_INTR2_EDGE_CTRL
  6592. *
  6593. * @param v_intr_edge_ctrl_u8 : The value of edge trigger enable
  6594. * value | interrupt enable
  6595. * ----------|-------------------
  6596. * 0x01 | BMI160_EDGE
  6597. * 0x00 | BMI160_LEVEL
  6598. *
  6599. * @return results of bus communication function
  6600. * @retval 0 -> Success
  6601. * @retval -1 -> Error
  6602. *
  6603. *
  6604. */
  6605. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_edge_ctrl(
  6606. u8 v_channel_u8, u8 *v_intr_edge_ctrl_u8)
  6607. {
  6608. /* variable used for return the status of communication result*/
  6609. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6610. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  6611. /* check the p_bmi160 structure as NULL*/
  6612. if (p_bmi160 == BMI160_NULL) {
  6613. return E_BMI160_NULL_PTR;
  6614. } else {
  6615. switch (v_channel_u8) {
  6616. case BMI160_INTR1_EDGE_CTRL:
  6617. /* read the edge trigger interrupt1*/
  6618. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6619. dev_addr, BMI160_USER_INTR1_EDGE_CTRL__REG,
  6620. &v_data_u8, C_BMI160_ONE_U8X);
  6621. *v_intr_edge_ctrl_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6622. BMI160_USER_INTR1_EDGE_CTRL);
  6623. break;
  6624. case BMI160_INTR2_EDGE_CTRL:
  6625. /* read the edge trigger interrupt2*/
  6626. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6627. dev_addr, BMI160_USER_INTR2_EDGE_CTRL__REG,
  6628. &v_data_u8, C_BMI160_ONE_U8X);
  6629. *v_intr_edge_ctrl_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6630. BMI160_USER_INTR2_EDGE_CTRL);
  6631. break;
  6632. default:
  6633. com_rslt = E_BMI160_OUT_OF_RANGE;
  6634. break;
  6635. }
  6636. }
  6637. return com_rslt;
  6638. }
  6639. /*!
  6640. * @brief Configure trigger condition of interrupt1
  6641. * and interrupt2 pin from the register 0x53
  6642. * @brief interrupt1 - bit 0
  6643. * @brief interrupt2 - bit 4
  6644. *
  6645. * @param v_channel_u8: The value of edge trigger selection
  6646. * v_channel_u8 | Edge trigger
  6647. * ---------------|---------------
  6648. * 0 | BMI160_INTR1_EDGE_CTRL
  6649. * 1 | BMI160_INTR2_EDGE_CTRL
  6650. *
  6651. * @param v_intr_edge_ctrl_u8 : The value of edge trigger enable
  6652. * value | interrupt enable
  6653. * ----------|-------------------
  6654. * 0x01 | BMI160_EDGE
  6655. * 0x00 | BMI160_LEVEL
  6656. *
  6657. * @return results of bus communication function
  6658. * @retval 0 -> Success
  6659. * @retval -1 -> Error
  6660. *
  6661. *
  6662. */
  6663. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_edge_ctrl(
  6664. u8 v_channel_u8, u8 v_intr_edge_ctrl_u8)
  6665. {
  6666. /* variable used for return the status of communication result*/
  6667. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6668. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  6669. /* check the p_bmi160 structure as NULL*/
  6670. if (p_bmi160 == BMI160_NULL) {
  6671. return E_BMI160_NULL_PTR;
  6672. } else {
  6673. switch (v_channel_u8) {
  6674. case BMI160_INTR1_EDGE_CTRL:
  6675. /* write the edge trigger interrupt1*/
  6676. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6677. dev_addr, BMI160_USER_INTR1_EDGE_CTRL__REG,
  6678. &v_data_u8, C_BMI160_ONE_U8X);
  6679. if (com_rslt == SUCCESS) {
  6680. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6681. BMI160_USER_INTR1_EDGE_CTRL,
  6682. v_intr_edge_ctrl_u8);
  6683. com_rslt +=
  6684. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6685. dev_addr, BMI160_USER_INTR1_EDGE_CTRL__REG,
  6686. &v_data_u8, C_BMI160_ONE_U8X);
  6687. }
  6688. break;
  6689. case BMI160_INTR2_EDGE_CTRL:
  6690. /* write the edge trigger interrupt2*/
  6691. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6692. dev_addr, BMI160_USER_INTR2_EDGE_CTRL__REG,
  6693. &v_data_u8, C_BMI160_ONE_U8X);
  6694. if (com_rslt == SUCCESS) {
  6695. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6696. BMI160_USER_INTR2_EDGE_CTRL,
  6697. v_intr_edge_ctrl_u8);
  6698. com_rslt +=
  6699. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6700. dev_addr, BMI160_USER_INTR2_EDGE_CTRL__REG,
  6701. &v_data_u8, C_BMI160_ONE_U8X);
  6702. }
  6703. break;
  6704. default:
  6705. com_rslt = E_BMI160_OUT_OF_RANGE;
  6706. break;
  6707. }
  6708. }
  6709. return com_rslt;
  6710. }
  6711. /*!
  6712. * @brief API used for get the Configure level condition of interrupt1
  6713. * and interrupt2 pin form the register 0x53
  6714. * @brief interrupt1 - bit 1
  6715. * @brief interrupt2 - bit 5
  6716. *
  6717. * @param v_channel_u8: The value of level condition selection
  6718. * v_channel_u8 | level selection
  6719. * ---------------|---------------
  6720. * 0 | BMI160_INTR1_LEVEL
  6721. * 1 | BMI160_INTR2_LEVEL
  6722. *
  6723. * @param v_intr_level_u8 : The value of level of interrupt enable
  6724. * value | Behaviour
  6725. * ----------|-------------------
  6726. * 0x01 | BMI160_LEVEL_HIGH
  6727. * 0x00 | BMI160_LEVEL_LOW
  6728. *
  6729. * @return results of bus communication function
  6730. * @retval 0 -> Success
  6731. * @retval -1 -> Error
  6732. *
  6733. *
  6734. */
  6735. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_level(
  6736. u8 v_channel_u8, u8 *v_intr_level_u8)
  6737. {
  6738. /* variable used for return the status of communication result*/
  6739. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6740. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  6741. /* check the p_bmi160 structure as NULL*/
  6742. if (p_bmi160 == BMI160_NULL) {
  6743. return E_BMI160_NULL_PTR;
  6744. } else {
  6745. switch (v_channel_u8) {
  6746. case BMI160_INTR1_LEVEL:
  6747. /* read the interrupt1 level*/
  6748. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6749. dev_addr, BMI160_USER_INTR1_LEVEL__REG,
  6750. &v_data_u8, C_BMI160_ONE_U8X);
  6751. *v_intr_level_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6752. BMI160_USER_INTR1_LEVEL);
  6753. break;
  6754. case BMI160_INTR2_LEVEL:
  6755. /* read the interrupt2 level*/
  6756. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6757. dev_addr, BMI160_USER_INTR2_LEVEL__REG,
  6758. &v_data_u8, C_BMI160_ONE_U8X);
  6759. *v_intr_level_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6760. BMI160_USER_INTR2_LEVEL);
  6761. break;
  6762. default:
  6763. com_rslt = E_BMI160_OUT_OF_RANGE;
  6764. break;
  6765. }
  6766. }
  6767. return com_rslt;
  6768. }
  6769. /*!
  6770. * @brief API used for set the Configure level condition of interrupt1
  6771. * and interrupt2 pin form the register 0x53
  6772. * @brief interrupt1 - bit 1
  6773. * @brief interrupt2 - bit 5
  6774. *
  6775. * @param v_channel_u8: The value of level condition selection
  6776. * v_channel_u8 | level selection
  6777. * ---------------|---------------
  6778. * 0 | BMI160_INTR1_LEVEL
  6779. * 1 | BMI160_INTR2_LEVEL
  6780. *
  6781. * @param v_intr_level_u8 : The value of level of interrupt enable
  6782. * value | Behaviour
  6783. * ----------|-------------------
  6784. * 0x01 | BMI160_LEVEL_HIGH
  6785. * 0x00 | BMI160_LEVEL_LOW
  6786. *
  6787. * @return results of bus communication function
  6788. * @retval 0 -> Success
  6789. * @retval -1 -> Error
  6790. *
  6791. *
  6792. */
  6793. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_level(
  6794. u8 v_channel_u8, u8 v_intr_level_u8)
  6795. {
  6796. /* variable used for return the status of communication result*/
  6797. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6798. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  6799. /* check the p_bmi160 structure as NULL*/
  6800. if (p_bmi160 == BMI160_NULL) {
  6801. return E_BMI160_NULL_PTR;
  6802. } else {
  6803. switch (v_channel_u8) {
  6804. case BMI160_INTR1_LEVEL:
  6805. /* write the interrupt1 level*/
  6806. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6807. dev_addr, BMI160_USER_INTR1_LEVEL__REG,
  6808. &v_data_u8, C_BMI160_ONE_U8X);
  6809. if (com_rslt == SUCCESS) {
  6810. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6811. BMI160_USER_INTR1_LEVEL, v_intr_level_u8);
  6812. com_rslt +=
  6813. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6814. dev_addr, BMI160_USER_INTR1_LEVEL__REG,
  6815. &v_data_u8, C_BMI160_ONE_U8X);
  6816. }
  6817. break;
  6818. case BMI160_INTR2_LEVEL:
  6819. /* write the interrupt2 level*/
  6820. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6821. dev_addr, BMI160_USER_INTR2_LEVEL__REG,
  6822. &v_data_u8, C_BMI160_ONE_U8X);
  6823. if (com_rslt == SUCCESS) {
  6824. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6825. BMI160_USER_INTR2_LEVEL, v_intr_level_u8);
  6826. com_rslt +=
  6827. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6828. dev_addr, BMI160_USER_INTR2_LEVEL__REG,
  6829. &v_data_u8, C_BMI160_ONE_U8X);
  6830. }
  6831. break;
  6832. default:
  6833. com_rslt = E_BMI160_OUT_OF_RANGE;
  6834. break;
  6835. }
  6836. }
  6837. return com_rslt;
  6838. }
  6839. /*!
  6840. * @brief API used to get configured output enable of interrupt1
  6841. * and interrupt2 from the register 0x53
  6842. * @brief interrupt1 - bit 2
  6843. * @brief interrupt2 - bit 6
  6844. *
  6845. *
  6846. * @param v_channel_u8: The value of output type enable selection
  6847. * v_channel_u8 | level selection
  6848. * ---------------|---------------
  6849. * 0 | BMI160_INTR1_OUTPUT_TYPE
  6850. * 1 | BMI160_INTR2_OUTPUT_TYPE
  6851. *
  6852. * @param v_intr_output_type_u8 :
  6853. * The value of output type of interrupt enable
  6854. * value | Behaviour
  6855. * ----------|-------------------
  6856. * 0x01 | BMI160_OPEN_DRAIN
  6857. * 0x00 | BMI160_PUSH_PULL
  6858. *
  6859. *
  6860. * @return results of bus communication function
  6861. * @retval 0 -> Success
  6862. * @retval -1 -> Error
  6863. *
  6864. *
  6865. */
  6866. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_output_type(
  6867. u8 v_channel_u8, u8 *v_intr_output_type_u8)
  6868. {
  6869. /* variable used for return the status of communication result*/
  6870. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6871. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  6872. /* check the p_bmi160 structure as NULL*/
  6873. if (p_bmi160 == BMI160_NULL) {
  6874. return E_BMI160_NULL_PTR;
  6875. } else {
  6876. switch (v_channel_u8) {
  6877. case BMI160_INTR1_OUTPUT_TYPE:
  6878. /* read the output type of interrupt1*/
  6879. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6880. dev_addr, BMI160_USER_INTR1_OUTPUT_TYPE__REG,
  6881. &v_data_u8, C_BMI160_ONE_U8X);
  6882. *v_intr_output_type_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6883. BMI160_USER_INTR1_OUTPUT_TYPE);
  6884. break;
  6885. case BMI160_INTR2_OUTPUT_TYPE:
  6886. /* read the output type of interrupt2*/
  6887. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6888. dev_addr, BMI160_USER_INTR2_OUTPUT_TYPE__REG,
  6889. &v_data_u8, C_BMI160_ONE_U8X);
  6890. *v_intr_output_type_u8 = BMI160_GET_BITSLICE(v_data_u8,
  6891. BMI160_USER_INTR2_OUTPUT_TYPE);
  6892. break;
  6893. default:
  6894. com_rslt = E_BMI160_OUT_OF_RANGE;
  6895. break;
  6896. }
  6897. }
  6898. return com_rslt;
  6899. }
  6900. /*!
  6901. * @brief API used to set output enable of interrupt1
  6902. * and interrupt2 from the register 0x53
  6903. * @brief interrupt1 - bit 2
  6904. * @brief interrupt2 - bit 6
  6905. *
  6906. *
  6907. * @param v_channel_u8: The value of output type enable selection
  6908. * v_channel_u8 | level selection
  6909. * ---------------|---------------
  6910. * 0 | BMI160_INTR1_OUTPUT_TYPE
  6911. * 1 | BMI160_INTR2_OUTPUT_TYPE
  6912. *
  6913. * @param v_intr_output_type_u8 :
  6914. * The value of output type of interrupt enable
  6915. * value | Behaviour
  6916. * ----------|-------------------
  6917. * 0x01 | BMI160_OPEN_DRAIN
  6918. * 0x00 | BMI160_PUSH_PULL
  6919. *
  6920. *
  6921. * @return results of bus communication function
  6922. * @retval 0 -> Success
  6923. * @retval -1 -> Error
  6924. *
  6925. *
  6926. */
  6927. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_output_type(
  6928. u8 v_channel_u8, u8 v_intr_output_type_u8)
  6929. {
  6930. /* variable used for return the status of communication result*/
  6931. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  6932. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  6933. /* check the p_bmi160 structure as NULL*/
  6934. if (p_bmi160 == BMI160_NULL) {
  6935. return E_BMI160_NULL_PTR;
  6936. } else {
  6937. switch (v_channel_u8) {
  6938. case BMI160_INTR1_OUTPUT_TYPE:
  6939. /* write the output type of interrupt1*/
  6940. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6941. dev_addr, BMI160_USER_INTR1_OUTPUT_TYPE__REG,
  6942. &v_data_u8, C_BMI160_ONE_U8X);
  6943. if (com_rslt == SUCCESS) {
  6944. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6945. BMI160_USER_INTR1_OUTPUT_TYPE,
  6946. v_intr_output_type_u8);
  6947. com_rslt +=
  6948. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6949. dev_addr, BMI160_USER_INTR1_OUTPUT_TYPE__REG,
  6950. &v_data_u8, C_BMI160_ONE_U8X);
  6951. }
  6952. break;
  6953. case BMI160_INTR2_OUTPUT_TYPE:
  6954. /* write the output type of interrupt2*/
  6955. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  6956. dev_addr, BMI160_USER_INTR2_OUTPUT_TYPE__REG,
  6957. &v_data_u8, C_BMI160_ONE_U8X);
  6958. if (com_rslt == SUCCESS) {
  6959. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  6960. BMI160_USER_INTR2_OUTPUT_TYPE,
  6961. v_intr_output_type_u8);
  6962. com_rslt +=
  6963. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  6964. dev_addr, BMI160_USER_INTR2_OUTPUT_TYPE__REG,
  6965. &v_data_u8, C_BMI160_ONE_U8X);
  6966. }
  6967. break;
  6968. default:
  6969. com_rslt = E_BMI160_OUT_OF_RANGE;
  6970. break;
  6971. }
  6972. }
  6973. return com_rslt;
  6974. }
  6975. /*!
  6976. * @brief API used to get the Output enable for interrupt1
  6977. * and interrupt1 pin from the register 0x53
  6978. * @brief interrupt1 - bit 3
  6979. * @brief interrupt2 - bit 7
  6980. *
  6981. * @param v_channel_u8: The value of output enable selection
  6982. * v_channel_u8 | level selection
  6983. * ---------------|---------------
  6984. * 0 | BMI160_INTR1_OUTPUT_TYPE
  6985. * 1 | BMI160_INTR2_OUTPUT_TYPE
  6986. *
  6987. * @param v_output_enable_u8 :
  6988. * The value of output enable of interrupt enable
  6989. * value | Behaviour
  6990. * ----------|-------------------
  6991. * 0x01 | BMI160_INPUT
  6992. * 0x00 | BMI160_OUTPUT
  6993. *
  6994. *
  6995. *
  6996. * @return results of bus communication function
  6997. * @retval 0 -> Success
  6998. * @retval -1 -> Error
  6999. *
  7000. *
  7001. */
  7002. BMI160_RETURN_FUNCTION_TYPE bmi160_get_output_enable(
  7003. u8 v_channel_u8, u8 *v_output_enable_u8)
  7004. {
  7005. /* variable used for return the status of communication result*/
  7006. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7007. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  7008. /* check the p_bmi160 structure as NULL*/
  7009. if (p_bmi160 == BMI160_NULL) {
  7010. return E_BMI160_NULL_PTR;
  7011. } else {
  7012. switch (v_channel_u8) {
  7013. case BMI160_INTR1_OUTPUT_ENABLE:
  7014. /* read the output enable of interrupt1*/
  7015. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7016. dev_addr, BMI160_USER_INTR1_OUTPUT_ENABLE__REG,
  7017. &v_data_u8, C_BMI160_ONE_U8X);
  7018. *v_output_enable_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7019. BMI160_USER_INTR1_OUTPUT_ENABLE);
  7020. break;
  7021. case BMI160_INTR2_OUTPUT_ENABLE:
  7022. /* read the output enable of interrupt2*/
  7023. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7024. dev_addr, BMI160_USER_INTR2_OUTPUT_EN__REG,
  7025. &v_data_u8, C_BMI160_ONE_U8X);
  7026. *v_output_enable_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7027. BMI160_USER_INTR2_OUTPUT_EN);
  7028. break;
  7029. default:
  7030. com_rslt = E_BMI160_OUT_OF_RANGE;
  7031. break;
  7032. }
  7033. }
  7034. return com_rslt;
  7035. }
  7036. /*!
  7037. * @brief API used to set the Output enable for interrupt1
  7038. * and interrupt1 pin from the register 0x53
  7039. * @brief interrupt1 - bit 3
  7040. * @brief interrupt2 - bit 7
  7041. *
  7042. * @param v_channel_u8: The value of output enable selection
  7043. * v_channel_u8 | level selection
  7044. * ---------------|---------------
  7045. * 0 | BMI160_INTR1_OUTPUT_TYPE
  7046. * 1 | BMI160_INTR2_OUTPUT_TYPE
  7047. *
  7048. * @param v_output_enable_u8 :
  7049. * The value of output enable of interrupt enable
  7050. * value | Behaviour
  7051. * ----------|-------------------
  7052. * 0x01 | BMI160_INPUT
  7053. * 0x00 | BMI160_OUTPUT
  7054. *
  7055. *
  7056. *
  7057. * @return results of bus communication function
  7058. * @retval 0 -> Success
  7059. * @retval -1 -> Error
  7060. *
  7061. *
  7062. */
  7063. BMI160_RETURN_FUNCTION_TYPE bmi160_set_output_enable(
  7064. u8 v_channel_u8, u8 v_output_enable_u8)
  7065. {
  7066. /* variable used for return the status of communication result*/
  7067. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7068. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  7069. /* check the p_bmi160 structure as NULL*/
  7070. if (p_bmi160 == BMI160_NULL) {
  7071. return E_BMI160_NULL_PTR;
  7072. } else {
  7073. switch (v_channel_u8) {
  7074. case BMI160_INTR1_OUTPUT_ENABLE:
  7075. /* write the output enable of interrupt1*/
  7076. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7077. dev_addr, BMI160_USER_INTR1_OUTPUT_ENABLE__REG,
  7078. &v_data_u8, C_BMI160_ONE_U8X);
  7079. if (com_rslt == SUCCESS) {
  7080. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7081. BMI160_USER_INTR1_OUTPUT_ENABLE,
  7082. v_output_enable_u8);
  7083. com_rslt +=
  7084. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7085. dev_addr, BMI160_USER_INTR1_OUTPUT_ENABLE__REG,
  7086. &v_data_u8, C_BMI160_ONE_U8X);
  7087. }
  7088. break;
  7089. case BMI160_INTR2_OUTPUT_ENABLE:
  7090. /* write the output enable of interrupt2*/
  7091. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7092. dev_addr, BMI160_USER_INTR2_OUTPUT_EN__REG,
  7093. &v_data_u8, C_BMI160_ONE_U8X);
  7094. if (com_rslt == SUCCESS) {
  7095. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7096. BMI160_USER_INTR2_OUTPUT_EN,
  7097. v_output_enable_u8);
  7098. com_rslt +=
  7099. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7100. dev_addr, BMI160_USER_INTR2_OUTPUT_EN__REG,
  7101. &v_data_u8, C_BMI160_ONE_U8X);
  7102. }
  7103. break;
  7104. default:
  7105. com_rslt = E_BMI160_OUT_OF_RANGE;
  7106. break;
  7107. }
  7108. }
  7109. return com_rslt;
  7110. }
  7111. /*!
  7112. * @brief This API is used to get the latch duration
  7113. * from the register 0x54 bit 0 to 3
  7114. * @brief This latch selection is not applicable for data ready,
  7115. * orientation and flat interrupts.
  7116. *
  7117. *
  7118. *
  7119. * @param v_latch_intr_u8 : The value of latch duration
  7120. * Latch Duration | value
  7121. * --------------------------------------|------------------
  7122. * BMI160_LATCH_DUR_NONE | 0x00
  7123. * BMI160_LATCH_DUR_312_5_MICRO_SEC | 0x01
  7124. * BMI160_LATCH_DUR_625_MICRO_SEC | 0x02
  7125. * BMI160_LATCH_DUR_1_25_MILLI_SEC | 0x03
  7126. * BMI160_LATCH_DUR_2_5_MILLI_SEC | 0x04
  7127. * BMI160_LATCH_DUR_5_MILLI_SEC | 0x05
  7128. * BMI160_LATCH_DUR_10_MILLI_SEC | 0x06
  7129. * BMI160_LATCH_DUR_20_MILLI_SEC | 0x07
  7130. * BMI160_LATCH_DUR_40_MILLI_SEC | 0x08
  7131. * BMI160_LATCH_DUR_80_MILLI_SEC | 0x09
  7132. * BMI160_LATCH_DUR_160_MILLI_SEC | 0x0A
  7133. * BMI160_LATCH_DUR_320_MILLI_SEC | 0x0B
  7134. * BMI160_LATCH_DUR_640_MILLI_SEC | 0x0C
  7135. * BMI160_LATCH_DUR_1_28_SEC | 0x0D
  7136. * BMI160_LATCH_DUR_2_56_SEC | 0x0E
  7137. * BMI160_LATCHED | 0x0F
  7138. *
  7139. *
  7140. *
  7141. * @return results of bus communication function
  7142. * @retval 0 -> Success
  7143. * @retval -1 -> Error
  7144. *
  7145. *
  7146. */
  7147. BMI160_RETURN_FUNCTION_TYPE bmi160_get_latch_intr(
  7148. u8 *v_latch_intr_u8)
  7149. {
  7150. /* variable used for return the status of communication result*/
  7151. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7152. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  7153. /* check the p_bmi160 structure as NULL*/
  7154. if (p_bmi160 == BMI160_NULL) {
  7155. return E_BMI160_NULL_PTR;
  7156. } else {
  7157. /* read the latch duration value */
  7158. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7159. dev_addr, BMI160_USER_INTR_LATCH__REG,
  7160. &v_data_u8, C_BMI160_ONE_U8X);
  7161. *v_latch_intr_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7162. BMI160_USER_INTR_LATCH);
  7163. }
  7164. return com_rslt;
  7165. }
  7166. /*!
  7167. * @brief This API is used to set the latch duration
  7168. * from the register 0x54 bit 0 to 3
  7169. * @brief This latch selection is not applicable for data ready,
  7170. * orientation and flat interrupts.
  7171. *
  7172. *
  7173. *
  7174. * @param v_latch_intr_u8 : The value of latch duration
  7175. * Latch Duration | value
  7176. * --------------------------------------|------------------
  7177. * BMI160_LATCH_DUR_NONE | 0x00
  7178. * BMI160_LATCH_DUR_312_5_MICRO_SEC | 0x01
  7179. * BMI160_LATCH_DUR_625_MICRO_SEC | 0x02
  7180. * BMI160_LATCH_DUR_1_25_MILLI_SEC | 0x03
  7181. * BMI160_LATCH_DUR_2_5_MILLI_SEC | 0x04
  7182. * BMI160_LATCH_DUR_5_MILLI_SEC | 0x05
  7183. * BMI160_LATCH_DUR_10_MILLI_SEC | 0x06
  7184. * BMI160_LATCH_DUR_20_MILLI_SEC | 0x07
  7185. * BMI160_LATCH_DUR_40_MILLI_SEC | 0x08
  7186. * BMI160_LATCH_DUR_80_MILLI_SEC | 0x09
  7187. * BMI160_LATCH_DUR_160_MILLI_SEC | 0x0A
  7188. * BMI160_LATCH_DUR_320_MILLI_SEC | 0x0B
  7189. * BMI160_LATCH_DUR_640_MILLI_SEC | 0x0C
  7190. * BMI160_LATCH_DUR_1_28_SEC | 0x0D
  7191. * BMI160_LATCH_DUR_2_56_SEC | 0x0E
  7192. * BMI160_LATCHED | 0x0F
  7193. *
  7194. *
  7195. *
  7196. * @return results of bus communication function
  7197. * @retval 0 -> Success
  7198. * @retval -1 -> Error
  7199. *
  7200. *
  7201. */
  7202. BMI160_RETURN_FUNCTION_TYPE bmi160_set_latch_intr(u8 v_latch_intr_u8)
  7203. {
  7204. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  7205. /* variable used for return the status of communication result*/
  7206. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7207. /* check the p_bmi160 structure as NULL*/
  7208. if (p_bmi160 == BMI160_NULL) {
  7209. return E_BMI160_NULL_PTR;
  7210. } else {
  7211. if (v_latch_intr_u8 < C_BMI160_SIXTEEN_U8X) {
  7212. /* write the latch duration value */
  7213. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7214. dev_addr, BMI160_USER_INTR_LATCH__REG,
  7215. &v_data_u8, C_BMI160_ONE_U8X);
  7216. if (com_rslt == SUCCESS) {
  7217. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7218. BMI160_USER_INTR_LATCH, v_latch_intr_u8);
  7219. com_rslt +=
  7220. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7221. dev_addr, BMI160_USER_INTR_LATCH__REG,
  7222. &v_data_u8, C_BMI160_ONE_U8X);
  7223. }
  7224. } else {
  7225. com_rslt = E_BMI160_OUT_OF_RANGE;
  7226. }
  7227. }
  7228. return com_rslt;
  7229. }
  7230. /*!
  7231. * @brief API used to get input enable for interrupt1
  7232. * and interrupt2 pin from the register 0x54
  7233. * @brief interrupt1 - bit 4
  7234. * @brief interrupt2 - bit 5
  7235. *
  7236. * @param v_channel_u8: The value of input enable selection
  7237. * v_channel_u8 | input selection
  7238. * ---------------|---------------
  7239. * 0 | BMI160_INTR1_INPUT_ENABLE
  7240. * 1 | BMI160_INTR2_INPUT_ENABLE
  7241. *
  7242. * @param v_input_en_u8 :
  7243. * The value of input enable of interrupt enable
  7244. * value | Behaviour
  7245. * ----------|-------------------
  7246. * 0x01 | BMI160_INPUT
  7247. * 0x00 | BMI160_OUTPUT
  7248. *
  7249. *
  7250. *
  7251. * @return results of bus communication function
  7252. * @retval 0 -> Success
  7253. * @retval -1 -> Error
  7254. *
  7255. *
  7256. */
  7257. BMI160_RETURN_FUNCTION_TYPE bmi160_get_input_enable(
  7258. u8 v_channel_u8, u8 *v_input_en_u8)
  7259. {
  7260. /* variable used for return the status of communication result*/
  7261. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7262. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  7263. /* check the p_bmi160 structure as NULL*/
  7264. if (p_bmi160 == BMI160_NULL) {
  7265. return E_BMI160_NULL_PTR;
  7266. } else {
  7267. switch (v_channel_u8) {
  7268. /* read input enable of interrup1 and interrupt2*/
  7269. case BMI160_INTR1_INPUT_ENABLE:
  7270. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7271. dev_addr, BMI160_USER_INTR1_INPUT_ENABLE__REG,
  7272. &v_data_u8, C_BMI160_ONE_U8X);
  7273. *v_input_en_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7274. BMI160_USER_INTR1_INPUT_ENABLE);
  7275. break;
  7276. case BMI160_INTR2_INPUT_ENABLE:
  7277. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7278. dev_addr, BMI160_USER_INTR2_INPUT_ENABLE__REG,
  7279. &v_data_u8, C_BMI160_ONE_U8X);
  7280. *v_input_en_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7281. BMI160_USER_INTR2_INPUT_ENABLE);
  7282. break;
  7283. default:
  7284. com_rslt = E_BMI160_OUT_OF_RANGE;
  7285. break;
  7286. }
  7287. }
  7288. return com_rslt;
  7289. }
  7290. /*!
  7291. * @brief API used to set input enable for interrupt1
  7292. * and interrupt2 pin from the register 0x54
  7293. * @brief interrupt1 - bit 4
  7294. * @brief interrupt2 - bit 5
  7295. *
  7296. * @param v_channel_u8: The value of input enable selection
  7297. * v_channel_u8 | input selection
  7298. * ---------------|---------------
  7299. * 0 | BMI160_INTR1_INPUT_ENABLE
  7300. * 1 | BMI160_INTR2_INPUT_ENABLE
  7301. *
  7302. * @param v_input_en_u8 :
  7303. * The value of input enable of interrupt enable
  7304. * value | Behaviour
  7305. * ----------|-------------------
  7306. * 0x01 | BMI160_INPUT
  7307. * 0x00 | BMI160_OUTPUT
  7308. *
  7309. *
  7310. *
  7311. * @return results of bus communication function
  7312. * @retval 0 -> Success
  7313. * @retval -1 -> Error
  7314. *
  7315. *
  7316. */
  7317. BMI160_RETURN_FUNCTION_TYPE bmi160_set_input_enable(
  7318. u8 v_channel_u8, u8 v_input_en_u8)
  7319. {
  7320. /* variable used for return the status of communication result*/
  7321. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7322. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  7323. /* check the p_bmi160 structure as NULL*/
  7324. if (p_bmi160 == BMI160_NULL) {
  7325. return E_BMI160_NULL_PTR;
  7326. } else {
  7327. switch (v_channel_u8) {
  7328. /* write input enable of interrup1 and interrupt2*/
  7329. case BMI160_INTR1_INPUT_ENABLE:
  7330. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7331. dev_addr, BMI160_USER_INTR1_INPUT_ENABLE__REG,
  7332. &v_data_u8, C_BMI160_ONE_U8X);
  7333. if (com_rslt == SUCCESS) {
  7334. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7335. BMI160_USER_INTR1_INPUT_ENABLE, v_input_en_u8);
  7336. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7337. dev_addr, BMI160_USER_INTR1_INPUT_ENABLE__REG,
  7338. &v_data_u8, C_BMI160_ONE_U8X);
  7339. }
  7340. break;
  7341. case BMI160_INTR2_INPUT_ENABLE:
  7342. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7343. dev_addr, BMI160_USER_INTR2_INPUT_ENABLE__REG,
  7344. &v_data_u8, C_BMI160_ONE_U8X);
  7345. if (com_rslt == SUCCESS) {
  7346. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7347. BMI160_USER_INTR2_INPUT_ENABLE, v_input_en_u8);
  7348. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7349. dev_addr, BMI160_USER_INTR2_INPUT_ENABLE__REG,
  7350. &v_data_u8, C_BMI160_ONE_U8X);
  7351. }
  7352. break;
  7353. default:
  7354. com_rslt = E_BMI160_OUT_OF_RANGE;
  7355. break;
  7356. }
  7357. }
  7358. return com_rslt;
  7359. }
  7360. /*!
  7361. * @brief reads the Low g interrupt mapped to interrupt1
  7362. * and interrupt2 from the register 0x55 and 0x57
  7363. * @brief interrupt1 bit 0 in the register 0x55
  7364. * @brief interrupt2 bit 0 in the register 0x57
  7365. *
  7366. *
  7367. * @param v_channel_u8: The value of low_g selection
  7368. * v_channel_u8 | interrupt
  7369. * ---------------|---------------
  7370. * 0 | BMI160_INTR1_MAP_LOW_G
  7371. * 1 | BMI160_INTR2_MAP_LOW_G
  7372. *
  7373. * @param v_intr_low_g_u8 : The value of low_g enable
  7374. * value | interrupt enable
  7375. * ----------|-------------------
  7376. * 0x01 | BMI160_ENABLE
  7377. * 0x00 | BMI160_DISABLE
  7378. *
  7379. *
  7380. *
  7381. * @return results of bus communication function
  7382. * @retval 0 -> Success
  7383. * @retval -1 -> Error
  7384. *
  7385. *
  7386. */
  7387. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_low_g(
  7388. u8 v_channel_u8, u8 *v_intr_low_g_u8)
  7389. {
  7390. /* variable used for return the status of communication result*/
  7391. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7392. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  7393. /* check the p_bmi160 structure as NULL*/
  7394. if (p_bmi160 == BMI160_NULL) {
  7395. return E_BMI160_NULL_PTR;
  7396. } else {
  7397. switch (v_channel_u8) {
  7398. /* read the low_g interrupt */
  7399. case BMI160_INTR1_MAP_LOW_G:
  7400. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7401. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_LOW_G__REG,
  7402. &v_data_u8, C_BMI160_ONE_U8X);
  7403. *v_intr_low_g_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7404. BMI160_USER_INTR_MAP_0_INTR1_LOW_G);
  7405. break;
  7406. case BMI160_INTR2_MAP_LOW_G:
  7407. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7408. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_LOW_G__REG,
  7409. &v_data_u8, C_BMI160_ONE_U8X);
  7410. *v_intr_low_g_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7411. BMI160_USER_INTR_MAP_2_INTR2_LOW_G);
  7412. break;
  7413. default:
  7414. com_rslt = E_BMI160_OUT_OF_RANGE;
  7415. break;
  7416. }
  7417. }
  7418. return com_rslt;
  7419. }
  7420. /*!
  7421. * @brief set the Low g interrupt mapped to interrupt1
  7422. * and interrupt2 from the register 0x55 and 0x57
  7423. * @brief interrupt1 bit 0 in the register 0x55
  7424. * @brief interrupt2 bit 0 in the register 0x57
  7425. *
  7426. *
  7427. * @param v_channel_u8: The value of low_g selection
  7428. * v_channel_u8 | interrupt
  7429. * ---------------|---------------
  7430. * 0 | BMI160_INTR1_MAP_LOW_G
  7431. * 1 | BMI160_INTR2_MAP_LOW_G
  7432. *
  7433. * @param v_intr_low_g_u8 : The value of low_g enable
  7434. * value | interrupt enable
  7435. * ----------|-------------------
  7436. * 0x01 | BMI160_ENABLE
  7437. * 0x00 | BMI160_DISABLE
  7438. *
  7439. *
  7440. *
  7441. * @return results of bus communication function
  7442. * @retval 0 -> Success
  7443. * @retval -1 -> Error
  7444. *
  7445. *
  7446. */
  7447. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_low_g(
  7448. u8 v_channel_u8, u8 v_intr_low_g_u8)
  7449. {
  7450. /* variable used for return the status of communication result*/
  7451. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7452. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  7453. u8 v_step_cnt_stat_u8 = C_BMI160_ZERO_U8X;
  7454. u8 v_step_det_stat_u8 = C_BMI160_ZERO_U8X;
  7455. /* check the p_bmi160 structure as NULL*/
  7456. if (p_bmi160 == BMI160_NULL) {
  7457. return E_BMI160_NULL_PTR;
  7458. } else {
  7459. /* check the step detector interrupt enable status*/
  7460. com_rslt = bmi160_get_step_detector_enable(&v_step_det_stat_u8);
  7461. /* disable the step detector interrupt */
  7462. if (v_step_det_stat_u8 != C_BMI160_ZERO_U8X)
  7463. com_rslt += bmi160_set_step_detector_enable(C_BMI160_ZERO_U8X);
  7464. /* check the step counter interrupt enable status*/
  7465. com_rslt += bmi160_get_step_counter_enable(&v_step_cnt_stat_u8);
  7466. /* disable the step counter interrupt */
  7467. if (v_step_cnt_stat_u8 != C_BMI160_ZERO_U8X)
  7468. com_rslt += bmi160_set_step_counter_enable(
  7469. C_BMI160_ZERO_U8X);
  7470. switch (v_channel_u8) {
  7471. /* write the low_g interrupt*/
  7472. case BMI160_INTR1_MAP_LOW_G:
  7473. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7474. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_LOW_G__REG,
  7475. &v_data_u8, C_BMI160_ONE_U8X);
  7476. if (com_rslt == SUCCESS) {
  7477. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7478. BMI160_USER_INTR_MAP_0_INTR1_LOW_G, v_intr_low_g_u8);
  7479. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7480. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_LOW_G__REG,
  7481. &v_data_u8, C_BMI160_ONE_U8X);
  7482. }
  7483. break;
  7484. case BMI160_INTR2_MAP_LOW_G:
  7485. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7486. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_LOW_G__REG,
  7487. &v_data_u8, C_BMI160_ONE_U8X);
  7488. if (com_rslt == SUCCESS) {
  7489. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7490. BMI160_USER_INTR_MAP_2_INTR2_LOW_G, v_intr_low_g_u8);
  7491. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7492. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_LOW_G__REG,
  7493. &v_data_u8, C_BMI160_ONE_U8X);
  7494. }
  7495. break;
  7496. default:
  7497. com_rslt = E_BMI160_OUT_OF_RANGE;
  7498. break;
  7499. }
  7500. }
  7501. return com_rslt;
  7502. }
  7503. /*!
  7504. * @brief Reads the HIGH g interrupt mapped to interrupt1
  7505. * and interrupt2 from the register 0x55 and 0x57
  7506. * @brief interrupt1 bit 1 in the register 0x55
  7507. * @brief interrupt2 bit 1 in the register 0x57
  7508. *
  7509. *
  7510. * @param v_channel_u8: The value of high_g selection
  7511. * v_channel_u8 | interrupt
  7512. * ---------------|---------------
  7513. * 0 | BMI160_INTR1_MAP_HIGH_G
  7514. * 1 | BMI160_INTR2_MAP_HIGH_G
  7515. *
  7516. * @param v_intr_high_g_u8 : The value of high_g enable
  7517. * value | interrupt enable
  7518. * ----------|-------------------
  7519. * 0x01 | BMI160_ENABLE
  7520. * 0x00 | BMI160_DISABLE
  7521. *
  7522. *
  7523. *
  7524. *
  7525. * @return results of bus communication function
  7526. * @retval 0 -> Success
  7527. * @retval -1 -> Error
  7528. *
  7529. *
  7530. */
  7531. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_high_g(
  7532. u8 v_channel_u8, u8 *v_intr_high_g_u8)
  7533. {
  7534. /* variable used for return the status of communication result*/
  7535. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7536. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  7537. /* check the p_bmi160 structure as NULL*/
  7538. if (p_bmi160 == BMI160_NULL) {
  7539. return E_BMI160_NULL_PTR;
  7540. } else {
  7541. /* read the high_g interrupt*/
  7542. switch (v_channel_u8) {
  7543. case BMI160_INTR1_MAP_HIGH_G:
  7544. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7545. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_HIGH_G__REG,
  7546. &v_data_u8, C_BMI160_ONE_U8X);
  7547. *v_intr_high_g_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7548. BMI160_USER_INTR_MAP_0_INTR1_HIGH_G);
  7549. break;
  7550. case BMI160_INTR2_MAP_HIGH_G:
  7551. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7552. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_HIGH_G__REG,
  7553. &v_data_u8, C_BMI160_ONE_U8X);
  7554. *v_intr_high_g_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7555. BMI160_USER_INTR_MAP_2_INTR2_HIGH_G);
  7556. break;
  7557. default:
  7558. com_rslt = E_BMI160_OUT_OF_RANGE;
  7559. break;
  7560. }
  7561. }
  7562. return com_rslt;
  7563. }
  7564. /*!
  7565. * @brief Write the HIGH g interrupt mapped to interrupt1
  7566. * and interrupt2 from the register 0x55 and 0x57
  7567. * @brief interrupt1 bit 1 in the register 0x55
  7568. * @brief interrupt2 bit 1 in the register 0x57
  7569. *
  7570. *
  7571. * @param v_channel_u8: The value of high_g selection
  7572. * v_channel_u8 | interrupt
  7573. * ---------------|---------------
  7574. * 0 | BMI160_INTR1_MAP_HIGH_G
  7575. * 1 | BMI160_INTR2_MAP_HIGH_G
  7576. *
  7577. * @param v_intr_high_g_u8 : The value of high_g enable
  7578. * value | interrupt enable
  7579. * ----------|-------------------
  7580. * 0x01 | BMI160_ENABLE
  7581. * 0x00 | BMI160_DISABLE
  7582. *
  7583. *
  7584. *
  7585. *
  7586. * @return results of bus communication function
  7587. * @retval 0 -> Success
  7588. * @retval -1 -> Error
  7589. *
  7590. *
  7591. */
  7592. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_high_g(
  7593. u8 v_channel_u8, u8 v_intr_high_g_u8)
  7594. {
  7595. /* variable used for return the status of communication result*/
  7596. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7597. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  7598. /* check the p_bmi160 structure as NULL*/
  7599. if (p_bmi160 == BMI160_NULL) {
  7600. return E_BMI160_NULL_PTR;
  7601. } else {
  7602. switch (v_channel_u8) {
  7603. /* write the high_g interrupt*/
  7604. case BMI160_INTR1_MAP_HIGH_G:
  7605. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7606. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_HIGH_G__REG,
  7607. &v_data_u8, C_BMI160_ONE_U8X);
  7608. if (com_rslt == SUCCESS) {
  7609. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7610. BMI160_USER_INTR_MAP_0_INTR1_HIGH_G, v_intr_high_g_u8);
  7611. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7612. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_HIGH_G__REG,
  7613. &v_data_u8, C_BMI160_ONE_U8X);
  7614. }
  7615. break;
  7616. case BMI160_INTR2_MAP_HIGH_G:
  7617. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7618. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_HIGH_G__REG,
  7619. &v_data_u8, C_BMI160_ONE_U8X);
  7620. if (com_rslt == SUCCESS) {
  7621. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7622. BMI160_USER_INTR_MAP_2_INTR2_HIGH_G, v_intr_high_g_u8);
  7623. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7624. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_HIGH_G__REG,
  7625. &v_data_u8, C_BMI160_ONE_U8X);
  7626. }
  7627. break;
  7628. default:
  7629. com_rslt = E_BMI160_OUT_OF_RANGE;
  7630. break;
  7631. }
  7632. }
  7633. return com_rslt;
  7634. }
  7635. /*!
  7636. * @brief Reads the Any motion interrupt
  7637. * interrupt mapped to interrupt1
  7638. * and interrupt2 from the register 0x55 and 0x57
  7639. * @brief interrupt1 bit 2 in the register 0x55
  7640. * @brief interrupt2 bit 2 in the register 0x57
  7641. *
  7642. *
  7643. * @param v_channel_u8: The value of any motion selection
  7644. * v_channel_u8 | interrupt
  7645. * ---------------|---------------
  7646. * 0 | BMI160_INTR1_MAP_ANY_MOTION
  7647. * 1 | BMI160_INTR2_MAP_ANY_MOTION
  7648. *
  7649. * @param v_intr_any_motion_u8 : The value of any motion enable
  7650. * value | interrupt enable
  7651. * ----------|-------------------
  7652. * 0x01 | BMI160_ENABLE
  7653. * 0x00 | BMI160_DISABLE
  7654. *
  7655. *
  7656. *
  7657. * @return results of bus communication function
  7658. * @retval 0 -> Success
  7659. * @retval -1 -> Error
  7660. *
  7661. *
  7662. */
  7663. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_any_motion(
  7664. u8 v_channel_u8, u8 *v_intr_any_motion_u8)
  7665. {
  7666. /* variable used for return the status of communication result*/
  7667. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7668. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  7669. /* check the p_bmi160 structure as NULL*/
  7670. if (p_bmi160 == BMI160_NULL) {
  7671. return E_BMI160_NULL_PTR;
  7672. } else {
  7673. switch (v_channel_u8) {
  7674. /* read the any motion interrupt */
  7675. case BMI160_INTR1_MAP_ANY_MOTION:
  7676. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7677. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG,
  7678. &v_data_u8, C_BMI160_ONE_U8X);
  7679. *v_intr_any_motion_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7680. BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION);
  7681. break;
  7682. case BMI160_INTR2_MAP_ANY_MOTION:
  7683. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7684. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG,
  7685. &v_data_u8, C_BMI160_ONE_U8X);
  7686. *v_intr_any_motion_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7687. BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION);
  7688. break;
  7689. default:
  7690. com_rslt = E_BMI160_OUT_OF_RANGE;
  7691. break;
  7692. }
  7693. }
  7694. return com_rslt;
  7695. }
  7696. /*!
  7697. * @brief Write the Any motion interrupt
  7698. * interrupt mapped to interrupt1
  7699. * and interrupt2 from the register 0x55 and 0x57
  7700. * @brief interrupt1 bit 2 in the register 0x55
  7701. * @brief interrupt2 bit 2 in the register 0x57
  7702. *
  7703. *
  7704. * @param v_channel_u8: The value of any motion selection
  7705. * v_channel_u8 | interrupt
  7706. * ---------------|---------------
  7707. * 0 | BMI160_INTR1_MAP_ANY_MOTION
  7708. * 1 | BMI160_INTR2_MAP_ANY_MOTION
  7709. *
  7710. * @param v_intr_any_motion_u8 : The value of any motion enable
  7711. * value | interrupt enable
  7712. * ----------|-------------------
  7713. * 0x01 | BMI160_ENABLE
  7714. * 0x00 | BMI160_DISABLE
  7715. *
  7716. *
  7717. *
  7718. * @return results of bus communication function
  7719. * @retval 0 -> Success
  7720. * @retval -1 -> Error
  7721. *
  7722. *
  7723. */
  7724. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_any_motion(
  7725. u8 v_channel_u8, u8 v_intr_any_motion_u8)
  7726. {
  7727. /* variable used for return the status of communication result*/
  7728. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7729. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  7730. u8 sig_mot_stat = C_BMI160_ZERO_U8X;
  7731. /* check the p_bmi160 structure as NULL*/
  7732. if (p_bmi160 == BMI160_NULL) {
  7733. return E_BMI160_NULL_PTR;
  7734. } else {
  7735. /* read the status of significant motion interrupt */
  7736. com_rslt = bmi160_get_intr_significant_motion_select(&sig_mot_stat);
  7737. /* disable the significant motion interrupt */
  7738. if (sig_mot_stat != C_BMI160_ZERO_U8X)
  7739. com_rslt += bmi160_set_intr_significant_motion_select(
  7740. C_BMI160_ZERO_U8X);
  7741. switch (v_channel_u8) {
  7742. /* write the any motion interrupt */
  7743. case BMI160_INTR1_MAP_ANY_MOTION:
  7744. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7745. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG,
  7746. &v_data_u8, C_BMI160_ONE_U8X);
  7747. if (com_rslt == SUCCESS) {
  7748. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7749. BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION,
  7750. v_intr_any_motion_u8);
  7751. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7752. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG,
  7753. &v_data_u8, C_BMI160_ONE_U8X);
  7754. }
  7755. break;
  7756. case BMI160_INTR2_MAP_ANY_MOTION:
  7757. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7758. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG,
  7759. &v_data_u8, C_BMI160_ONE_U8X);
  7760. if (com_rslt == SUCCESS) {
  7761. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7762. BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION,
  7763. v_intr_any_motion_u8);
  7764. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7765. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG,
  7766. &v_data_u8, C_BMI160_ONE_U8X);
  7767. }
  7768. break;
  7769. default:
  7770. com_rslt = E_BMI160_OUT_OF_RANGE;
  7771. break;
  7772. }
  7773. }
  7774. return com_rslt;
  7775. }
  7776. /*!
  7777. * @brief Reads the No motion interrupt
  7778. * interrupt mapped to interrupt1
  7779. * and interrupt2 from the register 0x55 and 0x57
  7780. * @brief interrupt1 bit 3 in the register 0x55
  7781. * @brief interrupt2 bit 3 in the register 0x57
  7782. *
  7783. *
  7784. * @param v_channel_u8: The value of no motion selection
  7785. * v_channel_u8 | interrupt
  7786. * ---------------|---------------
  7787. * 0 | BMI160_INTR1_MAP_NOMO
  7788. * 1 | BMI160_INTR2_MAP_NOMO
  7789. *
  7790. * @param v_intr_nomotion_u8 : The value of no motion enable
  7791. * value | interrupt enable
  7792. * ----------|-------------------
  7793. * 0x01 | BMI160_ENABLE
  7794. * 0x00 | BMI160_DISABLE
  7795. *
  7796. *
  7797. * @return results of bus communication function
  7798. * @retval 0 -> Success
  7799. * @retval -1 -> Error
  7800. *
  7801. *
  7802. */
  7803. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_nomotion(
  7804. u8 v_channel_u8, u8 *v_intr_nomotion_u8)
  7805. {
  7806. /* variable used for return the status of communication result*/
  7807. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7808. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  7809. /* check the p_bmi160 structure as NULL*/
  7810. if (p_bmi160 == BMI160_NULL) {
  7811. return E_BMI160_NULL_PTR;
  7812. } else {
  7813. switch (v_channel_u8) {
  7814. /* read the no motion interrupt*/
  7815. case BMI160_INTR1_MAP_NOMO:
  7816. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7817. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_NOMOTION__REG,
  7818. &v_data_u8, C_BMI160_ONE_U8X);
  7819. *v_intr_nomotion_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7820. BMI160_USER_INTR_MAP_0_INTR1_NOMOTION);
  7821. break;
  7822. case BMI160_INTR2_MAP_NOMO:
  7823. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7824. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_NOMOTION__REG,
  7825. &v_data_u8, C_BMI160_ONE_U8X);
  7826. *v_intr_nomotion_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7827. BMI160_USER_INTR_MAP_2_INTR2_NOMOTION);
  7828. break;
  7829. default:
  7830. com_rslt = E_BMI160_OUT_OF_RANGE;
  7831. break;
  7832. }
  7833. }
  7834. return com_rslt;
  7835. }
  7836. /*!
  7837. * @brief Write the No motion interrupt
  7838. * interrupt mapped to interrupt1
  7839. * and interrupt2 from the register 0x55 and 0x57
  7840. * @brief interrupt1 bit 3 in the register 0x55
  7841. * @brief interrupt2 bit 3 in the register 0x57
  7842. *
  7843. *
  7844. * @param v_channel_u8: The value of no motion selection
  7845. * v_channel_u8 | interrupt
  7846. * ---------------|---------------
  7847. * 0 | BMI160_INTR1_MAP_NOMO
  7848. * 1 | BMI160_INTR2_MAP_NOMO
  7849. *
  7850. * @param v_intr_nomotion_u8 : The value of no motion enable
  7851. * value | interrupt enable
  7852. * ----------|-------------------
  7853. * 0x01 | BMI160_ENABLE
  7854. * 0x00 | BMI160_DISABLE
  7855. *
  7856. *
  7857. * @return results of bus communication function
  7858. * @retval 0 -> Success
  7859. * @retval -1 -> Error
  7860. *
  7861. *
  7862. */
  7863. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_nomotion(
  7864. u8 v_channel_u8, u8 v_intr_nomotion_u8)
  7865. {
  7866. /* variable used for return the status of communication result*/
  7867. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7868. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  7869. /* check the p_bmi160 structure as NULL*/
  7870. if (p_bmi160 == BMI160_NULL) {
  7871. return E_BMI160_NULL_PTR;
  7872. } else {
  7873. switch (v_channel_u8) {
  7874. /* write the no motion interrupt*/
  7875. case BMI160_INTR1_MAP_NOMO:
  7876. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7877. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_NOMOTION__REG,
  7878. &v_data_u8, C_BMI160_ONE_U8X);
  7879. if (com_rslt == SUCCESS) {
  7880. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7881. BMI160_USER_INTR_MAP_0_INTR1_NOMOTION,
  7882. v_intr_nomotion_u8);
  7883. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7884. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_NOMOTION__REG,
  7885. &v_data_u8, C_BMI160_ONE_U8X);
  7886. }
  7887. break;
  7888. case BMI160_INTR2_MAP_NOMO:
  7889. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7890. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_NOMOTION__REG,
  7891. &v_data_u8, C_BMI160_ONE_U8X);
  7892. if (com_rslt == SUCCESS) {
  7893. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  7894. BMI160_USER_INTR_MAP_2_INTR2_NOMOTION,
  7895. v_intr_nomotion_u8);
  7896. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  7897. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_NOMOTION__REG,
  7898. &v_data_u8, C_BMI160_ONE_U8X);
  7899. }
  7900. break;
  7901. default:
  7902. com_rslt = E_BMI160_OUT_OF_RANGE;
  7903. break;
  7904. }
  7905. }
  7906. return com_rslt;
  7907. }
  7908. /*!
  7909. * @brief Reads the Double Tap interrupt
  7910. * interrupt mapped to interrupt1
  7911. * and interrupt2 from the register 0x55 and 0x57
  7912. * @brief interrupt1 bit 4 in the register 0x55
  7913. * @brief interrupt2 bit 4 in the register 0x57
  7914. *
  7915. *
  7916. * @param v_channel_u8: The value of double tap interrupt selection
  7917. * v_channel_u8 | interrupt
  7918. * ---------------|---------------
  7919. * 0 | BMI160_INTR1_MAP_DOUBLE_TAP
  7920. * 1 | BMI160_INTR2_MAP_DOUBLE_TAP
  7921. *
  7922. * @param v_intr_double_tap_u8 : The value of double tap enable
  7923. * value | interrupt enable
  7924. * ----------|-------------------
  7925. * 0x01 | BMI160_ENABLE
  7926. * 0x00 | BMI160_DISABLE
  7927. *
  7928. * @return results of bus communication function
  7929. * @retval 0 -> Success
  7930. * @retval -1 -> Error
  7931. *
  7932. *
  7933. */
  7934. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_double_tap(
  7935. u8 v_channel_u8, u8 *v_intr_double_tap_u8)
  7936. {
  7937. /* variable used for return the status of communication result*/
  7938. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7939. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  7940. /* check the p_bmi160 structure as NULL*/
  7941. if (p_bmi160 == BMI160_NULL) {
  7942. return E_BMI160_NULL_PTR;
  7943. } else {
  7944. switch (v_channel_u8) {
  7945. case BMI160_INTR1_MAP_DOUBLE_TAP:
  7946. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7947. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_DOUBLE_TAP__REG,
  7948. &v_data_u8, C_BMI160_ONE_U8X);
  7949. *v_intr_double_tap_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7950. BMI160_USER_INTR_MAP_0_INTR1_DOUBLE_TAP);
  7951. break;
  7952. case BMI160_INTR2_MAP_DOUBLE_TAP:
  7953. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  7954. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_DOUBLE_TAP__REG,
  7955. &v_data_u8, C_BMI160_ONE_U8X);
  7956. *v_intr_double_tap_u8 = BMI160_GET_BITSLICE(v_data_u8,
  7957. BMI160_USER_INTR_MAP_2_INTR2_DOUBLE_TAP);
  7958. break;
  7959. default:
  7960. com_rslt = E_BMI160_OUT_OF_RANGE;
  7961. break;
  7962. }
  7963. }
  7964. return com_rslt;
  7965. }
  7966. /*!
  7967. * @brief Write the Double Tap interrupt
  7968. * interrupt mapped to interrupt1
  7969. * and interrupt2 from the register 0x55 and 0x57
  7970. * @brief interrupt1 bit 4 in the register 0x55
  7971. * @brief interrupt2 bit 4 in the register 0x57
  7972. *
  7973. *
  7974. * @param v_channel_u8: The value of double tap interrupt selection
  7975. * v_channel_u8 | interrupt
  7976. * ---------------|---------------
  7977. * 0 | BMI160_INTR1_MAP_DOUBLE_TAP
  7978. * 1 | BMI160_INTR2_MAP_DOUBLE_TAP
  7979. *
  7980. * @param v_intr_double_tap_u8 : The value of double tap enable
  7981. * value | interrupt enable
  7982. * ----------|-------------------
  7983. * 0x01 | BMI160_ENABLE
  7984. * 0x00 | BMI160_DISABLE
  7985. *
  7986. * @return results of bus communication function
  7987. * @retval 0 -> Success
  7988. * @retval -1 -> Error
  7989. *
  7990. *
  7991. */
  7992. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_double_tap(
  7993. u8 v_channel_u8, u8 v_intr_double_tap_u8)
  7994. {
  7995. /* variable used for return the status of communication result*/
  7996. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  7997. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  7998. /* check the p_bmi160 structure as NULL*/
  7999. if (p_bmi160 == BMI160_NULL) {
  8000. return E_BMI160_NULL_PTR;
  8001. } else {
  8002. switch (v_channel_u8) {
  8003. /* set the double tap interrupt */
  8004. case BMI160_INTR1_MAP_DOUBLE_TAP:
  8005. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8006. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_DOUBLE_TAP__REG,
  8007. &v_data_u8, C_BMI160_ONE_U8X);
  8008. if (com_rslt == SUCCESS) {
  8009. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  8010. BMI160_USER_INTR_MAP_0_INTR1_DOUBLE_TAP,
  8011. v_intr_double_tap_u8);
  8012. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8013. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_DOUBLE_TAP__REG,
  8014. &v_data_u8, C_BMI160_ONE_U8X);
  8015. }
  8016. break;
  8017. case BMI160_INTR2_MAP_DOUBLE_TAP:
  8018. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8019. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_DOUBLE_TAP__REG,
  8020. &v_data_u8, C_BMI160_ONE_U8X);
  8021. if (com_rslt == SUCCESS) {
  8022. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  8023. BMI160_USER_INTR_MAP_2_INTR2_DOUBLE_TAP,
  8024. v_intr_double_tap_u8);
  8025. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8026. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_DOUBLE_TAP__REG,
  8027. &v_data_u8, C_BMI160_ONE_U8X);
  8028. }
  8029. break;
  8030. default:
  8031. com_rslt = E_BMI160_OUT_OF_RANGE;
  8032. break;
  8033. }
  8034. }
  8035. return com_rslt;
  8036. }
  8037. /*!
  8038. * @brief Reads the Single Tap interrupt
  8039. * interrupt mapped to interrupt1
  8040. * and interrupt2 from the register 0x55 and 0x57
  8041. * @brief interrupt1 bit 5 in the register 0x55
  8042. * @brief interrupt2 bit 5 in the register 0x57
  8043. *
  8044. *
  8045. * @param v_channel_u8: The value of single tap interrupt selection
  8046. * v_channel_u8 | interrupt
  8047. * ---------------|---------------
  8048. * 0 | BMI160_INTR1_MAP_SINGLE_TAP
  8049. * 1 | BMI160_INTR2_MAP_SINGLE_TAP
  8050. *
  8051. * @param v_intr_single_tap_u8 : The value of single tap enable
  8052. * value | interrupt enable
  8053. * ----------|-------------------
  8054. * 0x01 | BMI160_ENABLE
  8055. * 0x00 | BMI160_DISABLE
  8056. *
  8057. *
  8058. * @return results of bus communication function
  8059. * @retval 0 -> Success
  8060. * @retval -1 -> Error
  8061. *
  8062. *
  8063. */
  8064. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_single_tap(
  8065. u8 v_channel_u8, u8 *v_intr_single_tap_u8)
  8066. {
  8067. /* variable used for return the status of communication result*/
  8068. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8069. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  8070. /* check the p_bmi160 structure as NULL*/
  8071. if (p_bmi160 == BMI160_NULL) {
  8072. return E_BMI160_NULL_PTR;
  8073. } else {
  8074. switch (v_channel_u8) {
  8075. /* reads the single tap interrupt*/
  8076. case BMI160_INTR1_MAP_SINGLE_TAP:
  8077. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8078. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_SINGLE_TAP__REG,
  8079. &v_data_u8, C_BMI160_ONE_U8X);
  8080. *v_intr_single_tap_u8 = BMI160_GET_BITSLICE(v_data_u8,
  8081. BMI160_USER_INTR_MAP_0_INTR1_SINGLE_TAP);
  8082. break;
  8083. case BMI160_INTR2_MAP_SINGLE_TAP:
  8084. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8085. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_SINGLE_TAP__REG,
  8086. &v_data_u8, C_BMI160_ONE_U8X);
  8087. *v_intr_single_tap_u8 = BMI160_GET_BITSLICE(v_data_u8,
  8088. BMI160_USER_INTR_MAP_2_INTR2_SINGLE_TAP);
  8089. break;
  8090. default:
  8091. com_rslt = E_BMI160_OUT_OF_RANGE;
  8092. break;
  8093. }
  8094. }
  8095. return com_rslt;
  8096. }
  8097. /*!
  8098. * @brief Write the Single Tap interrupt
  8099. * interrupt mapped to interrupt1
  8100. * and interrupt2 from the register 0x55 and 0x57
  8101. * @brief interrupt1 bit 5 in the register 0x55
  8102. * @brief interrupt2 bit 5 in the register 0x57
  8103. *
  8104. *
  8105. * @param v_channel_u8: The value of single tap interrupt selection
  8106. * v_channel_u8 | interrupt
  8107. * ---------------|---------------
  8108. * 0 | BMI160_INTR1_MAP_SINGLE_TAP
  8109. * 1 | BMI160_INTR2_MAP_SINGLE_TAP
  8110. *
  8111. * @param v_intr_single_tap_u8 : The value of single tap enable
  8112. * value | interrupt enable
  8113. * ----------|-------------------
  8114. * 0x01 | BMI160_ENABLE
  8115. * 0x00 | BMI160_DISABLE
  8116. *
  8117. *
  8118. * @return results of bus communication function
  8119. * @retval 0 -> Success
  8120. * @retval -1 -> Error
  8121. *
  8122. *
  8123. */
  8124. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_single_tap(
  8125. u8 v_channel_u8, u8 v_intr_single_tap_u8)
  8126. {
  8127. /* variable used for return the status of communication result*/
  8128. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8129. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  8130. /* check the p_bmi160 structure as NULL*/
  8131. if (p_bmi160 == BMI160_NULL) {
  8132. return E_BMI160_NULL_PTR;
  8133. } else {
  8134. switch (v_channel_u8) {
  8135. /* write the single tap interrupt */
  8136. case BMI160_INTR1_MAP_SINGLE_TAP:
  8137. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8138. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_SINGLE_TAP__REG,
  8139. &v_data_u8, C_BMI160_ONE_U8X);
  8140. if (com_rslt == SUCCESS) {
  8141. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  8142. BMI160_USER_INTR_MAP_0_INTR1_SINGLE_TAP,
  8143. v_intr_single_tap_u8);
  8144. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8145. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_SINGLE_TAP__REG,
  8146. &v_data_u8, C_BMI160_ONE_U8X);
  8147. }
  8148. break;
  8149. case BMI160_INTR2_MAP_SINGLE_TAP:
  8150. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8151. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_SINGLE_TAP__REG,
  8152. &v_data_u8, C_BMI160_ONE_U8X);
  8153. if (com_rslt == SUCCESS) {
  8154. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  8155. BMI160_USER_INTR_MAP_2_INTR2_SINGLE_TAP,
  8156. v_intr_single_tap_u8);
  8157. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8158. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_SINGLE_TAP__REG,
  8159. &v_data_u8, C_BMI160_ONE_U8X);
  8160. }
  8161. break;
  8162. default:
  8163. com_rslt = E_BMI160_OUT_OF_RANGE;
  8164. break;
  8165. }
  8166. }
  8167. return com_rslt;
  8168. }
  8169. /*!
  8170. * @brief Reads the Orient interrupt
  8171. * interrupt mapped to interrupt1
  8172. * and interrupt2 from the register 0x55 and 0x57
  8173. * @brief interrupt1 bit 6 in the register 0x55
  8174. * @brief interrupt2 bit 6 in the register 0x57
  8175. *
  8176. *
  8177. * @param v_channel_u8: The value of orient interrupt selection
  8178. * v_channel_u8 | interrupt
  8179. * ---------------|---------------
  8180. * 0 | BMI160_INTR1_MAP_ORIENT
  8181. * 1 | BMI160_INTR2_MAP_ORIENT
  8182. *
  8183. * @param v_intr_orient_u8 : The value of orient enable
  8184. * value | interrupt enable
  8185. * ----------|-------------------
  8186. * 0x01 | BMI160_ENABLE
  8187. * 0x00 | BMI160_DISABLE
  8188. *
  8189. *
  8190. *
  8191. * @return results of bus communication function
  8192. * @retval 0 -> Success
  8193. * @retval -1 -> Error
  8194. *
  8195. *
  8196. */
  8197. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_orient(
  8198. u8 v_channel_u8, u8 *v_intr_orient_u8)
  8199. {
  8200. /* variable used for return the status of communication result*/
  8201. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8202. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  8203. /* check the p_bmi160 structure as NULL*/
  8204. if (p_bmi160 == BMI160_NULL) {
  8205. return E_BMI160_NULL_PTR;
  8206. } else {
  8207. switch (v_channel_u8) {
  8208. /* read the orientation interrupt*/
  8209. case BMI160_INTR1_MAP_ORIENT:
  8210. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8211. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_ORIENT__REG,
  8212. &v_data_u8, C_BMI160_ONE_U8X);
  8213. *v_intr_orient_u8 = BMI160_GET_BITSLICE(v_data_u8,
  8214. BMI160_USER_INTR_MAP_0_INTR1_ORIENT);
  8215. break;
  8216. case BMI160_INTR2_MAP_ORIENT:
  8217. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8218. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_ORIENT__REG,
  8219. &v_data_u8, C_BMI160_ONE_U8X);
  8220. *v_intr_orient_u8 = BMI160_GET_BITSLICE(v_data_u8,
  8221. BMI160_USER_INTR_MAP_2_INTR2_ORIENT);
  8222. break;
  8223. default:
  8224. com_rslt = E_BMI160_OUT_OF_RANGE;
  8225. break;
  8226. }
  8227. }
  8228. return com_rslt;
  8229. }
  8230. /*!
  8231. * @brief Write the Orient interrupt
  8232. * interrupt mapped to interrupt1
  8233. * and interrupt2 from the register 0x55 and 0x57
  8234. * @brief interrupt1 bit 6 in the register 0x55
  8235. * @brief interrupt2 bit 6 in the register 0x57
  8236. *
  8237. *
  8238. * @param v_channel_u8: The value of orient interrupt selection
  8239. * v_channel_u8 | interrupt
  8240. * ---------------|---------------
  8241. * 0 | BMI160_INTR1_MAP_ORIENT
  8242. * 1 | BMI160_INTR2_MAP_ORIENT
  8243. *
  8244. * @param v_intr_orient_u8 : The value of orient enable
  8245. * value | interrupt enable
  8246. * ----------|-------------------
  8247. * 0x01 | BMI160_ENABLE
  8248. * 0x00 | BMI160_DISABLE
  8249. *
  8250. *
  8251. *
  8252. * @return results of bus communication function
  8253. * @retval 0 -> Success
  8254. * @retval -1 -> Error
  8255. *
  8256. *
  8257. */
  8258. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_orient(
  8259. u8 v_channel_u8, u8 v_intr_orient_u8)
  8260. {
  8261. /* variable used for return the status of communication result*/
  8262. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8263. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  8264. /* check the p_bmi160 structure as NULL*/
  8265. if (p_bmi160 == BMI160_NULL) {
  8266. return E_BMI160_NULL_PTR;
  8267. } else {
  8268. switch (v_channel_u8) {
  8269. /* write the orientation interrupt*/
  8270. case BMI160_INTR1_MAP_ORIENT:
  8271. com_rslt =
  8272. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8273. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_ORIENT__REG,
  8274. &v_data_u8, C_BMI160_ONE_U8X);
  8275. if (com_rslt == SUCCESS) {
  8276. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  8277. BMI160_USER_INTR_MAP_0_INTR1_ORIENT, v_intr_orient_u8);
  8278. com_rslt +=
  8279. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8280. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_ORIENT__REG,
  8281. &v_data_u8, C_BMI160_ONE_U8X);
  8282. }
  8283. break;
  8284. case BMI160_INTR2_MAP_ORIENT:
  8285. com_rslt =
  8286. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8287. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_ORIENT__REG,
  8288. &v_data_u8, C_BMI160_ONE_U8X);
  8289. if (com_rslt == SUCCESS) {
  8290. v_data_u8 =
  8291. BMI160_SET_BITSLICE(v_data_u8,
  8292. BMI160_USER_INTR_MAP_2_INTR2_ORIENT, v_intr_orient_u8);
  8293. com_rslt +=
  8294. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8295. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_ORIENT__REG,
  8296. &v_data_u8, C_BMI160_ONE_U8X);
  8297. }
  8298. break;
  8299. default:
  8300. com_rslt = E_BMI160_OUT_OF_RANGE;
  8301. break;
  8302. }
  8303. }
  8304. return com_rslt;
  8305. }
  8306. /*!
  8307. * @brief Reads the Flat interrupt
  8308. * mapped to interrupt1
  8309. * and interrupt2 from the register 0x55 and 0x57
  8310. * @brief interrupt1 bit 7 in the register 0x55
  8311. * @brief interrupt2 bit 7 in the register 0x57
  8312. *
  8313. *
  8314. * @param v_channel_u8: The value of flat interrupt selection
  8315. * v_channel_u8 | interrupt
  8316. * ---------------|---------------
  8317. * 0 | BMI160_INTR1_MAP_FLAT
  8318. * 1 | BMI160_INTR2_MAP_FLAT
  8319. *
  8320. * @param v_intr_flat_u8 : The value of flat enable
  8321. * value | interrupt enable
  8322. * ----------|-------------------
  8323. * 0x01 | BMI160_ENABLE
  8324. * 0x00 | BMI160_DISABLE
  8325. *
  8326. *
  8327. * @return results of bus communication function
  8328. * @retval 0 -> Success
  8329. * @retval -1 -> Error
  8330. *
  8331. *
  8332. */
  8333. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_flat(
  8334. u8 v_channel_u8, u8 *v_intr_flat_u8)
  8335. {
  8336. /* variable used for return the status of communication result*/
  8337. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8338. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  8339. /* check the p_bmi160 structure as NULL*/
  8340. if (p_bmi160 == BMI160_NULL) {
  8341. return E_BMI160_NULL_PTR;
  8342. } else {
  8343. switch (v_channel_u8) {
  8344. /* read the flat interrupt*/
  8345. case BMI160_INTR1_MAP_FLAT:
  8346. com_rslt =
  8347. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8348. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_FLAT__REG,
  8349. &v_data_u8, C_BMI160_ONE_U8X);
  8350. *v_intr_flat_u8 =
  8351. BMI160_GET_BITSLICE(v_data_u8,
  8352. BMI160_USER_INTR_MAP_0_INTR1_FLAT);
  8353. break;
  8354. case BMI160_INTR2_MAP_FLAT:
  8355. com_rslt =
  8356. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8357. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_FLAT__REG,
  8358. &v_data_u8, C_BMI160_ONE_U8X);
  8359. *v_intr_flat_u8 =
  8360. BMI160_GET_BITSLICE(v_data_u8,
  8361. BMI160_USER_INTR_MAP_2_INTR2_FLAT);
  8362. break;
  8363. default:
  8364. com_rslt = E_BMI160_OUT_OF_RANGE;
  8365. break;
  8366. }
  8367. }
  8368. return com_rslt;
  8369. }
  8370. /*!
  8371. * @brief Write the Flat interrupt
  8372. * mapped to interrupt1
  8373. * and interrupt2 from the register 0x55 and 0x57
  8374. * @brief interrupt1 bit 7 in the register 0x55
  8375. * @brief interrupt2 bit 7 in the register 0x57
  8376. *
  8377. *
  8378. * @param v_channel_u8: The value of flat interrupt selection
  8379. * v_channel_u8 | interrupt
  8380. * ---------------|---------------
  8381. * 0 | BMI160_INTR1_MAP_FLAT
  8382. * 1 | BMI160_INTR2_MAP_FLAT
  8383. *
  8384. * @param v_intr_flat_u8 : The value of flat enable
  8385. * value | interrupt enable
  8386. * ----------|-------------------
  8387. * 0x01 | BMI160_ENABLE
  8388. * 0x00 | BMI160_DISABLE
  8389. *
  8390. *
  8391. * @return results of bus communication function
  8392. * @retval 0 -> Success
  8393. * @retval -1 -> Error
  8394. *
  8395. *
  8396. */
  8397. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_flat(
  8398. u8 v_channel_u8, u8 v_intr_flat_u8)
  8399. {
  8400. /* variable used for return the status of communication result*/
  8401. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8402. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  8403. /* check the p_bmi160 structure as NULL*/
  8404. if (p_bmi160 == BMI160_NULL) {
  8405. return E_BMI160_NULL_PTR;
  8406. } else {
  8407. switch (v_channel_u8) {
  8408. /* write the flat interrupt */
  8409. case BMI160_INTR1_MAP_FLAT:
  8410. com_rslt =
  8411. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8412. dev_addr, BMI160_USER_INTR_MAP_0_INTR1_FLAT__REG,
  8413. &v_data_u8, C_BMI160_ONE_U8X);
  8414. if (com_rslt == SUCCESS) {
  8415. v_data_u8 =
  8416. BMI160_SET_BITSLICE(v_data_u8,
  8417. BMI160_USER_INTR_MAP_0_INTR1_FLAT,
  8418. v_intr_flat_u8);
  8419. com_rslt +=
  8420. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8421. dev_addr,
  8422. BMI160_USER_INTR_MAP_0_INTR1_FLAT__REG,
  8423. &v_data_u8, C_BMI160_ONE_U8X);
  8424. }
  8425. break;
  8426. case BMI160_INTR2_MAP_FLAT:
  8427. com_rslt =
  8428. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8429. dev_addr, BMI160_USER_INTR_MAP_2_INTR2_FLAT__REG,
  8430. &v_data_u8, C_BMI160_ONE_U8X);
  8431. if (com_rslt == SUCCESS) {
  8432. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  8433. BMI160_USER_INTR_MAP_2_INTR2_FLAT,
  8434. v_intr_flat_u8);
  8435. com_rslt +=
  8436. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8437. dev_addr,
  8438. BMI160_USER_INTR_MAP_2_INTR2_FLAT__REG,
  8439. &v_data_u8, C_BMI160_ONE_U8X);
  8440. }
  8441. break;
  8442. default:
  8443. com_rslt = E_BMI160_OUT_OF_RANGE;
  8444. break;
  8445. }
  8446. }
  8447. return com_rslt;
  8448. }
  8449. /*!
  8450. * @brief Reads PMU trigger interrupt mapped to interrupt1
  8451. * and interrupt2 form the register 0x56 bit 0 and 4
  8452. * @brief interrupt1 bit 0 in the register 0x56
  8453. * @brief interrupt2 bit 4 in the register 0x56
  8454. *
  8455. *
  8456. * @param v_channel_u8: The value of pmu trigger selection
  8457. * v_channel_u8 | interrupt
  8458. * ---------------|---------------
  8459. * 0 | BMI160_INTR1_MAP_PMUTRIG
  8460. * 1 | BMI160_INTR2_MAP_PMUTRIG
  8461. *
  8462. * @param v_intr_pmu_trig_u8 : The value of pmu trigger enable
  8463. * value | interrupt enable
  8464. * ----------|-------------------
  8465. * 0x01 | BMI160_ENABLE
  8466. * 0x00 | BMI160_DISABLE
  8467. *
  8468. *
  8469. * @return results of bus communication function
  8470. * @retval 0 -> Success
  8471. * @retval -1 -> Error
  8472. *
  8473. *
  8474. */
  8475. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_pmu_trig(
  8476. u8 v_channel_u8, u8 *v_intr_pmu_trig_u8)
  8477. {
  8478. /* variable used for return the status of communication result*/
  8479. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8480. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  8481. /* check the p_bmi160 structure as NULL*/
  8482. if (p_bmi160 == BMI160_NULL) {
  8483. return E_BMI160_NULL_PTR;
  8484. } else {
  8485. switch (v_channel_u8) {
  8486. /* read the pmu trigger interrupt*/
  8487. case BMI160_INTR1_MAP_PMUTRIG:
  8488. com_rslt =
  8489. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8490. dev_addr, BMI160_USER_INTR_MAP_1_INTR1_PMU_TRIG__REG,
  8491. &v_data_u8, C_BMI160_ONE_U8X);
  8492. *v_intr_pmu_trig_u8 =
  8493. BMI160_GET_BITSLICE(v_data_u8,
  8494. BMI160_USER_INTR_MAP_1_INTR1_PMU_TRIG);
  8495. break;
  8496. case BMI160_INTR2_MAP_PMUTRIG:
  8497. com_rslt =
  8498. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8499. dev_addr, BMI160_USER_INTR_MAP_1_INTR2_PMU_TRIG__REG,
  8500. &v_data_u8, C_BMI160_ONE_U8X);
  8501. *v_intr_pmu_trig_u8 =
  8502. BMI160_GET_BITSLICE(v_data_u8,
  8503. BMI160_USER_INTR_MAP_1_INTR2_PMU_TRIG);
  8504. break;
  8505. default:
  8506. com_rslt = E_BMI160_OUT_OF_RANGE;
  8507. break;
  8508. }
  8509. }
  8510. return com_rslt;
  8511. }
  8512. /*!
  8513. * @brief Write PMU trigger interrupt mapped to interrupt1
  8514. * and interrupt2 form the register 0x56 bit 0 and 4
  8515. * @brief interrupt1 bit 0 in the register 0x56
  8516. * @brief interrupt2 bit 4 in the register 0x56
  8517. *
  8518. *
  8519. * @param v_channel_u8: The value of pmu trigger selection
  8520. * v_channel_u8 | interrupt
  8521. * ---------------|---------------
  8522. * 0 | BMI160_INTR1_MAP_PMUTRIG
  8523. * 1 | BMI160_INTR2_MAP_PMUTRIG
  8524. *
  8525. * @param v_intr_pmu_trig_u8 : The value of pmu trigger enable
  8526. * value | trigger enable
  8527. * ----------|-------------------
  8528. * 0x01 | BMI160_ENABLE
  8529. * 0x00 | BMI160_DISABLE
  8530. *
  8531. *
  8532. * @return results of bus communication function
  8533. * @retval 0 -> Success
  8534. * @retval -1 -> Error
  8535. *
  8536. *
  8537. */
  8538. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_pmu_trig(
  8539. u8 v_channel_u8, u8 v_intr_pmu_trig_u8)
  8540. {
  8541. /* variable used for return the status of communication result*/
  8542. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8543. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  8544. /* check the p_bmi160 structure as NULL*/
  8545. if (p_bmi160 == BMI160_NULL) {
  8546. return E_BMI160_NULL_PTR;
  8547. } else {
  8548. switch (v_channel_u8) {
  8549. /* write the pmu trigger interrupt */
  8550. case BMI160_INTR1_MAP_PMUTRIG:
  8551. com_rslt =
  8552. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8553. dev_addr, BMI160_USER_INTR_MAP_1_INTR1_PMU_TRIG__REG,
  8554. &v_data_u8, C_BMI160_ONE_U8X);
  8555. if (com_rslt == SUCCESS) {
  8556. v_data_u8 =
  8557. BMI160_SET_BITSLICE(v_data_u8,
  8558. BMI160_USER_INTR_MAP_1_INTR1_PMU_TRIG,
  8559. v_intr_pmu_trig_u8);
  8560. com_rslt +=
  8561. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8562. dev_addr, BMI160_USER_INTR_MAP_1_INTR1_PMU_TRIG__REG,
  8563. &v_data_u8, C_BMI160_ONE_U8X);
  8564. }
  8565. break;
  8566. case BMI160_INTR2_MAP_PMUTRIG:
  8567. com_rslt =
  8568. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8569. dev_addr, BMI160_USER_INTR_MAP_1_INTR2_PMU_TRIG__REG,
  8570. &v_data_u8, C_BMI160_ONE_U8X);
  8571. if (com_rslt == SUCCESS) {
  8572. v_data_u8 =
  8573. BMI160_SET_BITSLICE(v_data_u8,
  8574. BMI160_USER_INTR_MAP_1_INTR2_PMU_TRIG,
  8575. v_intr_pmu_trig_u8);
  8576. com_rslt +=
  8577. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8578. dev_addr, BMI160_USER_INTR_MAP_1_INTR2_PMU_TRIG__REG,
  8579. &v_data_u8, C_BMI160_ONE_U8X);
  8580. }
  8581. break;
  8582. default:
  8583. com_rslt = E_BMI160_OUT_OF_RANGE;
  8584. break;
  8585. }
  8586. }
  8587. return com_rslt;
  8588. }
  8589. /*!
  8590. * @brief Reads FIFO Full interrupt mapped to interrupt1
  8591. * and interrupt2 form the register 0x56 bit 5 and 1
  8592. * @brief interrupt1 bit 5 in the register 0x56
  8593. * @brief interrupt2 bit 1 in the register 0x56
  8594. *
  8595. *
  8596. * @param v_channel_u8: The value of fifo full interrupt selection
  8597. * v_channel_u8 | interrupt
  8598. * ---------------|---------------
  8599. * 0 | BMI160_INTR1_MAP_FIFO_FULL
  8600. * 1 | BMI160_INTR2_MAP_FIFO_FULL
  8601. *
  8602. * @param v_intr_fifo_full_u8 : The value of fifo full interrupt enable
  8603. * value | interrupt enable
  8604. * ----------|-------------------
  8605. * 0x01 | BMI160_ENABLE
  8606. * 0x00 | BMI160_DISABLE
  8607. *
  8608. *
  8609. *
  8610. * @return results of bus communication function
  8611. * @retval 0 -> Success
  8612. * @retval -1 -> Error
  8613. *
  8614. *
  8615. */
  8616. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_fifo_full(
  8617. u8 v_channel_u8, u8 *v_intr_fifo_full_u8)
  8618. {
  8619. /* variable used for return the status of communication result*/
  8620. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8621. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  8622. /* check the p_bmi160 structure as NULL*/
  8623. if (p_bmi160 == BMI160_NULL) {
  8624. return E_BMI160_NULL_PTR;
  8625. } else {
  8626. switch (v_channel_u8) {
  8627. /* read the fifo full interrupt */
  8628. case BMI160_INTR1_MAP_FIFO_FULL:
  8629. com_rslt =
  8630. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8631. dev_addr, BMI160_USER_INTR_MAP_1_INTR1_FIFO_FULL__REG,
  8632. &v_data_u8, C_BMI160_ONE_U8X);
  8633. *v_intr_fifo_full_u8 =
  8634. BMI160_GET_BITSLICE(v_data_u8,
  8635. BMI160_USER_INTR_MAP_1_INTR1_FIFO_FULL);
  8636. break;
  8637. case BMI160_INTR2_MAP_FIFO_FULL:
  8638. com_rslt =
  8639. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8640. dev_addr, BMI160_USER_INTR_MAP_1_INTR2_FIFO_FULL__REG,
  8641. &v_data_u8, C_BMI160_ONE_U8X);
  8642. *v_intr_fifo_full_u8 =
  8643. BMI160_GET_BITSLICE(v_data_u8,
  8644. BMI160_USER_INTR_MAP_1_INTR2_FIFO_FULL);
  8645. break;
  8646. default:
  8647. com_rslt = E_BMI160_OUT_OF_RANGE;
  8648. break;
  8649. }
  8650. }
  8651. return com_rslt;
  8652. }
  8653. /*!
  8654. * @brief Write FIFO Full interrupt mapped to interrupt1
  8655. * and interrupt2 form the register 0x56 bit 5 and 1
  8656. * @brief interrupt1 bit 5 in the register 0x56
  8657. * @brief interrupt2 bit 1 in the register 0x56
  8658. *
  8659. *
  8660. * @param v_channel_u8: The value of fifo full interrupt selection
  8661. * v_channel_u8 | interrupt
  8662. * ---------------|---------------
  8663. * 0 | BMI160_INTR1_MAP_FIFO_FULL
  8664. * 1 | BMI160_INTR2_MAP_FIFO_FULL
  8665. *
  8666. * @param v_intr_fifo_full_u8 : The value of fifo full interrupt enable
  8667. * value | interrupt enable
  8668. * ----------|-------------------
  8669. * 0x01 | BMI160_ENABLE
  8670. * 0x00 | BMI160_DISABLE
  8671. *
  8672. *
  8673. *
  8674. * @return results of bus communication function
  8675. * @retval 0 -> Success
  8676. * @retval -1 -> Error
  8677. *
  8678. *
  8679. */
  8680. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_fifo_full(
  8681. u8 v_channel_u8, u8 v_intr_fifo_full_u8)
  8682. {
  8683. /* variable used for return the status of communication result*/
  8684. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8685. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  8686. /* check the p_bmi160 structure as NULL*/
  8687. if (p_bmi160 == BMI160_NULL) {
  8688. return E_BMI160_NULL_PTR;
  8689. } else {
  8690. switch (v_channel_u8) {
  8691. /* write the fifo full interrupt */
  8692. case BMI160_INTR1_MAP_FIFO_FULL:
  8693. com_rslt =
  8694. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8695. dev_addr, BMI160_USER_INTR_MAP_1_INTR1_FIFO_FULL__REG,
  8696. &v_data_u8, C_BMI160_ONE_U8X);
  8697. if (com_rslt == SUCCESS) {
  8698. v_data_u8 =
  8699. BMI160_SET_BITSLICE(v_data_u8,
  8700. BMI160_USER_INTR_MAP_1_INTR1_FIFO_FULL,
  8701. v_intr_fifo_full_u8);
  8702. com_rslt +=
  8703. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8704. dev_addr,
  8705. BMI160_USER_INTR_MAP_1_INTR1_FIFO_FULL__REG,
  8706. &v_data_u8, C_BMI160_ONE_U8X);
  8707. }
  8708. break;
  8709. case BMI160_INTR2_MAP_FIFO_FULL:
  8710. com_rslt =
  8711. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8712. dev_addr, BMI160_USER_INTR_MAP_1_INTR2_FIFO_FULL__REG,
  8713. &v_data_u8, C_BMI160_ONE_U8X);
  8714. if (com_rslt == SUCCESS) {
  8715. v_data_u8 =
  8716. BMI160_SET_BITSLICE(v_data_u8,
  8717. BMI160_USER_INTR_MAP_1_INTR2_FIFO_FULL,
  8718. v_intr_fifo_full_u8);
  8719. com_rslt +=
  8720. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8721. dev_addr,
  8722. BMI160_USER_INTR_MAP_1_INTR2_FIFO_FULL__REG,
  8723. &v_data_u8, C_BMI160_ONE_U8X);
  8724. }
  8725. break;
  8726. default:
  8727. com_rslt = E_BMI160_OUT_OF_RANGE;
  8728. break;
  8729. }
  8730. }
  8731. return com_rslt;
  8732. }
  8733. /*!
  8734. * @brief Reads FIFO Watermark interrupt mapped to interrupt1
  8735. * and interrupt2 form the register 0x56 bit 6 and 2
  8736. * @brief interrupt1 bit 6 in the register 0x56
  8737. * @brief interrupt2 bit 2 in the register 0x56
  8738. *
  8739. *
  8740. * @param v_channel_u8: The value of fifo Watermark interrupt selection
  8741. * v_channel_u8 | interrupt
  8742. * ---------------|---------------
  8743. * 0 | BMI160_INTR1_MAP_FIFO_WM
  8744. * 1 | BMI160_INTR2_MAP_FIFO_WM
  8745. *
  8746. * @param v_intr_fifo_wm_u8 : The value of fifo Watermark interrupt enable
  8747. * value | interrupt enable
  8748. * ----------|-------------------
  8749. * 0x01 | BMI160_ENABLE
  8750. * 0x00 | BMI160_DISABLE
  8751. *
  8752. *
  8753. *
  8754. *
  8755. * @return results of bus communication function
  8756. * @retval 0 -> Success
  8757. * @retval -1 -> Error
  8758. *
  8759. *
  8760. */
  8761. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_fifo_wm(
  8762. u8 v_channel_u8, u8 *v_intr_fifo_wm_u8)
  8763. {
  8764. /* variable used for return the status of communication result*/
  8765. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8766. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  8767. /* check the p_bmi160 structure as NULL*/
  8768. if (p_bmi160 == BMI160_NULL) {
  8769. return E_BMI160_NULL_PTR;
  8770. } else {
  8771. switch (v_channel_u8) {
  8772. /* read the fifo water mark interrupt */
  8773. case BMI160_INTR1_MAP_FIFO_WM:
  8774. com_rslt =
  8775. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8776. dev_addr, BMI160_USER_INTR_MAP_1_INTR1_FIFO_WM__REG,
  8777. &v_data_u8, C_BMI160_ONE_U8X);
  8778. *v_intr_fifo_wm_u8 =
  8779. BMI160_GET_BITSLICE(v_data_u8,
  8780. BMI160_USER_INTR_MAP_1_INTR1_FIFO_WM);
  8781. break;
  8782. case BMI160_INTR2_MAP_FIFO_WM:
  8783. com_rslt =
  8784. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8785. dev_addr, BMI160_USER_INTR_MAP_1_INTR2_FIFO_WM__REG,
  8786. &v_data_u8, C_BMI160_ONE_U8X);
  8787. *v_intr_fifo_wm_u8 =
  8788. BMI160_GET_BITSLICE(v_data_u8,
  8789. BMI160_USER_INTR_MAP_1_INTR2_FIFO_WM);
  8790. break;
  8791. default:
  8792. com_rslt = E_BMI160_OUT_OF_RANGE;
  8793. break;
  8794. }
  8795. }
  8796. return com_rslt;
  8797. }
  8798. /*!
  8799. * @brief Write FIFO Watermark interrupt mapped to interrupt1
  8800. * and interrupt2 form the register 0x56 bit 6 and 2
  8801. * @brief interrupt1 bit 6 in the register 0x56
  8802. * @brief interrupt2 bit 2 in the register 0x56
  8803. *
  8804. *
  8805. * @param v_channel_u8: The value of fifo Watermark interrupt selection
  8806. * v_channel_u8 | interrupt
  8807. * ---------------|---------------
  8808. * 0 | BMI160_INTR1_MAP_FIFO_WM
  8809. * 1 | BMI160_INTR2_MAP_FIFO_WM
  8810. *
  8811. * @param v_intr_fifo_wm_u8 : The value of fifo Watermark interrupt enable
  8812. * value | interrupt enable
  8813. * ----------|-------------------
  8814. * 0x01 | BMI160_ENABLE
  8815. * 0x00 | BMI160_DISABLE
  8816. *
  8817. *
  8818. *
  8819. *
  8820. * @return results of bus communication function
  8821. * @retval 0 -> Success
  8822. * @retval -1 -> Error
  8823. *
  8824. *
  8825. */
  8826. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_fifo_wm(
  8827. u8 v_channel_u8, u8 v_intr_fifo_wm_u8)
  8828. {
  8829. /* variable used for return the status of communication result*/
  8830. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8831. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  8832. /* check the p_bmi160 structure as NULL*/
  8833. if (p_bmi160 == BMI160_NULL) {
  8834. return E_BMI160_NULL_PTR;
  8835. } else {
  8836. switch (v_channel_u8) {
  8837. /* write the fifo water mark interrupt */
  8838. case BMI160_INTR1_MAP_FIFO_WM:
  8839. com_rslt =
  8840. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8841. dev_addr, BMI160_USER_INTR_MAP_1_INTR1_FIFO_WM__REG,
  8842. &v_data_u8, C_BMI160_ONE_U8X);
  8843. if (com_rslt == SUCCESS) {
  8844. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  8845. BMI160_USER_INTR_MAP_1_INTR1_FIFO_WM,
  8846. v_intr_fifo_wm_u8);
  8847. com_rslt +=
  8848. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8849. dev_addr,
  8850. BMI160_USER_INTR_MAP_1_INTR1_FIFO_WM__REG,
  8851. &v_data_u8, C_BMI160_ONE_U8X);
  8852. }
  8853. break;
  8854. case BMI160_INTR2_MAP_FIFO_WM:
  8855. com_rslt =
  8856. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8857. dev_addr, BMI160_USER_INTR_MAP_1_INTR2_FIFO_WM__REG,
  8858. &v_data_u8, C_BMI160_ONE_U8X);
  8859. if (com_rslt == SUCCESS) {
  8860. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  8861. BMI160_USER_INTR_MAP_1_INTR2_FIFO_WM,
  8862. v_intr_fifo_wm_u8);
  8863. com_rslt +=
  8864. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8865. dev_addr,
  8866. BMI160_USER_INTR_MAP_1_INTR2_FIFO_WM__REG,
  8867. &v_data_u8, C_BMI160_ONE_U8X);
  8868. }
  8869. break;
  8870. default:
  8871. com_rslt = E_BMI160_OUT_OF_RANGE;
  8872. break;
  8873. }
  8874. }
  8875. return com_rslt;
  8876. }
  8877. /*!
  8878. * @brief Reads Data Ready interrupt mapped to interrupt1
  8879. * and interrupt2 form the register 0x56
  8880. * @brief interrupt1 bit 7 in the register 0x56
  8881. * @brief interrupt2 bit 3 in the register 0x56
  8882. *
  8883. *
  8884. * @param v_channel_u8: The value of data ready interrupt selection
  8885. * v_channel_u8 | interrupt
  8886. * ---------------|---------------
  8887. * 0 | BMI160_INTR1_MAP_DATA_RDY
  8888. * 1 | BMI160_INTR2_MAP_DATA_RDY
  8889. *
  8890. * @param v_intr_data_rdy_u8 : The value of data ready interrupt enable
  8891. * value | interrupt enable
  8892. * ----------|-------------------
  8893. * 0x01 | BMI160_ENABLE
  8894. * 0x00 | BMI160_DISABLE
  8895. *
  8896. *
  8897. *
  8898. * @return results of bus communication function
  8899. * @retval 0 -> Success
  8900. * @retval -1 -> Error
  8901. *
  8902. *
  8903. */
  8904. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_data_rdy(
  8905. u8 v_channel_u8, u8 *v_intr_data_rdy_u8)
  8906. {
  8907. /* variable used for return the status of communication result*/
  8908. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8909. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  8910. /* check the p_bmi160 structure as NULL*/
  8911. if (p_bmi160 == BMI160_NULL) {
  8912. return E_BMI160_NULL_PTR;
  8913. } else {
  8914. switch (v_channel_u8) {
  8915. /*Read Data Ready interrupt*/
  8916. case BMI160_INTR1_MAP_DATA_RDY:
  8917. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8918. dev_addr, BMI160_USER_INTR_MAP_1_INTR1_DATA_RDY__REG,
  8919. &v_data_u8, C_BMI160_ONE_U8X);
  8920. *v_intr_data_rdy_u8 = BMI160_GET_BITSLICE(v_data_u8,
  8921. BMI160_USER_INTR_MAP_1_INTR1_DATA_RDY);
  8922. break;
  8923. case BMI160_INTR2_MAP_DATA_RDY:
  8924. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8925. dev_addr, BMI160_USER_INTR_MAP_1_INTR2_DATA_RDY__REG,
  8926. &v_data_u8, C_BMI160_ONE_U8X);
  8927. *v_intr_data_rdy_u8 = BMI160_GET_BITSLICE(v_data_u8,
  8928. BMI160_USER_INTR_MAP_1_INTR2_DATA_RDY);
  8929. break;
  8930. default:
  8931. com_rslt = E_BMI160_OUT_OF_RANGE;
  8932. break;
  8933. }
  8934. }
  8935. return com_rslt;
  8936. }
  8937. /*!
  8938. * @brief Write Data Ready interrupt mapped to interrupt1
  8939. * and interrupt2 form the register 0x56
  8940. * @brief interrupt1 bit 7 in the register 0x56
  8941. * @brief interrupt2 bit 3 in the register 0x56
  8942. *
  8943. *
  8944. * @param v_channel_u8: The value of data ready interrupt selection
  8945. * v_channel_u8 | interrupt
  8946. * ---------------|---------------
  8947. * 0 | BMI160_INTR1_MAP_DATA_RDY
  8948. * 1 | BMI160_INTR2_MAP_DATA_RDY
  8949. *
  8950. * @param v_intr_data_rdy_u8 : The value of data ready interrupt enable
  8951. * value | interrupt enable
  8952. * ----------|-------------------
  8953. * 0x01 | BMI160_ENABLE
  8954. * 0x00 | BMI160_DISABLE
  8955. *
  8956. *
  8957. *
  8958. * @return results of bus communication function
  8959. * @retval 0 -> Success
  8960. * @retval -1 -> Error
  8961. *
  8962. *
  8963. */
  8964. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_data_rdy(
  8965. u8 v_channel_u8, u8 v_intr_data_rdy_u8)
  8966. {
  8967. /* variable used for return the status of communication result*/
  8968. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  8969. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  8970. /* check the p_bmi160 structure as NULL*/
  8971. if (p_bmi160 == BMI160_NULL) {
  8972. return E_BMI160_NULL_PTR;
  8973. } else {
  8974. switch (v_channel_u8) {
  8975. /*Write Data Ready interrupt*/
  8976. case BMI160_INTR1_MAP_DATA_RDY:
  8977. com_rslt =
  8978. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8979. dev_addr, BMI160_USER_INTR_MAP_1_INTR1_DATA_RDY__REG,
  8980. &v_data_u8, C_BMI160_ONE_U8X);
  8981. if (com_rslt == SUCCESS) {
  8982. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  8983. BMI160_USER_INTR_MAP_1_INTR1_DATA_RDY,
  8984. v_intr_data_rdy_u8);
  8985. com_rslt +=
  8986. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  8987. dev_addr, BMI160_USER_INTR_MAP_1_INTR1_DATA_RDY__REG,
  8988. &v_data_u8, C_BMI160_ONE_U8X);
  8989. }
  8990. break;
  8991. case BMI160_INTR2_MAP_DATA_RDY:
  8992. com_rslt =
  8993. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->
  8994. dev_addr, BMI160_USER_INTR_MAP_1_INTR2_DATA_RDY__REG,
  8995. &v_data_u8, C_BMI160_ONE_U8X);
  8996. if (com_rslt == SUCCESS) {
  8997. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  8998. BMI160_USER_INTR_MAP_1_INTR2_DATA_RDY,
  8999. v_intr_data_rdy_u8);
  9000. com_rslt +=
  9001. p_bmi160->BMI160_BUS_WRITE_FUNC(p_bmi160->
  9002. dev_addr, BMI160_USER_INTR_MAP_1_INTR2_DATA_RDY__REG,
  9003. &v_data_u8, C_BMI160_ONE_U8X);
  9004. }
  9005. break;
  9006. default:
  9007. com_rslt = E_BMI160_OUT_OF_RANGE;
  9008. break;
  9009. }
  9010. }
  9011. return com_rslt;
  9012. }
  9013. /*!
  9014. * @brief This API reads data source for the interrupt
  9015. * engine for the single and double tap interrupts from the register
  9016. * 0x58 bit 3
  9017. *
  9018. *
  9019. * @param v_tap_source_u8 : The value of the tap source
  9020. * value | Description
  9021. * ----------|-------------------
  9022. * 0x01 | UNFILTER_DATA
  9023. * 0x00 | FILTER_DATA
  9024. *
  9025. *
  9026. * @return results of bus communication function
  9027. * @retval 0 -> Success
  9028. * @retval -1 -> Error
  9029. *
  9030. *
  9031. */
  9032. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_tap_source(u8 *v_tap_source_u8)
  9033. {
  9034. /* variable used for return the status of communication result*/
  9035. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9036. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  9037. /* check the p_bmi160 structure as NULL*/
  9038. if (p_bmi160 == BMI160_NULL) {
  9039. return E_BMI160_NULL_PTR;
  9040. } else {
  9041. /* read the tap source interrupt */
  9042. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  9043. p_bmi160->dev_addr,
  9044. BMI160_USER_INTR_DATA_0_INTR_TAP_SOURCE__REG,
  9045. &v_data_u8, C_BMI160_ONE_U8X);
  9046. *v_tap_source_u8 = BMI160_GET_BITSLICE(v_data_u8,
  9047. BMI160_USER_INTR_DATA_0_INTR_TAP_SOURCE);
  9048. }
  9049. return com_rslt;
  9050. }
  9051. /*!
  9052. * @brief This API write data source for the interrupt
  9053. * engine for the single and double tap interrupts from the register
  9054. * 0x58 bit 3
  9055. *
  9056. *
  9057. * @param v_tap_source_u8 : The value of the tap source
  9058. * value | Description
  9059. * ----------|-------------------
  9060. * 0x01 | UNFILTER_DATA
  9061. * 0x00 | FILTER_DATA
  9062. *
  9063. *
  9064. * @return results of bus communication function
  9065. * @retval 0 -> Success
  9066. * @retval -1 -> Error
  9067. *
  9068. *
  9069. */
  9070. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_tap_source(
  9071. u8 v_tap_source_u8)
  9072. {
  9073. /* variable used for return the status of communication result*/
  9074. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9075. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  9076. /* check the p_bmi160 structure as NULL*/
  9077. if (p_bmi160 == BMI160_NULL) {
  9078. return E_BMI160_NULL_PTR;
  9079. } else {
  9080. if (v_tap_source_u8 < C_BMI160_TWO_U8X) {
  9081. /* write the tap source interrupt */
  9082. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  9083. (p_bmi160->dev_addr,
  9084. BMI160_USER_INTR_DATA_0_INTR_TAP_SOURCE__REG,
  9085. &v_data_u8, C_BMI160_ONE_U8X);
  9086. if (com_rslt == SUCCESS) {
  9087. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  9088. BMI160_USER_INTR_DATA_0_INTR_TAP_SOURCE,
  9089. v_tap_source_u8);
  9090. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  9091. (p_bmi160->dev_addr,
  9092. BMI160_USER_INTR_DATA_0_INTR_TAP_SOURCE__REG,
  9093. &v_data_u8, C_BMI160_ONE_U8X);
  9094. }
  9095. } else {
  9096. com_rslt = E_BMI160_OUT_OF_RANGE;
  9097. }
  9098. }
  9099. return com_rslt;
  9100. }
  9101. /*!
  9102. * @brief This API Reads Data source for the
  9103. * interrupt engine for the low and high g interrupts
  9104. * from the register 0x58 bit 7
  9105. *
  9106. * @param v_low_high_source_u8 : The value of the tap source
  9107. * value | Description
  9108. * ----------|-------------------
  9109. * 0x01 | UNFILTER_DATA
  9110. * 0x00 | FILTER_DATA
  9111. *
  9112. *
  9113. * @return results of bus communication function
  9114. * @retval 0 -> Success
  9115. * @retval -1 -> Error
  9116. *
  9117. *
  9118. */
  9119. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_low_high_source(
  9120. u8 *v_low_high_source_u8)
  9121. {
  9122. /* variable used for return the status of communication result*/
  9123. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9124. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  9125. /* check the p_bmi160 structure as NULL*/
  9126. if (p_bmi160 == BMI160_NULL) {
  9127. return E_BMI160_NULL_PTR;
  9128. } else {
  9129. /* read the high_low_g source interrupt */
  9130. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  9131. p_bmi160->dev_addr,
  9132. BMI160_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE__REG,
  9133. &v_data_u8, C_BMI160_ONE_U8X);
  9134. *v_low_high_source_u8 = BMI160_GET_BITSLICE(v_data_u8,
  9135. BMI160_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE);
  9136. }
  9137. return com_rslt;
  9138. }
  9139. /*!
  9140. * @brief This API write Data source for the
  9141. * interrupt engine for the low and high g interrupts
  9142. * from the register 0x58 bit 7
  9143. *
  9144. * @param v_low_high_source_u8 : The value of the tap source
  9145. * value | Description
  9146. * ----------|-------------------
  9147. * 0x01 | UNFILTER_DATA
  9148. * 0x00 | FILTER_DATA
  9149. *
  9150. *
  9151. * @return results of bus communication function
  9152. * @retval 0 -> Success
  9153. * @retval -1 -> Error
  9154. *
  9155. *
  9156. */
  9157. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_low_high_source(
  9158. u8 v_low_high_source_u8)
  9159. {
  9160. /* variable used for return the status of communication result*/
  9161. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9162. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  9163. /* check the p_bmi160 structure as NULL*/
  9164. if (p_bmi160 == BMI160_NULL) {
  9165. return E_BMI160_NULL_PTR;
  9166. } else {
  9167. if (v_low_high_source_u8 < C_BMI160_TWO_U8X) {
  9168. /* write the high_low_g source interrupt */
  9169. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  9170. (p_bmi160->dev_addr,
  9171. BMI160_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE__REG,
  9172. &v_data_u8, C_BMI160_ONE_U8X);
  9173. if (com_rslt == SUCCESS) {
  9174. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  9175. BMI160_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE,
  9176. v_low_high_source_u8);
  9177. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  9178. (p_bmi160->dev_addr,
  9179. BMI160_USER_INTR_DATA_0_INTR_LOW_HIGH_SOURCE__REG,
  9180. &v_data_u8, C_BMI160_ONE_U8X);
  9181. }
  9182. } else {
  9183. com_rslt = E_BMI160_OUT_OF_RANGE;
  9184. }
  9185. }
  9186. return com_rslt;
  9187. }
  9188. /*!
  9189. * @brief This API reads Data source for the
  9190. * interrupt engine for the nomotion and anymotion interrupts
  9191. * from the register 0x59 bit 7
  9192. *
  9193. * @param v_motion_source_u8 :
  9194. * The value of the any/no motion interrupt source
  9195. * value | Description
  9196. * ----------|-------------------
  9197. * 0x01 | UNFILTER_DATA
  9198. * 0x00 | FILTER_DATA
  9199. *
  9200. * @return results of bus communication function
  9201. * @retval 0 -> Success
  9202. * @retval -1 -> Error
  9203. *
  9204. *
  9205. */
  9206. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_motion_source(
  9207. u8 *v_motion_source_u8)
  9208. {
  9209. /* variable used for return the status of communication result*/
  9210. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9211. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  9212. /* check the p_bmi160 structure as NULL*/
  9213. if (p_bmi160 == BMI160_NULL) {
  9214. return E_BMI160_NULL_PTR;
  9215. } else {
  9216. /* read the any/no motion interrupt */
  9217. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  9218. p_bmi160->dev_addr,
  9219. BMI160_USER_INTR_DATA_1_INTR_MOTION_SOURCE__REG,
  9220. &v_data_u8, C_BMI160_ONE_U8X);
  9221. *v_motion_source_u8 = BMI160_GET_BITSLICE(v_data_u8,
  9222. BMI160_USER_INTR_DATA_1_INTR_MOTION_SOURCE);
  9223. }
  9224. return com_rslt;
  9225. }
  9226. /*!
  9227. * @brief This API write Data source for the
  9228. * interrupt engine for the nomotion and anymotion interrupts
  9229. * from the register 0x59 bit 7
  9230. *
  9231. * @param v_motion_source_u8 :
  9232. * The value of the any/no motion interrupt source
  9233. * value | Description
  9234. * ----------|-------------------
  9235. * 0x01 | UNFILTER_DATA
  9236. * 0x00 | FILTER_DATA
  9237. *
  9238. * @return results of bus communication function
  9239. * @retval 0 -> Success
  9240. * @retval -1 -> Error
  9241. *
  9242. *
  9243. */
  9244. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_motion_source(
  9245. u8 v_motion_source_u8)
  9246. {
  9247. /* variable used for return the status of communication result*/
  9248. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9249. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  9250. /* check the p_bmi160 structure as NULL*/
  9251. if (p_bmi160 == BMI160_NULL) {
  9252. return E_BMI160_NULL_PTR;
  9253. } else {
  9254. if (v_motion_source_u8 < C_BMI160_TWO_U8X) {
  9255. /* write the any/no motion interrupt */
  9256. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  9257. p_bmi160->dev_addr,
  9258. BMI160_USER_INTR_DATA_1_INTR_MOTION_SOURCE__REG,
  9259. &v_data_u8, C_BMI160_ONE_U8X);
  9260. if (com_rslt == SUCCESS) {
  9261. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  9262. BMI160_USER_INTR_DATA_1_INTR_MOTION_SOURCE,
  9263. v_motion_source_u8);
  9264. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  9265. p_bmi160->dev_addr,
  9266. BMI160_USER_INTR_DATA_1_INTR_MOTION_SOURCE__REG,
  9267. &v_data_u8, C_BMI160_ONE_U8X);
  9268. }
  9269. } else {
  9270. com_rslt = E_BMI160_OUT_OF_RANGE;
  9271. }
  9272. }
  9273. return com_rslt;
  9274. }
  9275. /*!
  9276. * @brief This API is used to read the low_g duration from register
  9277. * 0x5A bit 0 to 7
  9278. *
  9279. *
  9280. *
  9281. *
  9282. * @param v_low_g_durn_u8 : The value of low_g duration
  9283. *
  9284. * @note Low_g duration trigger trigger delay according to
  9285. * "(v_low_g_durn_u8 * 2.5)ms" in a range from 2.5ms to 640ms.
  9286. * the default corresponds delay is 20ms
  9287. * @note When low_g data source of interrupt is unfiltered
  9288. * the sensor must not be in low power mode
  9289. *
  9290. * @return results of bus communication function
  9291. * @retval 0 -> Success
  9292. * @retval -1 -> Error
  9293. *
  9294. *
  9295. */
  9296. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_low_g_durn(
  9297. u8 *v_low_g_durn_u8)
  9298. {
  9299. /* variable used for return the status of communication result*/
  9300. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9301. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  9302. /* check the p_bmi160 structure as NULL*/
  9303. if (p_bmi160 == BMI160_NULL) {
  9304. return E_BMI160_NULL_PTR;
  9305. } else {
  9306. /* read the low_g interrupt */
  9307. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  9308. p_bmi160->dev_addr,
  9309. BMI160_USER_INTR_LOWHIGH_0_INTR_LOW_DURN__REG,
  9310. &v_data_u8, C_BMI160_ONE_U8X);
  9311. *v_low_g_durn_u8 =
  9312. BMI160_GET_BITSLICE(v_data_u8,
  9313. BMI160_USER_INTR_LOWHIGH_0_INTR_LOW_DURN);
  9314. }
  9315. return com_rslt;
  9316. }
  9317. /*!
  9318. * @brief This API is used to write the low_g duration from register
  9319. * 0x5A bit 0 to 7
  9320. *
  9321. *
  9322. *
  9323. *
  9324. * @param v_low_g_durn_u8 : The value of low_g duration
  9325. *
  9326. * @note Low_g duration trigger trigger delay according to
  9327. * "(v_low_g_durn_u8 * 2.5)ms" in a range from 2.5ms to 640ms.
  9328. * the default corresponds delay is 20ms
  9329. * @note When low_g data source of interrupt is unfiltered
  9330. * the sensor must not be in low power mode
  9331. *
  9332. * @return results of bus communication function
  9333. * @retval 0 -> Success
  9334. * @retval -1 -> Error
  9335. *
  9336. *
  9337. */
  9338. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_low_g_durn(u8 v_low_g_durn_u8)
  9339. {
  9340. /* variable used for return the status of communication result*/
  9341. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9342. /* check the p_bmi160 structure as NULL*/
  9343. if (p_bmi160 == BMI160_NULL) {
  9344. return E_BMI160_NULL_PTR;
  9345. } else {
  9346. /* write the low_g interrupt */
  9347. com_rslt = p_bmi160->BMI160_BUS_WRITE_FUNC(
  9348. p_bmi160->dev_addr,
  9349. BMI160_USER_INTR_LOWHIGH_0_INTR_LOW_DURN__REG,
  9350. &v_low_g_durn_u8, C_BMI160_ONE_U8X);
  9351. }
  9352. return com_rslt;
  9353. }
  9354. /*!
  9355. * @brief This API is used to read Threshold
  9356. * definition for the low-g interrupt from the register 0x5B bit 0 to 7
  9357. *
  9358. *
  9359. *
  9360. *
  9361. * @param v_low_g_thres_u8 : The value of low_g threshold
  9362. *
  9363. * @note Low_g interrupt trigger threshold according to
  9364. * (v_low_g_thres_u8 * 7.81)mg for v_low_g_thres_u8 > 0
  9365. * 3.91 mg for v_low_g_thres_u8 = 0
  9366. * The threshold range is form 3.91mg to 2.000mg
  9367. *
  9368. *
  9369. * @return results of bus communication function
  9370. * @retval 0 -> Success
  9371. * @retval -1 -> Error
  9372. *
  9373. *
  9374. */
  9375. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_low_g_thres(
  9376. u8 *v_low_g_thres_u8)
  9377. {
  9378. /* variable used for return the status of communication result*/
  9379. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9380. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  9381. /* check the p_bmi160 structure as NULL*/
  9382. if (p_bmi160 == BMI160_NULL) {
  9383. return E_BMI160_NULL_PTR;
  9384. } else {
  9385. /* read low_g threshold */
  9386. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  9387. p_bmi160->dev_addr,
  9388. BMI160_USER_INTR_LOWHIGH_1_INTR_LOW_THRES__REG,
  9389. &v_data_u8, C_BMI160_ONE_U8X);
  9390. *v_low_g_thres_u8 =
  9391. BMI160_GET_BITSLICE(v_data_u8,
  9392. BMI160_USER_INTR_LOWHIGH_1_INTR_LOW_THRES);
  9393. }
  9394. return com_rslt;
  9395. }
  9396. /*!
  9397. * @brief This API is used to write Threshold
  9398. * definition for the low-g interrupt from the register 0x5B bit 0 to 7
  9399. *
  9400. *
  9401. *
  9402. *
  9403. * @param v_low_g_thres_u8 : The value of low_g threshold
  9404. *
  9405. * @note Low_g interrupt trigger threshold according to
  9406. * (v_low_g_thres_u8 * 7.81)mg for v_low_g_thres_u8 > 0
  9407. * 3.91 mg for v_low_g_thres_u8 = 0
  9408. * The threshold range is form 3.91mg to 2.000mg
  9409. *
  9410. *
  9411. * @return results of bus communication function
  9412. * @retval 0 -> Success
  9413. * @retval -1 -> Error
  9414. *
  9415. *
  9416. */
  9417. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_low_g_thres(
  9418. u8 v_low_g_thres_u8)
  9419. {
  9420. /* variable used for return the status of communication result*/
  9421. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9422. /* check the p_bmi160 structure as NULL*/
  9423. if (p_bmi160 == BMI160_NULL) {
  9424. return E_BMI160_NULL_PTR;
  9425. } else {
  9426. /* write low_g threshold */
  9427. com_rslt = p_bmi160->BMI160_BUS_WRITE_FUNC(
  9428. p_bmi160->dev_addr,
  9429. BMI160_USER_INTR_LOWHIGH_1_INTR_LOW_THRES__REG,
  9430. &v_low_g_thres_u8, C_BMI160_ONE_U8X);
  9431. }
  9432. return com_rslt;
  9433. }
  9434. /*!
  9435. * @brief This API Reads Low-g interrupt hysteresis
  9436. * from the register 0x5C bit 0 to 1
  9437. *
  9438. * @param v_low_hyst_u8 :The value of low_g hysteresis
  9439. *
  9440. * @note Low_g hysteresis calculated by v_low_hyst_u8*125 mg
  9441. *
  9442. * @return results of bus communication function
  9443. * @retval 0 -> Success
  9444. * @retval -1 -> Error
  9445. *
  9446. *
  9447. */
  9448. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_low_g_hyst(
  9449. u8 *v_low_hyst_u8)
  9450. {
  9451. /* variable used for return the status of communication result*/
  9452. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9453. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  9454. /* check the p_bmi160 structure as NULL*/
  9455. if (p_bmi160 == BMI160_NULL) {
  9456. return E_BMI160_NULL_PTR;
  9457. } else {
  9458. /* read low_g hysteresis*/
  9459. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  9460. p_bmi160->dev_addr,
  9461. BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST__REG,
  9462. &v_data_u8, C_BMI160_ONE_U8X);
  9463. *v_low_hyst_u8 = BMI160_GET_BITSLICE(
  9464. v_data_u8,
  9465. BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST);
  9466. }
  9467. return com_rslt;
  9468. }
  9469. /*!
  9470. * @brief This API write Low-g interrupt hysteresis
  9471. * from the register 0x5C bit 0 to 1
  9472. *
  9473. * @param v_low_hyst_u8 :The value of low_g hysteresis
  9474. *
  9475. * @note Low_g hysteresis calculated by v_low_hyst_u8*125 mg
  9476. *
  9477. * @return results of bus communication function
  9478. * @retval 0 -> Success
  9479. * @retval -1 -> Error
  9480. *
  9481. *
  9482. */
  9483. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_low_g_hyst(
  9484. u8 v_low_hyst_u8)
  9485. {
  9486. /* variable used for return the status of communication result*/
  9487. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9488. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  9489. /* check the p_bmi160 structure as NULL*/
  9490. if (p_bmi160 == BMI160_NULL) {
  9491. return E_BMI160_NULL_PTR;
  9492. } else {
  9493. /* write low_g hysteresis*/
  9494. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  9495. (p_bmi160->dev_addr,
  9496. BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST__REG,
  9497. &v_data_u8, C_BMI160_ONE_U8X);
  9498. if (com_rslt == SUCCESS) {
  9499. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  9500. BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST,
  9501. v_low_hyst_u8);
  9502. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  9503. p_bmi160->dev_addr,
  9504. BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_HYST__REG,
  9505. &v_data_u8, C_BMI160_ONE_U8X);
  9506. }
  9507. }
  9508. return com_rslt;
  9509. }
  9510. /*!
  9511. * @brief This API reads Low-g interrupt mode
  9512. * from the register 0x5C bit 2
  9513. *
  9514. * @param v_low_g_mode_u8 : The value of low_g mode
  9515. * Value | Description
  9516. * ----------|-----------------
  9517. * 0 | single-axis
  9518. * 1 | axis-summing
  9519. *
  9520. *
  9521. * @return results of bus communication function
  9522. * @retval 0 -> Success
  9523. * @retval -1 -> Error
  9524. *
  9525. *
  9526. */
  9527. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_low_g_mode(u8 *v_low_g_mode_u8)
  9528. {
  9529. /* variable used for return the status of communication result*/
  9530. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9531. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  9532. /* check the p_bmi160 structure as NULL*/
  9533. if (p_bmi160 == BMI160_NULL) {
  9534. return E_BMI160_NULL_PTR;
  9535. } else {
  9536. /*read Low-g interrupt mode*/
  9537. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  9538. p_bmi160->dev_addr,
  9539. BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE__REG,
  9540. &v_data_u8, C_BMI160_ONE_U8X);
  9541. *v_low_g_mode_u8 = BMI160_GET_BITSLICE(v_data_u8,
  9542. BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE);
  9543. }
  9544. return com_rslt;
  9545. }
  9546. /*!
  9547. * @brief This API write Low-g interrupt mode
  9548. * from the register 0x5C bit 2
  9549. *
  9550. * @param v_low_g_mode_u8 : The value of low_g mode
  9551. * Value | Description
  9552. * ----------|-----------------
  9553. * 0 | single-axis
  9554. * 1 | axis-summing
  9555. *
  9556. *
  9557. * @return results of bus communication function
  9558. * @retval 0 -> Success
  9559. * @retval -1 -> Error
  9560. *
  9561. *
  9562. */
  9563. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_low_g_mode(
  9564. u8 v_low_g_mode_u8)
  9565. {
  9566. /* variable used for return the status of communication result*/
  9567. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9568. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  9569. /* check the p_bmi160 structure as NULL*/
  9570. if (p_bmi160 == BMI160_NULL) {
  9571. return E_BMI160_NULL_PTR;
  9572. } else {
  9573. if (v_low_g_mode_u8 < C_BMI160_TWO_U8X) {
  9574. /*write Low-g interrupt mode*/
  9575. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  9576. p_bmi160->dev_addr,
  9577. BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE__REG,
  9578. &v_data_u8, C_BMI160_ONE_U8X);
  9579. if (com_rslt == SUCCESS) {
  9580. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  9581. BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE,
  9582. v_low_g_mode_u8);
  9583. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  9584. p_bmi160->dev_addr,
  9585. BMI160_USER_INTR_LOWHIGH_2_INTR_LOW_G_MODE__REG,
  9586. &v_data_u8, C_BMI160_ONE_U8X);
  9587. }
  9588. } else {
  9589. com_rslt = E_BMI160_OUT_OF_RANGE;
  9590. }
  9591. }
  9592. return com_rslt;
  9593. }
  9594. /*!
  9595. * @brief This API reads High-g interrupt hysteresis
  9596. * from the register 0x5C bit 6 and 7
  9597. *
  9598. * @param v_high_g_hyst_u8 : The value of high hysteresis
  9599. *
  9600. * @note High_g hysteresis changes according to accel g range
  9601. * accel g range can be set by the function ""
  9602. * accel_range | high_g hysteresis
  9603. * ----------------|---------------------
  9604. * 2g | high_hy*125 mg
  9605. * 4g | high_hy*250 mg
  9606. * 8g | high_hy*500 mg
  9607. * 16g | high_hy*1000 mg
  9608. *
  9609. * @return results of bus communication function
  9610. * @retval 0 -> Success
  9611. * @retval -1 -> Error
  9612. *
  9613. *
  9614. */
  9615. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_high_g_hyst(
  9616. u8 *v_high_g_hyst_u8)
  9617. {
  9618. /* variable used for return the status of communication result*/
  9619. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9620. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  9621. /* check the p_bmi160 structure as NULL*/
  9622. if (p_bmi160 == BMI160_NULL) {
  9623. return E_BMI160_NULL_PTR;
  9624. } else {
  9625. /* read high_g hysteresis*/
  9626. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  9627. (p_bmi160->dev_addr,
  9628. BMI160_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST__REG,
  9629. &v_data_u8, C_BMI160_ONE_U8X);
  9630. *v_high_g_hyst_u8 = BMI160_GET_BITSLICE(v_data_u8,
  9631. BMI160_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST);
  9632. }
  9633. return com_rslt;
  9634. }
  9635. /*!
  9636. * @brief This API write High-g interrupt hysteresis
  9637. * from the register 0x5C bit 6 and 7
  9638. *
  9639. * @param v_high_g_hyst_u8 : The value of high hysteresis
  9640. *
  9641. * @note High_g hysteresis changes according to accel g range
  9642. * accel g range can be set by the function ""
  9643. * accel_range | high_g hysteresis
  9644. * ----------------|---------------------
  9645. * 2g | high_hy*125 mg
  9646. * 4g | high_hy*250 mg
  9647. * 8g | high_hy*500 mg
  9648. * 16g | high_hy*1000 mg
  9649. *
  9650. * @return results of bus communication function
  9651. * @retval 0 -> Success
  9652. * @retval -1 -> Error
  9653. *
  9654. *
  9655. */
  9656. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_high_g_hyst(
  9657. u8 v_high_g_hyst_u8)
  9658. {
  9659. /* variable used for return the status of communication result*/
  9660. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9661. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  9662. /* check the p_bmi160 structure as NULL*/
  9663. if (p_bmi160 == BMI160_NULL) {
  9664. return E_BMI160_NULL_PTR;
  9665. } else {
  9666. /* write high_g hysteresis*/
  9667. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  9668. p_bmi160->dev_addr,
  9669. BMI160_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST__REG,
  9670. &v_data_u8, C_BMI160_ONE_U8X);
  9671. if (com_rslt == SUCCESS) {
  9672. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  9673. BMI160_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST,
  9674. v_high_g_hyst_u8);
  9675. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  9676. p_bmi160->dev_addr,
  9677. BMI160_USER_INTR_LOWHIGH_2_INTR_HIGH_G_HYST__REG,
  9678. &v_data_u8, C_BMI160_ONE_U8X);
  9679. }
  9680. }
  9681. return com_rslt;
  9682. }
  9683. /*!
  9684. * @brief This API is used to read Delay
  9685. * time definition for the high-g interrupt from the register
  9686. * 0x5D bit 0 to 7
  9687. *
  9688. *
  9689. *
  9690. * @param v_high_g_durn_u8 : The value of high duration
  9691. *
  9692. * @note High_g interrupt delay triggered according to
  9693. * v_high_g_durn_u8 * 2.5ms in a range from 2.5ms to 640ms
  9694. *
  9695. * @return results of bus communication function
  9696. * @retval 0 -> Success
  9697. * @retval -1 -> Error
  9698. *
  9699. *
  9700. */
  9701. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_high_g_durn(
  9702. u8 *v_high_g_durn_u8)
  9703. {
  9704. /* variable used for return the status of communication result*/
  9705. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9706. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  9707. /* check the p_bmi160 structure as NULL*/
  9708. if (p_bmi160 == BMI160_NULL) {
  9709. return E_BMI160_NULL_PTR;
  9710. } else {
  9711. /* read high_g duration*/
  9712. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  9713. p_bmi160->dev_addr,
  9714. BMI160_USER_INTR_LOWHIGH_3_INTR_HIGH_G_DURN__REG,
  9715. &v_data_u8, C_BMI160_ONE_U8X);
  9716. *v_high_g_durn_u8 =
  9717. BMI160_GET_BITSLICE(v_data_u8,
  9718. BMI160_USER_INTR_LOWHIGH_3_INTR_HIGH_G_DURN);
  9719. }
  9720. return com_rslt;
  9721. }
  9722. /*!
  9723. * @brief This API is used to write Delay
  9724. * time definition for the high-g interrupt from the register
  9725. * 0x5D bit 0 to 7
  9726. *
  9727. *
  9728. *
  9729. * @param v_high_g_durn_u8 : The value of high duration
  9730. *
  9731. * @note High_g interrupt delay triggered according to
  9732. * v_high_g_durn_u8 * 2.5ms in a range from 2.5ms to 640ms
  9733. *
  9734. * @return results of bus communication function
  9735. * @retval 0 -> Success
  9736. * @retval -1 -> Error
  9737. *
  9738. *
  9739. */
  9740. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_high_g_durn(
  9741. u8 v_high_g_durn_u8)
  9742. {
  9743. /* variable used for return the status of communication result*/
  9744. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9745. /* check the p_bmi160 structure as NULL*/
  9746. if (p_bmi160 == BMI160_NULL) {
  9747. return E_BMI160_NULL_PTR;
  9748. } else {
  9749. /* write high_g duration*/
  9750. com_rslt = p_bmi160->BMI160_BUS_WRITE_FUNC
  9751. (p_bmi160->dev_addr,
  9752. BMI160_USER_INTR_LOWHIGH_3_INTR_HIGH_G_DURN__REG,
  9753. &v_high_g_durn_u8, C_BMI160_ONE_U8X);
  9754. }
  9755. return com_rslt;
  9756. }
  9757. /*!
  9758. * @brief This API is used to read Threshold
  9759. * definition for the high-g interrupt from the register 0x5E 0 to 7
  9760. *
  9761. *
  9762. *
  9763. *
  9764. * @param v_high_g_thres_u8 : Pointer holding the value of Threshold
  9765. * @note High_g threshold changes according to accel g range
  9766. * accel g range can be set by the function ""
  9767. * accel_range | high_g threshold
  9768. * ----------------|---------------------
  9769. * 2g | v_high_g_thres_u8*7.81 mg
  9770. * 4g | v_high_g_thres_u8*15.63 mg
  9771. * 8g | v_high_g_thres_u8*31.25 mg
  9772. * 16g | v_high_g_thres_u8*62.5 mg
  9773. * @note when v_high_g_thres_u8 = 0
  9774. * accel_range | high_g threshold
  9775. * ----------------|---------------------
  9776. * 2g | 3.91 mg
  9777. * 4g | 7.81 mg
  9778. * 8g | 15.63 mg
  9779. * 16g | 31.25 mg
  9780. *
  9781. *
  9782. * @return results of bus communication function
  9783. * @retval 0 -> Success
  9784. * @retval -1 -> Error
  9785. *
  9786. *
  9787. */
  9788. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_high_g_thres(
  9789. u8 *v_high_g_thres_u8)
  9790. {
  9791. /* variable used for return the status of communication result*/
  9792. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9793. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  9794. /* check the p_bmi160 structure as NULL*/
  9795. if (p_bmi160 == BMI160_NULL) {
  9796. return E_BMI160_NULL_PTR;
  9797. } else {
  9798. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  9799. p_bmi160->dev_addr,
  9800. BMI160_USER_INTR_LOWHIGH_4_INTR_HIGH_THRES__REG,
  9801. &v_data_u8, C_BMI160_ONE_U8X);
  9802. *v_high_g_thres_u8 =
  9803. BMI160_GET_BITSLICE(v_data_u8,
  9804. BMI160_USER_INTR_LOWHIGH_4_INTR_HIGH_THRES);
  9805. }
  9806. return com_rslt;
  9807. }
  9808. /*!
  9809. * @brief This API is used to write Threshold
  9810. * definition for the high-g interrupt from the register 0x5E 0 to 7
  9811. *
  9812. *
  9813. *
  9814. *
  9815. * @param v_high_g_thres_u8 : Pointer holding the value of Threshold
  9816. * @note High_g threshold changes according to accel g range
  9817. * accel g range can be set by the function ""
  9818. * accel_range | high_g threshold
  9819. * ----------------|---------------------
  9820. * 2g | v_high_g_thres_u8*7.81 mg
  9821. * 4g | v_high_g_thres_u8*15.63 mg
  9822. * 8g | v_high_g_thres_u8*31.25 mg
  9823. * 16g | v_high_g_thres_u8*62.5 mg
  9824. * @note when v_high_g_thres_u8 = 0
  9825. * accel_range | high_g threshold
  9826. * ----------------|---------------------
  9827. * 2g | 3.91 mg
  9828. * 4g | 7.81 mg
  9829. * 8g | 15.63 mg
  9830. * 16g | 31.25 mg
  9831. *
  9832. *
  9833. * @return results of bus communication function
  9834. * @retval 0 -> Success
  9835. * @retval -1 -> Error
  9836. *
  9837. *
  9838. */
  9839. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_high_g_thres(
  9840. u8 v_high_g_thres_u8)
  9841. {
  9842. /* variable used for return the status of communication result*/
  9843. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9844. /* check the p_bmi160 structure as NULL*/
  9845. if (p_bmi160 == BMI160_NULL) {
  9846. return E_BMI160_NULL_PTR;
  9847. } else {
  9848. com_rslt = p_bmi160->BMI160_BUS_WRITE_FUNC(
  9849. p_bmi160->dev_addr,
  9850. BMI160_USER_INTR_LOWHIGH_4_INTR_HIGH_THRES__REG,
  9851. &v_high_g_thres_u8, C_BMI160_ONE_U8X);
  9852. }
  9853. return com_rslt;
  9854. }
  9855. /*!
  9856. * @brief This API reads any motion duration
  9857. * from the register 0x5F bit 0 and 1
  9858. *
  9859. * @param v_any_motion_durn_u8 : The value of any motion duration
  9860. *
  9861. * @note Any motion duration can be calculated by "v_any_motion_durn_u8 + 1"
  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_get_intr_any_motion_durn(
  9870. u8 *v_any_motion_durn_u8)
  9871. {
  9872. /* variable used for return the status of communication result*/
  9873. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9874. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  9875. /* check the p_bmi160 structure as NULL*/
  9876. if (p_bmi160 == BMI160_NULL) {
  9877. return E_BMI160_NULL_PTR;
  9878. } else {
  9879. /* read any motion duration*/
  9880. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  9881. (p_bmi160->dev_addr,
  9882. BMI160_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN__REG,
  9883. &v_data_u8, C_BMI160_ONE_U8X);
  9884. *v_any_motion_durn_u8 = BMI160_GET_BITSLICE
  9885. (v_data_u8,
  9886. BMI160_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN);
  9887. }
  9888. return com_rslt;
  9889. }
  9890. /*!
  9891. * @brief This API write any motion duration
  9892. * from the register 0x5F bit 0 and 1
  9893. *
  9894. * @param v_any_motion_durn_u8 : The value of any motion duration
  9895. *
  9896. * @note Any motion duration can be calculated by "v_any_motion_durn_u8 + 1"
  9897. *
  9898. * @return results of bus communication function
  9899. * @retval 0 -> Success
  9900. * @retval -1 -> Error
  9901. *
  9902. *
  9903. */
  9904. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_any_motion_durn(
  9905. u8 v_any_motion_durn_u8)
  9906. {
  9907. /* variable used for return the status of communication result*/
  9908. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9909. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  9910. /* check the p_bmi160 structure as NULL*/
  9911. if (p_bmi160 == BMI160_NULL) {
  9912. return E_BMI160_NULL_PTR;
  9913. } else {
  9914. /* write any motion duration*/
  9915. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  9916. (p_bmi160->dev_addr,
  9917. BMI160_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN__REG,
  9918. &v_data_u8, C_BMI160_ONE_U8X);
  9919. if (com_rslt == SUCCESS) {
  9920. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  9921. BMI160_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN,
  9922. v_any_motion_durn_u8);
  9923. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  9924. (p_bmi160->dev_addr,
  9925. BMI160_USER_INTR_MOTION_0_INTR_ANY_MOTION_DURN__REG,
  9926. &v_data_u8, C_BMI160_ONE_U8X);
  9927. }
  9928. }
  9929. return com_rslt;
  9930. }
  9931. /*!
  9932. * @brief This API read Slow/no-motion
  9933. * interrupt trigger delay duration from the register 0x5F bit 2 to 7
  9934. *
  9935. * @param v_slow_no_motion_u8 :The value of slow no motion duration
  9936. *
  9937. *
  9938. *
  9939. * @return results of bus communication function
  9940. * @retval 0 -> Success
  9941. * @retval -1 -> Error
  9942. *
  9943. * @note
  9944. * @note v_slow_no_motion_u8(5:4)=0b00 ->
  9945. * [v_slow_no_motion_u8(3:0) + 1] * 1.28s (1.28s-20.48s)
  9946. * @note v_slow_no_motion_u8(5:4)=1 ->
  9947. * [v_slow_no_motion_u8(3:0)+5] * 5.12s (25.6s-102.4s)
  9948. * @note v_slow_no_motion_u8(5)='1' ->
  9949. * [(v_slow_no_motion_u8:0)+11] * 10.24s (112.64s-430.08s);
  9950. *
  9951. */
  9952. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_slow_no_motion_durn(
  9953. u8 *v_slow_no_motion_u8)
  9954. {
  9955. /* variable used for return the status of communication result*/
  9956. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9957. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  9958. /* check the p_bmi160 structure as NULL*/
  9959. if (p_bmi160 == BMI160_NULL) {
  9960. return E_BMI160_NULL_PTR;
  9961. } else {
  9962. /* read slow no motion duration*/
  9963. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  9964. (p_bmi160->dev_addr,
  9965. BMI160_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN__REG,
  9966. &v_data_u8, C_BMI160_ONE_U8X);
  9967. *v_slow_no_motion_u8 = BMI160_GET_BITSLICE
  9968. (v_data_u8,
  9969. BMI160_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN);
  9970. }
  9971. return com_rslt;
  9972. }
  9973. /*!
  9974. * @brief This API write Slow/no-motion
  9975. * interrupt trigger delay duration from the register 0x5F bit 2 to 7
  9976. *
  9977. * @param v_slow_no_motion_u8 :The value of slow no motion duration
  9978. *
  9979. *
  9980. *
  9981. * @return results of bus communication function
  9982. * @retval 0 -> Success
  9983. * @retval -1 -> Error
  9984. *
  9985. * @note
  9986. * @note v_slow_no_motion_u8(5:4)=0b00 ->
  9987. * [v_slow_no_motion_u8(3:0) + 1] * 1.28s (1.28s-20.48s)
  9988. * @note v_slow_no_motion_u8(5:4)=1 ->
  9989. * [v_slow_no_motion_u8(3:0)+5] * 5.12s (25.6s-102.4s)
  9990. * @note v_slow_no_motion_u8(5)='1' ->
  9991. * [(v_slow_no_motion_u8:0)+11] * 10.24s (112.64s-430.08s);
  9992. *
  9993. */
  9994. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_slow_no_motion_durn(
  9995. u8 v_slow_no_motion_u8)
  9996. {
  9997. /* variable used for return the status of communication result*/
  9998. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  9999. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  10000. /* check the p_bmi160 structure as NULL*/
  10001. if (p_bmi160 == BMI160_NULL) {
  10002. return E_BMI160_NULL_PTR;
  10003. } else {
  10004. /* write slow no motion duration*/
  10005. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  10006. (p_bmi160->dev_addr,
  10007. BMI160_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN__REG,
  10008. &v_data_u8, C_BMI160_ONE_U8X);
  10009. if (com_rslt == SUCCESS) {
  10010. v_data_u8 = BMI160_SET_BITSLICE
  10011. (v_data_u8,
  10012. BMI160_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN,
  10013. v_slow_no_motion_u8);
  10014. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  10015. (p_bmi160->dev_addr,
  10016. BMI160_USER_INTR_MOTION_0_INTR_SLOW_NO_MOTION_DURN__REG,
  10017. &v_data_u8, C_BMI160_ONE_U8X);
  10018. }
  10019. }
  10020. return com_rslt;
  10021. }
  10022. /*!
  10023. * @brief This API is used to read threshold
  10024. * definition for the any-motion interrupt
  10025. * from the register 0x60 bit 0 to 7
  10026. *
  10027. *
  10028. * @param v_any_motion_thres_u8 : The value of any motion threshold
  10029. *
  10030. * @note any motion threshold changes according to accel g range
  10031. * accel g range can be set by the function ""
  10032. * accel_range | any motion threshold
  10033. * ----------------|---------------------
  10034. * 2g | v_any_motion_thres_u8*3.91 mg
  10035. * 4g | v_any_motion_thres_u8*7.81 mg
  10036. * 8g | v_any_motion_thres_u8*15.63 mg
  10037. * 16g | v_any_motion_thres_u8*31.25 mg
  10038. * @note when v_any_motion_thres_u8 = 0
  10039. * accel_range | any motion threshold
  10040. * ----------------|---------------------
  10041. * 2g | 1.95 mg
  10042. * 4g | 3.91 mg
  10043. * 8g | 7.81 mg
  10044. * 16g | 15.63 mg
  10045. *
  10046. *
  10047. * @return results of bus communication function
  10048. * @retval 0 -> Success
  10049. * @retval -1 -> Error
  10050. *
  10051. *
  10052. */
  10053. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_any_motion_thres(
  10054. u8 *v_any_motion_thres_u8)
  10055. {
  10056. /* variable used for return the status of communication result*/
  10057. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10058. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  10059. /* check the p_bmi160 structure as NULL*/
  10060. if (p_bmi160 == BMI160_NULL) {
  10061. return E_BMI160_NULL_PTR;
  10062. } else {
  10063. /* read any motion threshold*/
  10064. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  10065. (p_bmi160->dev_addr,
  10066. BMI160_USER_INTR_MOTION_1_INTR_ANY_MOTION_THRES__REG,
  10067. &v_data_u8, C_BMI160_ONE_U8X);
  10068. *v_any_motion_thres_u8 =
  10069. BMI160_GET_BITSLICE(v_data_u8,
  10070. BMI160_USER_INTR_MOTION_1_INTR_ANY_MOTION_THRES);
  10071. }
  10072. return com_rslt;
  10073. }
  10074. /*!
  10075. * @brief This API is used to write threshold
  10076. * definition for the any-motion interrupt
  10077. * from the register 0x60 bit 0 to 7
  10078. *
  10079. *
  10080. * @param v_any_motion_thres_u8 : The value of any motion threshold
  10081. *
  10082. * @note any motion threshold changes according to accel g range
  10083. * accel g range can be set by the function ""
  10084. * accel_range | any motion threshold
  10085. * ----------------|---------------------
  10086. * 2g | v_any_motion_thres_u8*3.91 mg
  10087. * 4g | v_any_motion_thres_u8*7.81 mg
  10088. * 8g | v_any_motion_thres_u8*15.63 mg
  10089. * 16g | v_any_motion_thres_u8*31.25 mg
  10090. * @note when v_any_motion_thres_u8 = 0
  10091. * accel_range | any motion threshold
  10092. * ----------------|---------------------
  10093. * 2g | 1.95 mg
  10094. * 4g | 3.91 mg
  10095. * 8g | 7.81 mg
  10096. * 16g | 15.63 mg
  10097. *
  10098. *
  10099. * @return results of bus communication function
  10100. * @retval 0 -> Success
  10101. * @retval -1 -> Error
  10102. *
  10103. *
  10104. */
  10105. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_any_motion_thres(
  10106. u8 v_any_motion_thres_u8)
  10107. {
  10108. /* variable used for return the status of communication result*/
  10109. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10110. /* check the p_bmi160 structure as NULL*/
  10111. if (p_bmi160 == BMI160_NULL) {
  10112. return E_BMI160_NULL_PTR;
  10113. } else {
  10114. /* write any motion threshold*/
  10115. com_rslt = p_bmi160->BMI160_BUS_WRITE_FUNC
  10116. (p_bmi160->dev_addr,
  10117. BMI160_USER_INTR_MOTION_1_INTR_ANY_MOTION_THRES__REG,
  10118. &v_any_motion_thres_u8, C_BMI160_ONE_U8X);
  10119. }
  10120. return com_rslt;
  10121. }
  10122. /*!
  10123. * @brief This API is used to read threshold
  10124. * for the slow/no-motion interrupt
  10125. * from the register 0x61 bit 0 to 7
  10126. *
  10127. *
  10128. *
  10129. *
  10130. * @param v_slow_no_motion_thres_u8 : The value of slow no motion threshold
  10131. * @note slow no motion threshold changes according to accel g range
  10132. * accel g range can be set by the function ""
  10133. * accel_range | slow no motion threshold
  10134. * ----------------|---------------------
  10135. * 2g | v_slow_no_motion_thres_u8*3.91 mg
  10136. * 4g | v_slow_no_motion_thres_u8*7.81 mg
  10137. * 8g | v_slow_no_motion_thres_u8*15.63 mg
  10138. * 16g | v_slow_no_motion_thres_u8*31.25 mg
  10139. * @note when v_slow_no_motion_thres_u8 = 0
  10140. * accel_range | slow no motion threshold
  10141. * ----------------|---------------------
  10142. * 2g | 1.95 mg
  10143. * 4g | 3.91 mg
  10144. * 8g | 7.81 mg
  10145. * 16g | 15.63 mg
  10146. *
  10147. *
  10148. * @return results of bus communication function
  10149. * @retval 0 -> Success
  10150. * @retval -1 -> Error
  10151. *
  10152. *
  10153. */
  10154. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_slow_no_motion_thres(
  10155. u8 *v_slow_no_motion_thres_u8)
  10156. {
  10157. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10158. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  10159. /* check the p_bmi160 structure as NULL*/
  10160. if (p_bmi160 == BMI160_NULL) {
  10161. return E_BMI160_NULL_PTR;
  10162. } else {
  10163. /* read slow no motion threshold*/
  10164. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  10165. (p_bmi160->dev_addr,
  10166. BMI160_USER_INTR_MOTION_2_INTR_SLOW_NO_MOTION_THRES__REG,
  10167. &v_data_u8, C_BMI160_ONE_U8X);
  10168. *v_slow_no_motion_thres_u8 =
  10169. BMI160_GET_BITSLICE(v_data_u8,
  10170. BMI160_USER_INTR_MOTION_2_INTR_SLOW_NO_MOTION_THRES);
  10171. }
  10172. return com_rslt;
  10173. }
  10174. /*!
  10175. * @brief This API is used to write threshold
  10176. * for the slow/no-motion interrupt
  10177. * from the register 0x61 bit 0 to 7
  10178. *
  10179. *
  10180. *
  10181. *
  10182. * @param v_slow_no_motion_thres_u8 : The value of slow no motion threshold
  10183. * @note slow no motion threshold changes according to accel g range
  10184. * accel g range can be set by the function ""
  10185. * accel_range | slow no motion threshold
  10186. * ----------------|---------------------
  10187. * 2g | v_slow_no_motion_thres_u8*3.91 mg
  10188. * 4g | v_slow_no_motion_thres_u8*7.81 mg
  10189. * 8g | v_slow_no_motion_thres_u8*15.63 mg
  10190. * 16g | v_slow_no_motion_thres_u8*31.25 mg
  10191. * @note when v_slow_no_motion_thres_u8 = 0
  10192. * accel_range | slow no motion threshold
  10193. * ----------------|---------------------
  10194. * 2g | 1.95 mg
  10195. * 4g | 3.91 mg
  10196. * 8g | 7.81 mg
  10197. * 16g | 15.63 mg
  10198. *
  10199. *
  10200. * @return results of bus communication function
  10201. * @retval 0 -> Success
  10202. * @retval -1 -> Error
  10203. *
  10204. *
  10205. */
  10206. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_slow_no_motion_thres(
  10207. u8 v_slow_no_motion_thres_u8)
  10208. {
  10209. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10210. /* check the p_bmi160 structure as NULL*/
  10211. if (p_bmi160 == BMI160_NULL) {
  10212. return E_BMI160_NULL_PTR;
  10213. } else {
  10214. /* write slow no motion threshold*/
  10215. com_rslt = p_bmi160->BMI160_BUS_WRITE_FUNC(
  10216. p_bmi160->dev_addr,
  10217. BMI160_USER_INTR_MOTION_2_INTR_SLOW_NO_MOTION_THRES__REG,
  10218. &v_slow_no_motion_thres_u8, C_BMI160_ONE_U8X);
  10219. }
  10220. return com_rslt;
  10221. }
  10222. /*!
  10223. * @brief This API is used to read
  10224. * the slow/no-motion selection from the register 0x62 bit 0
  10225. *
  10226. *
  10227. *
  10228. *
  10229. * @param v_intr_slow_no_motion_select_u8 :
  10230. * The value of slow/no-motion select
  10231. * value | Behaviour
  10232. * ----------|-------------------
  10233. * 0x00 | SLOW_MOTION
  10234. * 0x01 | NO_MOTION
  10235. *
  10236. *
  10237. * @return results of bus communication function
  10238. * @retval 0 -> Success
  10239. * @retval -1 -> Error
  10240. *
  10241. *
  10242. */
  10243. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_slow_no_motion_select(
  10244. u8 *v_intr_slow_no_motion_select_u8)
  10245. {
  10246. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10247. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  10248. /* check the p_bmi160 structure as NULL*/
  10249. if (p_bmi160 == BMI160_NULL) {
  10250. return E_BMI160_NULL_PTR;
  10251. } else {
  10252. /* read slow no motion select*/
  10253. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  10254. p_bmi160->dev_addr,
  10255. BMI160_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT__REG,
  10256. &v_data_u8, C_BMI160_ONE_U8X);
  10257. *v_intr_slow_no_motion_select_u8 =
  10258. BMI160_GET_BITSLICE(v_data_u8,
  10259. BMI160_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT);
  10260. }
  10261. return com_rslt;
  10262. }
  10263. /*!
  10264. * @brief This API is used to write
  10265. * the slow/no-motion selection from the register 0x62 bit 0
  10266. *
  10267. *
  10268. *
  10269. *
  10270. * @param v_intr_slow_no_motion_select_u8 :
  10271. * The value of slow/no-motion select
  10272. * value | Behaviour
  10273. * ----------|-------------------
  10274. * 0x00 | SLOW_MOTION
  10275. * 0x01 | NO_MOTION
  10276. *
  10277. *
  10278. * @return results of bus communication function
  10279. * @retval 0 -> Success
  10280. * @retval -1 -> Error
  10281. *
  10282. *
  10283. */
  10284. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_slow_no_motion_select(
  10285. u8 v_intr_slow_no_motion_select_u8)
  10286. {
  10287. /* variable used for return the status of communication result*/
  10288. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10289. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  10290. /* check the p_bmi160 structure as NULL*/
  10291. if (p_bmi160 == BMI160_NULL) {
  10292. return E_BMI160_NULL_PTR;
  10293. } else {
  10294. if (v_intr_slow_no_motion_select_u8 < C_BMI160_TWO_U8X) {
  10295. /* write slow no motion select*/
  10296. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  10297. (p_bmi160->dev_addr,
  10298. BMI160_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT__REG,
  10299. &v_data_u8, C_BMI160_ONE_U8X);
  10300. if (com_rslt == SUCCESS) {
  10301. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  10302. BMI160_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT,
  10303. v_intr_slow_no_motion_select_u8);
  10304. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  10305. (p_bmi160->dev_addr,
  10306. BMI160_USER_INTR_MOTION_3_INTR_SLOW_NO_MOTION_SELECT__REG,
  10307. &v_data_u8, C_BMI160_ONE_U8X);
  10308. }
  10309. } else {
  10310. com_rslt = E_BMI160_OUT_OF_RANGE;
  10311. }
  10312. }
  10313. return com_rslt;
  10314. }
  10315. /*!
  10316. * @brief This API is used to select
  10317. * the significant or any motion interrupt from the register 0x62 bit 1
  10318. *
  10319. *
  10320. *
  10321. *
  10322. * @param v_intr_significant_motion_select_u8 :
  10323. * the value of significant or any motion interrupt selection
  10324. * value | Behaviour
  10325. * ----------|-------------------
  10326. * 0x00 | ANY_MOTION
  10327. * 0x01 | SIGNIFICANT_MOTION
  10328. *
  10329. *
  10330. * @return results of bus communication function
  10331. * @retval 0 -> Success
  10332. * @retval -1 -> Error
  10333. *
  10334. *
  10335. */
  10336. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_significant_motion_select(
  10337. u8 *v_intr_significant_motion_select_u8)
  10338. {
  10339. /* variable used for return the status of communication result*/
  10340. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10341. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  10342. /* check the p_bmi160 structure as NULL*/
  10343. if (p_bmi160 == BMI160_NULL) {
  10344. return E_BMI160_NULL_PTR;
  10345. } else {
  10346. /* read the significant or any motion interrupt*/
  10347. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  10348. p_bmi160->dev_addr,
  10349. BMI160_USER_INTR_SIGNIFICATION_MOTION_SELECT__REG,
  10350. &v_data_u8, C_BMI160_ONE_U8X);
  10351. *v_intr_significant_motion_select_u8 =
  10352. BMI160_GET_BITSLICE(v_data_u8,
  10353. BMI160_USER_INTR_SIGNIFICATION_MOTION_SELECT);
  10354. }
  10355. return com_rslt;
  10356. }
  10357. /*!
  10358. * @brief This API is used to write, select
  10359. * the significant or any motion interrupt from the register 0x62 bit 1
  10360. *
  10361. *
  10362. *
  10363. *
  10364. * @param v_intr_significant_motion_select_u8 :
  10365. * the value of significant or any motion interrupt selection
  10366. * value | Behaviour
  10367. * ----------|-------------------
  10368. * 0x00 | ANY_MOTION
  10369. * 0x01 | SIGNIFICANT_MOTION
  10370. *
  10371. *
  10372. * @return results of bus communication function
  10373. * @retval 0 -> Success
  10374. * @retval -1 -> Error
  10375. *
  10376. *
  10377. */
  10378. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_significant_motion_select(
  10379. u8 v_intr_significant_motion_select_u8)
  10380. {
  10381. /* variable used for return the status of communication result*/
  10382. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10383. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  10384. /* check the p_bmi160 structure as NULL*/
  10385. if (p_bmi160 == BMI160_NULL) {
  10386. return E_BMI160_NULL_PTR;
  10387. } else {
  10388. if (v_intr_significant_motion_select_u8 < C_BMI160_TWO_U8X) {
  10389. /* write the significant or any motion interrupt*/
  10390. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  10391. (p_bmi160->dev_addr,
  10392. BMI160_USER_INTR_SIGNIFICATION_MOTION_SELECT__REG,
  10393. &v_data_u8, C_BMI160_ONE_U8X);
  10394. if (com_rslt == SUCCESS) {
  10395. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  10396. BMI160_USER_INTR_SIGNIFICATION_MOTION_SELECT,
  10397. v_intr_significant_motion_select_u8);
  10398. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  10399. (p_bmi160->dev_addr,
  10400. BMI160_USER_INTR_SIGNIFICATION_MOTION_SELECT__REG,
  10401. &v_data_u8, C_BMI160_ONE_U8X);
  10402. }
  10403. } else {
  10404. com_rslt = E_BMI160_OUT_OF_RANGE;
  10405. }
  10406. }
  10407. return com_rslt;
  10408. }
  10409. /*!
  10410. * @brief This API is used to read
  10411. * the significant skip time from the register 0x62 bit 2 and 3
  10412. *
  10413. *
  10414. *
  10415. *
  10416. * @param v_int_sig_mot_skip_u8 : the value of significant skip time
  10417. * value | Behaviour
  10418. * ----------|-------------------
  10419. * 0x00 | skip time 1.5 seconds
  10420. * 0x01 | skip time 3 seconds
  10421. * 0x02 | skip time 6 seconds
  10422. * 0x03 | skip time 12 seconds
  10423. *
  10424. *
  10425. * @return results of bus communication function
  10426. * @retval 0 -> Success
  10427. * @retval -1 -> Error
  10428. *
  10429. *
  10430. */
  10431. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_significant_motion_skip(
  10432. u8 *v_int_sig_mot_skip_u8)
  10433. {
  10434. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10435. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  10436. /* check the p_bmi160 structure as NULL*/
  10437. if (p_bmi160 == BMI160_NULL) {
  10438. return E_BMI160_NULL_PTR;
  10439. } else {
  10440. /* read significant skip time*/
  10441. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  10442. p_bmi160->dev_addr,
  10443. BMI160_USER_INTR_SIGNIFICANT_MOTION_SKIP__REG,
  10444. &v_data_u8, C_BMI160_ONE_U8X);
  10445. *v_int_sig_mot_skip_u8 =
  10446. BMI160_GET_BITSLICE(v_data_u8,
  10447. BMI160_USER_INTR_SIGNIFICANT_MOTION_SKIP);
  10448. }
  10449. return com_rslt;
  10450. }
  10451. /*!
  10452. * @brief This API is used to write
  10453. * the significant skip time from the register 0x62 bit 2 and 3
  10454. *
  10455. *
  10456. *
  10457. *
  10458. * @param v_int_sig_mot_skip_u8 : the value of significant skip time
  10459. * value | Behaviour
  10460. * ----------|-------------------
  10461. * 0x00 | skip time 1.5 seconds
  10462. * 0x01 | skip time 3 seconds
  10463. * 0x02 | skip time 6 seconds
  10464. * 0x03 | skip time 12 seconds
  10465. *
  10466. *
  10467. * @return results of bus communication function
  10468. * @retval 0 -> Success
  10469. * @retval -1 -> Error
  10470. *
  10471. *
  10472. */
  10473. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_significant_motion_skip(
  10474. u8 v_int_sig_mot_skip_u8)
  10475. {
  10476. /* variable used for return the status of communication result*/
  10477. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10478. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  10479. /* check the p_bmi160 structure as NULL*/
  10480. if (p_bmi160 == BMI160_NULL) {
  10481. return E_BMI160_NULL_PTR;
  10482. } else {
  10483. if (v_int_sig_mot_skip_u8 < C_BMI160_EIGHT_U8X) {
  10484. /* write significant skip time*/
  10485. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  10486. (p_bmi160->dev_addr,
  10487. BMI160_USER_INTR_SIGNIFICANT_MOTION_SKIP__REG,
  10488. &v_data_u8, C_BMI160_ONE_U8X);
  10489. if (com_rslt == SUCCESS) {
  10490. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  10491. BMI160_USER_INTR_SIGNIFICANT_MOTION_SKIP,
  10492. v_int_sig_mot_skip_u8);
  10493. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  10494. (p_bmi160->dev_addr,
  10495. BMI160_USER_INTR_SIGNIFICANT_MOTION_SKIP__REG,
  10496. &v_data_u8, C_BMI160_ONE_U8X);
  10497. }
  10498. } else {
  10499. com_rslt = E_BMI160_OUT_OF_RANGE;
  10500. }
  10501. }
  10502. return com_rslt;
  10503. }
  10504. /*!
  10505. * @brief This API is used to read
  10506. * the significant proof time from the register 0x62 bit 4 and 5
  10507. *
  10508. *
  10509. *
  10510. *
  10511. * @param v_significant_motion_proof_u8 :
  10512. * the value of significant proof time
  10513. * value | Behaviour
  10514. * ----------|-------------------
  10515. * 0x00 | proof time 0.25 seconds
  10516. * 0x01 | proof time 0.5 seconds
  10517. * 0x02 | proof time 1 seconds
  10518. * 0x03 | proof time 2 seconds
  10519. *
  10520. *
  10521. * @return results of bus communication function
  10522. * @retval 0 -> Success
  10523. * @retval -1 -> Error
  10524. *
  10525. *
  10526. */
  10527. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_significant_motion_proof(
  10528. u8 *v_significant_motion_proof_u8)
  10529. {
  10530. /* variable used for return the status of communication result*/
  10531. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10532. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  10533. /* check the p_bmi160 structure as NULL*/
  10534. if (p_bmi160 == BMI160_NULL) {
  10535. return E_BMI160_NULL_PTR;
  10536. } else {
  10537. /* read significant proof time */
  10538. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  10539. p_bmi160->dev_addr,
  10540. BMI160_USER_INTR_SIGNIFICANT_MOTION_PROOF__REG,
  10541. &v_data_u8, C_BMI160_ONE_U8X);
  10542. *v_significant_motion_proof_u8 =
  10543. BMI160_GET_BITSLICE(v_data_u8,
  10544. BMI160_USER_INTR_SIGNIFICANT_MOTION_PROOF);
  10545. }
  10546. return com_rslt;
  10547. }
  10548. /*!
  10549. * @brief This API is used to write
  10550. * the significant proof time from the register 0x62 bit 4 and 5
  10551. *
  10552. *
  10553. *
  10554. *
  10555. * @param v_significant_motion_proof_u8 :
  10556. * the value of significant proof time
  10557. * value | Behaviour
  10558. * ----------|-------------------
  10559. * 0x00 | proof time 0.25 seconds
  10560. * 0x01 | proof time 0.5 seconds
  10561. * 0x02 | proof time 1 seconds
  10562. * 0x03 | proof time 2 seconds
  10563. *
  10564. *
  10565. * @return results of bus communication function
  10566. * @retval 0 -> Success
  10567. * @retval -1 -> Error
  10568. *
  10569. *
  10570. */
  10571. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_significant_motion_proof(
  10572. u8 v_significant_motion_proof_u8)
  10573. {
  10574. /* variable used for return the status of communication result*/
  10575. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10576. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  10577. /* check the p_bmi160 structure as NULL*/
  10578. if (p_bmi160 == BMI160_NULL) {
  10579. return E_BMI160_NULL_PTR;
  10580. } else {
  10581. if (v_significant_motion_proof_u8 < C_BMI160_EIGHT_U8X) {
  10582. /* write significant proof time */
  10583. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  10584. (p_bmi160->dev_addr,
  10585. BMI160_USER_INTR_SIGNIFICANT_MOTION_PROOF__REG,
  10586. &v_data_u8, C_BMI160_ONE_U8X);
  10587. if (com_rslt == SUCCESS) {
  10588. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  10589. BMI160_USER_INTR_SIGNIFICANT_MOTION_PROOF,
  10590. v_significant_motion_proof_u8);
  10591. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  10592. (p_bmi160->dev_addr,
  10593. BMI160_USER_INTR_SIGNIFICANT_MOTION_PROOF__REG,
  10594. &v_data_u8, C_BMI160_ONE_U8X);
  10595. }
  10596. } else {
  10597. com_rslt = E_BMI160_OUT_OF_RANGE;
  10598. }
  10599. }
  10600. return com_rslt;
  10601. }
  10602. /*!
  10603. * @brief This API is used to get the tap duration
  10604. * from the register 0x63 bit 0 to 2
  10605. *
  10606. *
  10607. *
  10608. * @param v_tap_durn_u8 : The value of tap duration
  10609. * value | Behaviour
  10610. * ----------|-------------------
  10611. * 0x00 | BMI160_TAP_DURN_50MS
  10612. * 0x01 | BMI160_TAP_DURN_100MS
  10613. * 0x03 | BMI160_TAP_DURN_150MS
  10614. * 0x04 | BMI160_TAP_DURN_200MS
  10615. * 0x05 | BMI160_TAP_DURN_250MS
  10616. * 0x06 | BMI160_TAP_DURN_375MS
  10617. * 0x07 | BMI160_TAP_DURN_700MS
  10618. *
  10619. *
  10620. *
  10621. * @return results of bus communication function
  10622. * @retval 0 -> Success
  10623. * @retval -1 -> Error
  10624. *
  10625. *
  10626. */
  10627. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_tap_durn(
  10628. u8 *v_tap_durn_u8)
  10629. {
  10630. /* variable used for return the status of communication result*/
  10631. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10632. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  10633. /* check the p_bmi160 structure as NULL*/
  10634. if (p_bmi160 == BMI160_NULL) {
  10635. return E_BMI160_NULL_PTR;
  10636. } else {
  10637. /* read tap duration*/
  10638. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  10639. (p_bmi160->dev_addr,
  10640. BMI160_USER_INTR_TAP_0_INTR_TAP_DURN__REG,
  10641. &v_data_u8, C_BMI160_ONE_U8X);
  10642. *v_tap_durn_u8 = BMI160_GET_BITSLICE(
  10643. v_data_u8,
  10644. BMI160_USER_INTR_TAP_0_INTR_TAP_DURN);
  10645. }
  10646. return com_rslt;
  10647. }
  10648. /*!
  10649. * @brief This API is used to write the tap duration
  10650. * from the register 0x63 bit 0 to 2
  10651. *
  10652. *
  10653. *
  10654. * @param v_tap_durn_u8 : The value of tap duration
  10655. * value | Behaviour
  10656. * ----------|-------------------
  10657. * 0x00 | BMI160_TAP_DURN_50MS
  10658. * 0x01 | BMI160_TAP_DURN_100MS
  10659. * 0x03 | BMI160_TAP_DURN_150MS
  10660. * 0x04 | BMI160_TAP_DURN_200MS
  10661. * 0x05 | BMI160_TAP_DURN_250MS
  10662. * 0x06 | BMI160_TAP_DURN_375MS
  10663. * 0x07 | BMI160_TAP_DURN_700MS
  10664. *
  10665. *
  10666. *
  10667. * @return results of bus communication function
  10668. * @retval 0 -> Success
  10669. * @retval -1 -> Error
  10670. *
  10671. *
  10672. */
  10673. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_tap_durn(
  10674. u8 v_tap_durn_u8)
  10675. {
  10676. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  10677. /* variable used for return the status of communication result*/
  10678. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10679. u8 v_data_tap_durn_u8 = C_BMI160_ZERO_U8X;
  10680. /* check the p_bmi160 structure as NULL*/
  10681. if (p_bmi160 == BMI160_NULL) {
  10682. return E_BMI160_NULL_PTR;
  10683. } else {
  10684. if (v_tap_durn_u8 < C_BMI160_EIGHT_U8X) {
  10685. switch (v_tap_durn_u8) {
  10686. case BMI160_TAP_DURN_50MS:
  10687. v_data_tap_durn_u8 = BMI160_TAP_DURN_50MS;
  10688. break;
  10689. case BMI160_TAP_DURN_100MS:
  10690. v_data_tap_durn_u8 = BMI160_TAP_DURN_100MS;
  10691. break;
  10692. case BMI160_TAP_DURN_150MS:
  10693. v_data_tap_durn_u8 = BMI160_TAP_DURN_150MS;
  10694. break;
  10695. case BMI160_TAP_DURN_200MS:
  10696. v_data_tap_durn_u8 = BMI160_TAP_DURN_200MS;
  10697. break;
  10698. case BMI160_TAP_DURN_250MS:
  10699. v_data_tap_durn_u8 = BMI160_TAP_DURN_250MS;
  10700. break;
  10701. case BMI160_TAP_DURN_375MS:
  10702. v_data_tap_durn_u8 = BMI160_TAP_DURN_375MS;
  10703. break;
  10704. case BMI160_TAP_DURN_500MS:
  10705. v_data_tap_durn_u8 = BMI160_TAP_DURN_500MS;
  10706. break;
  10707. case BMI160_TAP_DURN_700MS:
  10708. v_data_tap_durn_u8 = BMI160_TAP_DURN_700MS;
  10709. break;
  10710. default:
  10711. break;
  10712. }
  10713. /* write tap duration*/
  10714. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  10715. p_bmi160->dev_addr,
  10716. BMI160_USER_INTR_TAP_0_INTR_TAP_DURN__REG,
  10717. &v_data_u8, C_BMI160_ONE_U8X);
  10718. if (com_rslt == SUCCESS) {
  10719. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  10720. BMI160_USER_INTR_TAP_0_INTR_TAP_DURN,
  10721. v_data_tap_durn_u8);
  10722. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  10723. (p_bmi160->dev_addr,
  10724. BMI160_USER_INTR_TAP_0_INTR_TAP_DURN__REG,
  10725. &v_data_u8, C_BMI160_ONE_U8X);
  10726. }
  10727. } else {
  10728. com_rslt = E_BMI160_OUT_OF_RANGE;
  10729. }
  10730. }
  10731. return com_rslt;
  10732. }
  10733. /*!
  10734. * @brief This API read the
  10735. * tap shock duration from the register 0x63 bit 2
  10736. *
  10737. * @param v_tap_shock_u8 :The value of tap shock
  10738. * value | Behaviour
  10739. * ----------|-------------------
  10740. * 0x00 | BMI160_TAP_SHOCK_50MS
  10741. * 0x01 | BMI160_TAP_SHOCK_75MS
  10742. *
  10743. *
  10744. * @return results of bus communication function
  10745. * @retval 0 -> Success
  10746. * @retval -1 -> Error
  10747. *
  10748. *
  10749. */
  10750. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_tap_shock(
  10751. u8 *v_tap_shock_u8)
  10752. {
  10753. /* variable used for return the status of communication result*/
  10754. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10755. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  10756. /* check the p_bmi160 structure as NULL*/
  10757. if (p_bmi160 == BMI160_NULL) {
  10758. return E_BMI160_NULL_PTR;
  10759. } else {
  10760. /* read tap shock duration*/
  10761. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  10762. p_bmi160->dev_addr,
  10763. BMI160_USER_INTR_TAP_0_INTR_TAP_SHOCK__REG,
  10764. &v_data_u8, C_BMI160_ONE_U8X);
  10765. *v_tap_shock_u8 = BMI160_GET_BITSLICE(v_data_u8,
  10766. BMI160_USER_INTR_TAP_0_INTR_TAP_SHOCK);
  10767. }
  10768. return com_rslt;
  10769. }
  10770. /*!
  10771. * @brief This API write the
  10772. * tap shock duration from the register 0x63 bit 2
  10773. *
  10774. * @param v_tap_shock_u8 :The value of tap shock
  10775. * value | Behaviour
  10776. * ----------|-------------------
  10777. * 0x00 | BMI160_TAP_SHOCK_50MS
  10778. * 0x01 | BMI160_TAP_SHOCK_75MS
  10779. *
  10780. *
  10781. * @return results of bus communication function
  10782. * @retval 0 -> Success
  10783. * @retval -1 -> Error
  10784. *
  10785. *
  10786. */
  10787. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_tap_shock(u8 v_tap_shock_u8)
  10788. {
  10789. /* variable used for return the status of communication result*/
  10790. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10791. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  10792. /* check the p_bmi160 structure as NULL*/
  10793. if (p_bmi160 == BMI160_NULL) {
  10794. return E_BMI160_NULL_PTR;
  10795. } else {
  10796. if (v_tap_shock_u8 < C_BMI160_TWO_U8X) {
  10797. /* write tap shock duration*/
  10798. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  10799. (p_bmi160->dev_addr,
  10800. BMI160_USER_INTR_TAP_0_INTR_TAP_SHOCK__REG,
  10801. &v_data_u8, C_BMI160_ONE_U8X);
  10802. if (com_rslt == SUCCESS) {
  10803. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  10804. BMI160_USER_INTR_TAP_0_INTR_TAP_SHOCK,
  10805. v_tap_shock_u8);
  10806. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  10807. (p_bmi160->dev_addr,
  10808. BMI160_USER_INTR_TAP_0_INTR_TAP_SHOCK__REG,
  10809. &v_data_u8, C_BMI160_ONE_U8X);
  10810. }
  10811. } else {
  10812. com_rslt = E_BMI160_OUT_OF_RANGE;
  10813. }
  10814. }
  10815. return com_rslt;
  10816. }
  10817. /*!
  10818. * @brief This API read
  10819. * tap quiet duration from the register 0x63 bit 7
  10820. *
  10821. *
  10822. * @param v_tap_quiet_u8 : The value of tap quiet
  10823. * value | Behaviour
  10824. * ----------|-------------------
  10825. * 0x00 | BMI160_TAP_QUIET_30MS
  10826. * 0x01 | BMI160_TAP_QUIET_20MS
  10827. *
  10828. *
  10829. * @return results of bus communication function
  10830. * @retval 0 -> Success
  10831. * @retval -1 -> Error
  10832. *
  10833. *
  10834. */
  10835. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_tap_quiet(
  10836. u8 *v_tap_quiet_u8)
  10837. {
  10838. /* variable used for return the status of communication result*/
  10839. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10840. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  10841. /* check the p_bmi160 structure as NULL*/
  10842. if (p_bmi160 == BMI160_NULL) {
  10843. return E_BMI160_NULL_PTR;
  10844. } else {
  10845. /* read tap quiet duration*/
  10846. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  10847. p_bmi160->dev_addr,
  10848. BMI160_USER_INTR_TAP_0_INTR_TAP_QUIET__REG,
  10849. &v_data_u8, C_BMI160_ONE_U8X);
  10850. *v_tap_quiet_u8 = BMI160_GET_BITSLICE(
  10851. v_data_u8,
  10852. BMI160_USER_INTR_TAP_0_INTR_TAP_QUIET);
  10853. }
  10854. return com_rslt;
  10855. }
  10856. /*!
  10857. * @brief This API write
  10858. * tap quiet duration from the register 0x63 bit 7
  10859. *
  10860. *
  10861. * @param v_tap_quiet_u8 : The value of tap quiet
  10862. * value | Behaviour
  10863. * ----------|-------------------
  10864. * 0x00 | BMI160_TAP_QUIET_30MS
  10865. * 0x01 | BMI160_TAP_QUIET_20MS
  10866. *
  10867. *
  10868. * @return results of bus communication function
  10869. * @retval 0 -> Success
  10870. * @retval -1 -> Error
  10871. *
  10872. *
  10873. */
  10874. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_tap_quiet(u8 v_tap_quiet_u8)
  10875. {
  10876. /* variable used for return the status of communication result*/
  10877. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10878. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  10879. /* check the p_bmi160 structure as NULL*/
  10880. if (p_bmi160 == BMI160_NULL) {
  10881. return E_BMI160_NULL_PTR;
  10882. } else {
  10883. if (v_tap_quiet_u8 < C_BMI160_TWO_U8X) {
  10884. /* write tap quiet duration*/
  10885. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  10886. (p_bmi160->dev_addr,
  10887. BMI160_USER_INTR_TAP_0_INTR_TAP_QUIET__REG,
  10888. &v_data_u8, C_BMI160_ONE_U8X);
  10889. if (com_rslt == SUCCESS) {
  10890. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  10891. BMI160_USER_INTR_TAP_0_INTR_TAP_QUIET,
  10892. v_tap_quiet_u8);
  10893. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  10894. (p_bmi160->dev_addr,
  10895. BMI160_USER_INTR_TAP_0_INTR_TAP_QUIET__REG,
  10896. &v_data_u8, C_BMI160_ONE_U8X);
  10897. }
  10898. } else {
  10899. com_rslt = E_BMI160_OUT_OF_RANGE;
  10900. }
  10901. }
  10902. return com_rslt;
  10903. }
  10904. /*!
  10905. * @brief This API read Threshold of the
  10906. * single/double tap interrupt from the register 0x64 bit 0 to 4
  10907. *
  10908. *
  10909. * @param v_tap_thres_u8 : The value of single/double tap threshold
  10910. *
  10911. * @note single/double tap threshold changes according to accel g range
  10912. * accel g range can be set by the function ""
  10913. * accel_range | single/double tap threshold
  10914. * ----------------|---------------------
  10915. * 2g | ((v_tap_thres_u8 + 1) * 62.5)mg
  10916. * 4g | ((v_tap_thres_u8 + 1) * 125)mg
  10917. * 8g | ((v_tap_thres_u8 + 1) * 250)mg
  10918. * 16g | ((v_tap_thres_u8 + 1) * 500)mg
  10919. *
  10920. * @return results of bus communication function
  10921. * @retval 0 -> Success
  10922. * @retval -1 -> Error
  10923. *
  10924. *
  10925. */
  10926. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_tap_thres(
  10927. u8 *v_tap_thres_u8)
  10928. {
  10929. /* variable used for return the status of communication result*/
  10930. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10931. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  10932. /* check the p_bmi160 structure as NULL*/
  10933. if (p_bmi160 == BMI160_NULL) {
  10934. return E_BMI160_NULL_PTR;
  10935. } else {
  10936. /* read tap threshold*/
  10937. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  10938. p_bmi160->dev_addr,
  10939. BMI160_USER_INTR_TAP_1_INTR_TAP_THRES__REG,
  10940. &v_data_u8, C_BMI160_ONE_U8X);
  10941. *v_tap_thres_u8 = BMI160_GET_BITSLICE
  10942. (v_data_u8,
  10943. BMI160_USER_INTR_TAP_1_INTR_TAP_THRES);
  10944. }
  10945. return com_rslt;
  10946. }
  10947. /*!
  10948. * @brief This API write Threshold of the
  10949. * single/double tap interrupt from the register 0x64 bit 0 to 4
  10950. *
  10951. *
  10952. * @param v_tap_thres_u8 : The value of single/double tap threshold
  10953. *
  10954. * @note single/double tap threshold changes according to accel g range
  10955. * accel g range can be set by the function ""
  10956. * accel_range | single/double tap threshold
  10957. * ----------------|---------------------
  10958. * 2g | ((v_tap_thres_u8 + 1) * 62.5)mg
  10959. * 4g | ((v_tap_thres_u8 + 1) * 125)mg
  10960. * 8g | ((v_tap_thres_u8 + 1) * 250)mg
  10961. * 16g | ((v_tap_thres_u8 + 1) * 500)mg
  10962. *
  10963. * @return results of bus communication function
  10964. * @retval 0 -> Success
  10965. * @retval -1 -> Error
  10966. *
  10967. *
  10968. */
  10969. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_tap_thres(
  10970. u8 v_tap_thres_u8)
  10971. {
  10972. /* variable used for return the status of communication result*/
  10973. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  10974. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  10975. /* check the p_bmi160 structure as NULL*/
  10976. if (p_bmi160 == BMI160_NULL) {
  10977. return E_BMI160_NULL_PTR;
  10978. } else {
  10979. /* write tap threshold*/
  10980. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  10981. (p_bmi160->dev_addr,
  10982. BMI160_USER_INTR_TAP_1_INTR_TAP_THRES__REG,
  10983. &v_data_u8, C_BMI160_ONE_U8X);
  10984. if (com_rslt == SUCCESS) {
  10985. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  10986. BMI160_USER_INTR_TAP_1_INTR_TAP_THRES,
  10987. v_tap_thres_u8);
  10988. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  10989. (p_bmi160->dev_addr,
  10990. BMI160_USER_INTR_TAP_1_INTR_TAP_THRES__REG,
  10991. &v_data_u8, C_BMI160_ONE_U8X);
  10992. }
  10993. }
  10994. return com_rslt;
  10995. }
  10996. /*!
  10997. * @brief This API read the threshold for orientation interrupt
  10998. * from the register 0x65 bit 0 and 1
  10999. *
  11000. * @param v_orient_mode_u8 : The value of threshold for orientation
  11001. * value | Behaviour
  11002. * ----------|-------------------
  11003. * 0x00 | symmetrical
  11004. * 0x01 | high-asymmetrical
  11005. * 0x02 | low-asymmetrical
  11006. * 0x03 | symmetrical
  11007. *
  11008. *
  11009. *
  11010. * @return results of bus communication function
  11011. * @retval 0 -> Success
  11012. * @retval -1 -> Error
  11013. *
  11014. *
  11015. */
  11016. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_orient_mode(
  11017. u8 *v_orient_mode_u8)
  11018. {
  11019. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11020. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11021. /* check the p_bmi160 structure as NULL*/
  11022. if (p_bmi160 == BMI160_NULL) {
  11023. return E_BMI160_NULL_PTR;
  11024. } else {
  11025. /* read orientation threshold*/
  11026. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11027. (p_bmi160->dev_addr,
  11028. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_MODE__REG,
  11029. &v_data_u8, C_BMI160_ONE_U8X);
  11030. *v_orient_mode_u8 = BMI160_GET_BITSLICE
  11031. (v_data_u8,
  11032. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_MODE);
  11033. }
  11034. return com_rslt;
  11035. }
  11036. /*!
  11037. * @brief This API write the threshold for orientation interrupt
  11038. * from the register 0x65 bit 0 and 1
  11039. *
  11040. * @param v_orient_mode_u8 : The value of threshold for orientation
  11041. * value | Behaviour
  11042. * ----------|-------------------
  11043. * 0x00 | symmetrical
  11044. * 0x01 | high-asymmetrical
  11045. * 0x02 | low-asymmetrical
  11046. * 0x03 | symmetrical
  11047. *
  11048. *
  11049. *
  11050. * @return results of bus communication function
  11051. * @retval 0 -> Success
  11052. * @retval -1 -> Error
  11053. *
  11054. *
  11055. */
  11056. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_orient_mode(
  11057. u8 v_orient_mode_u8)
  11058. {
  11059. /* variable used for return the status of communication result*/
  11060. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11061. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11062. /* check the p_bmi160 structure as NULL*/
  11063. if (p_bmi160 == BMI160_NULL) {
  11064. return E_BMI160_NULL_PTR;
  11065. } else {
  11066. if (v_orient_mode_u8 < C_BMI160_FOUR_U8X) {
  11067. /* write orientation threshold*/
  11068. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11069. (p_bmi160->dev_addr,
  11070. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_MODE__REG,
  11071. &v_data_u8, C_BMI160_ONE_U8X);
  11072. if (com_rslt == SUCCESS) {
  11073. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  11074. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_MODE,
  11075. v_orient_mode_u8);
  11076. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  11077. (p_bmi160->dev_addr,
  11078. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_MODE__REG,
  11079. &v_data_u8, C_BMI160_ONE_U8X);
  11080. }
  11081. } else {
  11082. com_rslt = E_BMI160_OUT_OF_RANGE;
  11083. }
  11084. }
  11085. return com_rslt;
  11086. }
  11087. /*!
  11088. * @brief This API read the orient blocking mode
  11089. * that is used for the generation of the orientation interrupt.
  11090. * from the register 0x65 bit 2 and 3
  11091. *
  11092. * @param v_orient_blocking_u8 : The value of orient blocking mode
  11093. * value | Behaviour
  11094. * ----------|-------------------
  11095. * 0x00 | No blocking
  11096. * 0x01 | Theta blocking or acceleration in any axis > 1.5g
  11097. * 0x02 | Theta blocking or acceleration slope in any axis >
  11098. * - | 0.2g or acceleration in any axis > 1.5g
  11099. * 0x03 | Theta blocking or acceleration slope in any axis >
  11100. * - | 0.4g or acceleration in any axis >
  11101. * - | 1.5g and value of orient is not stable
  11102. * - | for at least 100 ms
  11103. *
  11104. *
  11105. *
  11106. * @return results of bus communication function
  11107. * @retval 0 -> Success
  11108. * @retval -1 -> Error
  11109. *
  11110. *
  11111. */
  11112. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_orient_blocking(
  11113. u8 *v_orient_blocking_u8)
  11114. {
  11115. /* variable used for return the status of communication result*/
  11116. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11117. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11118. /* check the p_bmi160 structure as NULL*/
  11119. if (p_bmi160 == BMI160_NULL) {
  11120. return E_BMI160_NULL_PTR;
  11121. } else {
  11122. /* read orient blocking mode*/
  11123. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11124. (p_bmi160->dev_addr,
  11125. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING__REG,
  11126. &v_data_u8, C_BMI160_ONE_U8X);
  11127. *v_orient_blocking_u8 = BMI160_GET_BITSLICE
  11128. (v_data_u8,
  11129. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING);
  11130. }
  11131. return com_rslt;
  11132. }
  11133. /*!
  11134. * @brief This API write the orient blocking mode
  11135. * that is used for the generation of the orientation interrupt.
  11136. * from the register 0x65 bit 2 and 3
  11137. *
  11138. * @param v_orient_blocking_u8 : The value of orient blocking mode
  11139. * value | Behaviour
  11140. * ----------|-------------------
  11141. * 0x00 | No blocking
  11142. * 0x01 | Theta blocking or acceleration in any axis > 1.5g
  11143. * 0x02 | Theta blocking or acceleration slope in any axis >
  11144. * - | 0.2g or acceleration in any axis > 1.5g
  11145. * 0x03 | Theta blocking or acceleration slope in any axis >
  11146. * - | 0.4g or acceleration in any axis >
  11147. * - | 1.5g and value of orient is not stable
  11148. * - | for at least 100 ms
  11149. *
  11150. *
  11151. *
  11152. * @return results of bus communication function
  11153. * @retval 0 -> Success
  11154. * @retval -1 -> Error
  11155. *
  11156. *
  11157. */
  11158. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_orient_blocking(
  11159. u8 v_orient_blocking_u8)
  11160. {
  11161. /* variable used for return the status of communication result*/
  11162. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11163. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11164. /* check the p_bmi160 structure as NULL*/
  11165. if (p_bmi160 == BMI160_NULL) {
  11166. return E_BMI160_NULL_PTR;
  11167. } else {
  11168. if (v_orient_blocking_u8 < C_BMI160_FOUR_U8X) {
  11169. /* write orient blocking mode*/
  11170. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11171. (p_bmi160->dev_addr,
  11172. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING__REG,
  11173. &v_data_u8, C_BMI160_ONE_U8X);
  11174. if (com_rslt == SUCCESS) {
  11175. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  11176. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING,
  11177. v_orient_blocking_u8);
  11178. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  11179. (p_bmi160->dev_addr,
  11180. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_BLOCKING__REG,
  11181. &v_data_u8, C_BMI160_ONE_U8X);
  11182. }
  11183. } else {
  11184. com_rslt = E_BMI160_OUT_OF_RANGE;
  11185. }
  11186. }
  11187. return com_rslt;
  11188. }
  11189. /*!
  11190. * @brief This API read Orient interrupt
  11191. * hysteresis, from the register 0x64 bit 4 to 7
  11192. *
  11193. *
  11194. *
  11195. * @param v_orient_hyst_u8 : The value of orient hysteresis
  11196. *
  11197. * @note 1 LSB corresponds to 62.5 mg,
  11198. * irrespective of the selected accel range
  11199. *
  11200. *
  11201. * @return results of bus communication function
  11202. * @retval 0 -> Success
  11203. * @retval -1 -> Error
  11204. *
  11205. *
  11206. */
  11207. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_orient_hyst(
  11208. u8 *v_orient_hyst_u8)
  11209. {
  11210. /* variable used for return the status of communication result*/
  11211. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11212. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11213. /* check the p_bmi160 structure as NULL*/
  11214. if (p_bmi160 == BMI160_NULL) {
  11215. return E_BMI160_NULL_PTR;
  11216. } else {
  11217. /* read orient hysteresis*/
  11218. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11219. (p_bmi160->dev_addr,
  11220. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_HYST__REG,
  11221. &v_data_u8, C_BMI160_ONE_U8X);
  11222. *v_orient_hyst_u8 = BMI160_GET_BITSLICE
  11223. (v_data_u8,
  11224. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_HYST);
  11225. }
  11226. return com_rslt;
  11227. }
  11228. /*!
  11229. * @brief This API write Orient interrupt
  11230. * hysteresis, from the register 0x64 bit 4 to 7
  11231. *
  11232. *
  11233. *
  11234. * @param v_orient_hyst_u8 : The value of orient hysteresis
  11235. *
  11236. * @note 1 LSB corresponds to 62.5 mg,
  11237. * irrespective of the selected accel range
  11238. *
  11239. *
  11240. * @return results of bus communication function
  11241. * @retval 0 -> Success
  11242. * @retval -1 -> Error
  11243. *
  11244. *
  11245. */
  11246. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_orient_hyst(
  11247. u8 v_orient_hyst_u8)
  11248. {
  11249. /* variable used for return the status of communication result*/
  11250. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11251. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11252. /* check the p_bmi160 structure as NULL*/
  11253. if (p_bmi160 == BMI160_NULL) {
  11254. return E_BMI160_NULL_PTR;
  11255. } else {
  11256. /* write orient hysteresis*/
  11257. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11258. (p_bmi160->dev_addr,
  11259. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_HYST__REG,
  11260. &v_data_u8, C_BMI160_ONE_U8X);
  11261. if (com_rslt == SUCCESS) {
  11262. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  11263. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_HYST,
  11264. v_orient_hyst_u8);
  11265. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  11266. (p_bmi160->dev_addr,
  11267. BMI160_USER_INTR_ORIENT_0_INTR_ORIENT_HYST__REG,
  11268. &v_data_u8, C_BMI160_ONE_U8X);
  11269. }
  11270. }
  11271. return com_rslt;
  11272. }
  11273. /*!
  11274. * @brief This API read Orient
  11275. * blocking angle (0 to 44.8) from the register 0x66 bit 0 to 5
  11276. *
  11277. * @param v_orient_theta_u8 : The value of Orient blocking angle
  11278. *
  11279. *
  11280. *
  11281. * @return results of bus communication function
  11282. * @retval 0 -> Success
  11283. * @retval -1 -> Error
  11284. *
  11285. *
  11286. */
  11287. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_orient_theta(
  11288. u8 *v_orient_theta_u8)
  11289. {
  11290. /* variable used for return the status of communication result*/
  11291. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11292. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11293. /* check the p_bmi160 structure as NULL*/
  11294. if (p_bmi160 == BMI160_NULL) {
  11295. return E_BMI160_NULL_PTR;
  11296. } else {
  11297. /* read Orient blocking angle*/
  11298. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11299. (p_bmi160->dev_addr,
  11300. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_THETA__REG,
  11301. &v_data_u8, C_BMI160_ONE_U8X);
  11302. *v_orient_theta_u8 = BMI160_GET_BITSLICE
  11303. (v_data_u8,
  11304. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_THETA);
  11305. }
  11306. return com_rslt;
  11307. }
  11308. /*!
  11309. * @brief This API write Orient
  11310. * blocking angle (0 to 44.8) from the register 0x66 bit 0 to 5
  11311. *
  11312. * @param v_orient_theta_u8 : The value of Orient blocking angle
  11313. *
  11314. *
  11315. *
  11316. * @return results of bus communication function
  11317. * @retval 0 -> Success
  11318. * @retval -1 -> Error
  11319. *
  11320. *
  11321. */
  11322. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_orient_theta(
  11323. u8 v_orient_theta_u8)
  11324. {
  11325. /* variable used for return the status of communication result*/
  11326. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11327. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11328. /* check the p_bmi160 structure as NULL*/
  11329. if (p_bmi160 == BMI160_NULL) {
  11330. return E_BMI160_NULL_PTR;
  11331. } else {
  11332. if (v_orient_theta_u8 <= C_BMI160_THIRTYONE_U8X) {
  11333. /* write Orient blocking angle*/
  11334. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11335. (p_bmi160->dev_addr,
  11336. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_THETA__REG,
  11337. &v_data_u8, C_BMI160_ONE_U8X);
  11338. if (com_rslt == SUCCESS) {
  11339. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  11340. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_THETA,
  11341. v_orient_theta_u8);
  11342. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  11343. (p_bmi160->dev_addr,
  11344. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_THETA__REG,
  11345. &v_data_u8, C_BMI160_ONE_U8X);
  11346. }
  11347. } else {
  11348. com_rslt = E_BMI160_OUT_OF_RANGE;
  11349. }
  11350. }
  11351. return com_rslt;
  11352. }
  11353. /*!
  11354. * @brief This API read orient change
  11355. * of up/down bit from the register 0x66 bit 6
  11356. *
  11357. * @param v_orient_ud_u8 : The value of orient change of up/down
  11358. * value | Behaviour
  11359. * ----------|-------------------
  11360. * 0x00 | Is ignored
  11361. * 0x01 | Generates orientation interrupt
  11362. *
  11363. *
  11364. * @return results of bus communication function
  11365. * @retval 0 -> Success
  11366. * @retval -1 -> Error
  11367. *
  11368. *
  11369. */
  11370. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_orient_ud_enable(
  11371. u8 *v_orient_ud_u8)
  11372. {
  11373. /* variable used for return the status of communication result*/
  11374. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11375. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11376. /* check the p_bmi160 structure as NULL*/
  11377. if (p_bmi160 == BMI160_NULL) {
  11378. return E_BMI160_NULL_PTR;
  11379. } else {
  11380. /* read orient up/down enable*/
  11381. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11382. (p_bmi160->dev_addr,
  11383. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE__REG,
  11384. &v_data_u8, C_BMI160_ONE_U8X);
  11385. *v_orient_ud_u8 = BMI160_GET_BITSLICE
  11386. (v_data_u8,
  11387. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE);
  11388. }
  11389. return com_rslt;
  11390. }
  11391. /*!
  11392. * @brief This API write orient change
  11393. * of up/down bit from the register 0x66 bit 6
  11394. *
  11395. * @param v_orient_ud_u8 : The value of orient change of up/down
  11396. * value | Behaviour
  11397. * ----------|-------------------
  11398. * 0x00 | Is ignored
  11399. * 0x01 | Generates orientation interrupt
  11400. *
  11401. *
  11402. * @return results of bus communication function
  11403. * @retval 0 -> Success
  11404. * @retval -1 -> Error
  11405. *
  11406. *
  11407. */
  11408. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_orient_ud_enable(
  11409. u8 v_orient_ud_u8)
  11410. {
  11411. /* variable used for return the status of communication result*/
  11412. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11413. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11414. /* check the p_bmi160 structure as NULL*/
  11415. if (p_bmi160 == BMI160_NULL) {
  11416. return E_BMI160_NULL_PTR;
  11417. } else {
  11418. if (v_orient_ud_u8 < C_BMI160_TWO_U8X) {
  11419. /* write orient up/down enable */
  11420. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11421. (p_bmi160->dev_addr,
  11422. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE__REG,
  11423. &v_data_u8, C_BMI160_ONE_U8X);
  11424. if (com_rslt == SUCCESS) {
  11425. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  11426. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE,
  11427. v_orient_ud_u8);
  11428. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  11429. (p_bmi160->dev_addr,
  11430. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_UD_ENABLE__REG,
  11431. &v_data_u8, C_BMI160_ONE_U8X);
  11432. }
  11433. } else {
  11434. com_rslt = E_BMI160_OUT_OF_RANGE;
  11435. }
  11436. }
  11437. return com_rslt;
  11438. }
  11439. /*!
  11440. * @brief This API read orientation axes changes
  11441. * from the register 0x66 bit 7
  11442. *
  11443. * @param v_orient_axes_u8 : The value of orient axes assignment
  11444. * value | Behaviour | Name
  11445. * ----------|--------------------|------
  11446. * 0x00 | x = x, y = y, z = z|orient_ax_noex
  11447. * 0x01 | x = y, y = z, z = x|orient_ax_ex
  11448. *
  11449. *
  11450. * @return results of bus communication function
  11451. * @retval 0 -> Success
  11452. * @retval -1 -> Error
  11453. *
  11454. *
  11455. */
  11456. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_orient_axes_enable(
  11457. u8 *v_orient_axes_u8)
  11458. {
  11459. /* variable used for return the status of communication result*/
  11460. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11461. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11462. /* check the p_bmi160 structure as NULL*/
  11463. if (p_bmi160 == BMI160_NULL) {
  11464. return E_BMI160_NULL_PTR;
  11465. } else {
  11466. /* read orientation axes changes */
  11467. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11468. (p_bmi160->dev_addr,
  11469. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX__REG,
  11470. &v_data_u8, C_BMI160_ONE_U8X);
  11471. *v_orient_axes_u8 = BMI160_GET_BITSLICE
  11472. (v_data_u8,
  11473. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX);
  11474. }
  11475. return com_rslt;
  11476. }
  11477. /*!
  11478. * @brief This API write orientation axes changes
  11479. * from the register 0x66 bit 7
  11480. *
  11481. * @param v_orient_axes_u8 : The value of orient axes assignment
  11482. * value | Behaviour | Name
  11483. * ----------|--------------------|------
  11484. * 0x00 | x = x, y = y, z = z|orient_ax_noex
  11485. * 0x01 | x = y, y = z, z = x|orient_ax_ex
  11486. *
  11487. *
  11488. * @return results of bus communication function
  11489. * @retval 0 -> Success
  11490. * @retval -1 -> Error
  11491. *
  11492. *
  11493. */
  11494. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_orient_axes_enable(
  11495. u8 v_orient_axes_u8)
  11496. {
  11497. /* variable used for return the status of communication result*/
  11498. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11499. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11500. /* check the p_bmi160 structure as NULL*/
  11501. if (p_bmi160 == BMI160_NULL) {
  11502. return E_BMI160_NULL_PTR;
  11503. } else {
  11504. if (v_orient_axes_u8 < C_BMI160_TWO_U8X) {
  11505. /*write orientation axes changes */
  11506. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11507. (p_bmi160->dev_addr,
  11508. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX__REG,
  11509. &v_data_u8, C_BMI160_ONE_U8X);
  11510. if (com_rslt == SUCCESS) {
  11511. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  11512. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX,
  11513. v_orient_axes_u8);
  11514. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  11515. (p_bmi160->dev_addr,
  11516. BMI160_USER_INTR_ORIENT_1_INTR_ORIENT_AXES_EX__REG,
  11517. &v_data_u8, C_BMI160_ONE_U8X);
  11518. }
  11519. } else {
  11520. com_rslt = E_BMI160_OUT_OF_RANGE;
  11521. }
  11522. }
  11523. return com_rslt;
  11524. }
  11525. /*!
  11526. * @brief This API read Flat angle (0 to 44.8) for flat interrupt
  11527. * from the register 0x67 bit 0 to 5
  11528. *
  11529. * @param v_flat_theta_u8 : The value of flat angle
  11530. *
  11531. *
  11532. *
  11533. * @return results of bus communication function
  11534. * @retval 0 -> Success
  11535. * @retval -1 -> Error
  11536. *
  11537. *
  11538. */
  11539. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_flat_theta(
  11540. u8 *v_flat_theta_u8)
  11541. {
  11542. /* variable used for return the status of communication result*/
  11543. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11544. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11545. /* check the p_bmi160 structure as NULL*/
  11546. if (p_bmi160 == BMI160_NULL) {
  11547. return E_BMI160_NULL_PTR;
  11548. } else {
  11549. /* read Flat angle*/
  11550. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11551. (p_bmi160->dev_addr,
  11552. BMI160_USER_INTR_FLAT_0_INTR_FLAT_THETA__REG,
  11553. &v_data_u8, C_BMI160_ONE_U8X);
  11554. *v_flat_theta_u8 = BMI160_GET_BITSLICE(v_data_u8,
  11555. BMI160_USER_INTR_FLAT_0_INTR_FLAT_THETA);
  11556. }
  11557. return com_rslt;
  11558. }
  11559. /*!
  11560. * @brief This API write Flat angle (0 to 44.8) for flat interrupt
  11561. * from the register 0x67 bit 0 to 5
  11562. *
  11563. * @param v_flat_theta_u8 : The value of flat angle
  11564. *
  11565. *
  11566. *
  11567. * @return results of bus communication function
  11568. * @retval 0 -> Success
  11569. * @retval -1 -> Error
  11570. *
  11571. *
  11572. */
  11573. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_flat_theta(
  11574. u8 v_flat_theta_u8)
  11575. {
  11576. /* variable used for return the status of communication result*/
  11577. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11578. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11579. /* check the p_bmi160 structure as NULL*/
  11580. if (p_bmi160 == BMI160_NULL) {
  11581. return E_BMI160_NULL_PTR;
  11582. } else {
  11583. if (v_flat_theta_u8 <= C_BMI160_THIRTYONE_U8X) {
  11584. /* write Flat angle */
  11585. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11586. (p_bmi160->dev_addr,
  11587. BMI160_USER_INTR_FLAT_0_INTR_FLAT_THETA__REG,
  11588. &v_data_u8, C_BMI160_ONE_U8X);
  11589. if (com_rslt == SUCCESS) {
  11590. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  11591. BMI160_USER_INTR_FLAT_0_INTR_FLAT_THETA,
  11592. v_flat_theta_u8);
  11593. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  11594. (p_bmi160->dev_addr,
  11595. BMI160_USER_INTR_FLAT_0_INTR_FLAT_THETA__REG,
  11596. &v_data_u8, C_BMI160_ONE_U8X);
  11597. }
  11598. } else {
  11599. com_rslt = E_BMI160_OUT_OF_RANGE;
  11600. }
  11601. }
  11602. return com_rslt;
  11603. }
  11604. /*!
  11605. * @brief This API read Flat interrupt hold time;
  11606. * from the register 0x68 bit 4 and 5
  11607. *
  11608. * @param v_flat_hold_u8 : The value of flat hold time
  11609. * value | Behaviour
  11610. * ----------|-------------------
  11611. * 0x00 | 0ms
  11612. * 0x01 | 512ms
  11613. * 0x01 | 1024ms
  11614. * 0x01 | 2048ms
  11615. *
  11616. *
  11617. * @return results of bus communication function
  11618. * @retval 0 -> Success
  11619. * @retval -1 -> Error
  11620. *
  11621. *
  11622. */
  11623. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_flat_hold(
  11624. u8 *v_flat_hold_u8)
  11625. {
  11626. /* variable used for return the status of communication result*/
  11627. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11628. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11629. /* check the p_bmi160 structure as NULL*/
  11630. if (p_bmi160 == BMI160_NULL) {
  11631. return E_BMI160_NULL_PTR;
  11632. } else {
  11633. /* read flat hold time*/
  11634. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  11635. p_bmi160->dev_addr,
  11636. BMI160_USER_INTR_FLAT_1_INTR_FLAT_HOLD__REG,
  11637. &v_data_u8, C_BMI160_ONE_U8X);
  11638. *v_flat_hold_u8 = BMI160_GET_BITSLICE(v_data_u8,
  11639. BMI160_USER_INTR_FLAT_1_INTR_FLAT_HOLD);
  11640. }
  11641. return com_rslt;
  11642. }
  11643. /*!
  11644. * @brief This API write Flat interrupt hold time;
  11645. * from the register 0x68 bit 4 and 5
  11646. *
  11647. * @param v_flat_hold_u8 : The value of flat hold time
  11648. * value | Behaviour
  11649. * ----------|-------------------
  11650. * 0x00 | 0ms
  11651. * 0x01 | 512ms
  11652. * 0x01 | 1024ms
  11653. * 0x01 | 2048ms
  11654. *
  11655. *
  11656. * @return results of bus communication function
  11657. * @retval 0 -> Success
  11658. * @retval -1 -> Error
  11659. *
  11660. *
  11661. */
  11662. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_flat_hold(
  11663. u8 v_flat_hold_u8)
  11664. {
  11665. /* variable used for return the status of communication result*/
  11666. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11667. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11668. /* check the p_bmi160 structure as NULL*/
  11669. if (p_bmi160 == BMI160_NULL) {
  11670. return E_BMI160_NULL_PTR;
  11671. } else {
  11672. if (v_flat_hold_u8 < C_BMI160_FOUR_U8X) {
  11673. /* write flat hold time*/
  11674. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  11675. p_bmi160->dev_addr,
  11676. BMI160_USER_INTR_FLAT_1_INTR_FLAT_HOLD__REG,
  11677. &v_data_u8, C_BMI160_ONE_U8X);
  11678. if (com_rslt == SUCCESS) {
  11679. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  11680. BMI160_USER_INTR_FLAT_1_INTR_FLAT_HOLD,
  11681. v_flat_hold_u8);
  11682. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  11683. (p_bmi160->dev_addr,
  11684. BMI160_USER_INTR_FLAT_1_INTR_FLAT_HOLD__REG,
  11685. &v_data_u8, C_BMI160_ONE_U8X);
  11686. }
  11687. } else {
  11688. com_rslt = E_BMI160_OUT_OF_RANGE;
  11689. }
  11690. }
  11691. return com_rslt;
  11692. }
  11693. /*!
  11694. * @brief This API read flat interrupt hysteresis
  11695. * from the register 0x68 bit 0 to 3
  11696. *
  11697. * @param v_flat_hyst_u8 : The value of flat hysteresis
  11698. *
  11699. *
  11700. *
  11701. * @return results of bus communication function
  11702. * @retval 0 -> Success
  11703. * @retval -1 -> Error
  11704. *
  11705. *
  11706. */
  11707. BMI160_RETURN_FUNCTION_TYPE bmi160_get_intr_flat_hyst(
  11708. u8 *v_flat_hyst_u8)
  11709. {
  11710. /* variable used to return the status of communication result*/
  11711. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11712. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11713. /* check the p_bmi160 structure as NULL*/
  11714. if (p_bmi160 == BMI160_NULL) {
  11715. return E_BMI160_NULL_PTR;
  11716. } else {
  11717. /* read the flat hysteresis*/
  11718. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  11719. p_bmi160->dev_addr,
  11720. BMI160_USER_INTR_FLAT_1_INTR_FLAT_HYST__REG,
  11721. &v_data_u8, C_BMI160_ONE_U8X);
  11722. *v_flat_hyst_u8 = BMI160_GET_BITSLICE(
  11723. v_data_u8,
  11724. BMI160_USER_INTR_FLAT_1_INTR_FLAT_HYST);
  11725. }
  11726. return com_rslt;
  11727. }
  11728. /*!
  11729. * @brief This API write flat interrupt hysteresis
  11730. * from the register 0x68 bit 0 to 3
  11731. *
  11732. * @param v_flat_hyst_u8 : The value of flat hysteresis
  11733. *
  11734. *
  11735. *
  11736. * @return results of bus communication function
  11737. * @retval 0 -> Success
  11738. * @retval -1 -> Error
  11739. *
  11740. *
  11741. */
  11742. BMI160_RETURN_FUNCTION_TYPE bmi160_set_intr_flat_hyst(
  11743. u8 v_flat_hyst_u8)
  11744. {
  11745. /* variable used for return the status of communication result*/
  11746. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11747. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11748. /* check the p_bmi160 structure as NULL*/
  11749. if (p_bmi160 == BMI160_NULL) {
  11750. return E_BMI160_NULL_PTR;
  11751. } else {
  11752. if (v_flat_hyst_u8 < C_BMI160_SIXTEEN_U8X) {
  11753. /* read the flat hysteresis*/
  11754. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11755. (p_bmi160->dev_addr,
  11756. BMI160_USER_INTR_FLAT_1_INTR_FLAT_HYST__REG,
  11757. &v_data_u8, C_BMI160_ONE_U8X);
  11758. if (com_rslt == SUCCESS) {
  11759. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  11760. BMI160_USER_INTR_FLAT_1_INTR_FLAT_HYST,
  11761. v_flat_hyst_u8);
  11762. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  11763. (p_bmi160->dev_addr,
  11764. BMI160_USER_INTR_FLAT_1_INTR_FLAT_HYST__REG,
  11765. &v_data_u8, C_BMI160_ONE_U8X);
  11766. }
  11767. } else {
  11768. com_rslt = E_BMI160_OUT_OF_RANGE;
  11769. }
  11770. }
  11771. return com_rslt;
  11772. }
  11773. /*!
  11774. * @brief This API read accel offset compensation
  11775. * target value for z-axis from the register 0x69 bit 0 and 1
  11776. *
  11777. * @param v_foc_accel_z_u8 : the value of accel offset compensation z axis
  11778. * value | Behaviour
  11779. * ----------|-------------------
  11780. * 0x00 | disable
  11781. * 0x01 | +1g
  11782. * 0x01 | -1g
  11783. * 0x01 | 0g
  11784. *
  11785. * @return results of bus communication function
  11786. * @retval 0 -> Success
  11787. * @retval -1 -> Error
  11788. *
  11789. *
  11790. */
  11791. BMI160_RETURN_FUNCTION_TYPE bmi160_get_foc_accel_z(u8 *v_foc_accel_z_u8)
  11792. {
  11793. /* variable used for return the status of communication result*/
  11794. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11795. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11796. /* check the p_bmi160 structure as NULL*/
  11797. if (p_bmi160 == BMI160_NULL) {
  11798. return E_BMI160_NULL_PTR;
  11799. } else {
  11800. /* read the accel offset compensation for z axis*/
  11801. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  11802. p_bmi160->dev_addr,
  11803. BMI160_USER_FOC_ACCEL_Z__REG,
  11804. &v_data_u8, C_BMI160_ONE_U8X);
  11805. *v_foc_accel_z_u8 = BMI160_GET_BITSLICE(v_data_u8,
  11806. BMI160_USER_FOC_ACCEL_Z);
  11807. }
  11808. return com_rslt;
  11809. }
  11810. /*!
  11811. * @brief This API write accel offset compensation
  11812. * target value for z-axis from the register 0x69 bit 0 and 1
  11813. *
  11814. * @param v_foc_accel_z_u8 : the value of accel offset compensation z axis
  11815. * value | Behaviour
  11816. * ----------|-------------------
  11817. * 0x00 | disable
  11818. * 0x01 | +1g
  11819. * 0x01 | -1g
  11820. * 0x01 | 0g
  11821. *
  11822. * @return results of bus communication function
  11823. * @retval 0 -> Success
  11824. * @retval -1 -> Error
  11825. *
  11826. *
  11827. */
  11828. BMI160_RETURN_FUNCTION_TYPE bmi160_set_foc_accel_z(
  11829. u8 v_foc_accel_z_u8)
  11830. {
  11831. /* variable used for return the status of communication result*/
  11832. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11833. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11834. /* check the p_bmi160 structure as NULL*/
  11835. if (p_bmi160 == BMI160_NULL) {
  11836. return E_BMI160_NULL_PTR;
  11837. } else {
  11838. /* write the accel offset compensation for z axis*/
  11839. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11840. (p_bmi160->dev_addr,
  11841. BMI160_USER_FOC_ACCEL_Z__REG,
  11842. &v_data_u8, C_BMI160_ONE_U8X);
  11843. if (com_rslt == SUCCESS) {
  11844. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  11845. BMI160_USER_FOC_ACCEL_Z,
  11846. v_foc_accel_z_u8);
  11847. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  11848. (p_bmi160->dev_addr,
  11849. BMI160_USER_FOC_ACCEL_Z__REG,
  11850. &v_data_u8, C_BMI160_ONE_U8X);
  11851. }
  11852. }
  11853. return com_rslt;
  11854. }
  11855. /*!
  11856. * @brief This API read accel offset compensation
  11857. * target value for y-axis
  11858. * from the register 0x69 bit 2 and 3
  11859. *
  11860. * @param v_foc_accel_y_u8 : the value of accel offset compensation y axis
  11861. * value | Behaviour
  11862. * ----------|-------------------
  11863. * 0x00 | disable
  11864. * 0x01 | +1g
  11865. * 0x01 | -1g
  11866. * 0x01 | 0g
  11867. *
  11868. *
  11869. *
  11870. * @return results of bus communication function
  11871. * @retval 0 -> Success
  11872. * @retval -1 -> Error
  11873. *
  11874. *
  11875. */
  11876. BMI160_RETURN_FUNCTION_TYPE bmi160_get_foc_accel_y(u8 *v_foc_accel_y_u8)
  11877. {
  11878. /* variable used for return the status of communication result*/
  11879. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11880. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11881. /* check the p_bmi160 structure as NULL*/
  11882. if (p_bmi160 == BMI160_NULL) {
  11883. return E_BMI160_NULL_PTR;
  11884. } else {
  11885. /* read the accel offset compensation for y axis*/
  11886. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11887. (p_bmi160->dev_addr,
  11888. BMI160_USER_FOC_ACCEL_Y__REG,
  11889. &v_data_u8, C_BMI160_ONE_U8X);
  11890. *v_foc_accel_y_u8 = BMI160_GET_BITSLICE(v_data_u8,
  11891. BMI160_USER_FOC_ACCEL_Y);
  11892. }
  11893. return com_rslt;
  11894. }
  11895. /*!
  11896. * @brief This API write accel offset compensation
  11897. * target value for y-axis
  11898. * from the register 0x69 bit 2 and 3
  11899. *
  11900. * @param v_foc_accel_y_u8 : the value of accel offset compensation y axis
  11901. * value | Behaviour
  11902. * ----------|-------------------
  11903. * 0x00 | disable
  11904. * 0x01 | +1g
  11905. * 0x01 | -1g
  11906. * 0x01 | 0g
  11907. *
  11908. *
  11909. *
  11910. * @return results of bus communication function
  11911. * @retval 0 -> Success
  11912. * @retval -1 -> Error
  11913. *
  11914. *
  11915. */
  11916. BMI160_RETURN_FUNCTION_TYPE bmi160_set_foc_accel_y(u8 v_foc_accel_y_u8)
  11917. {
  11918. /* variable used for return the status of communication result*/
  11919. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11920. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11921. /* check the p_bmi160 structure as NULL*/
  11922. if (p_bmi160 == BMI160_NULL) {
  11923. return E_BMI160_NULL_PTR;
  11924. } else {
  11925. if (v_foc_accel_y_u8 < C_BMI160_FOUR_U8X) {
  11926. /* write the accel offset compensation for y axis*/
  11927. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  11928. (p_bmi160->dev_addr,
  11929. BMI160_USER_FOC_ACCEL_Y__REG,
  11930. &v_data_u8, C_BMI160_ONE_U8X);
  11931. if (com_rslt == SUCCESS) {
  11932. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  11933. BMI160_USER_FOC_ACCEL_Y,
  11934. v_foc_accel_y_u8);
  11935. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  11936. (p_bmi160->dev_addr,
  11937. BMI160_USER_FOC_ACCEL_Y__REG,
  11938. &v_data_u8, C_BMI160_ONE_U8X);
  11939. }
  11940. } else {
  11941. com_rslt = E_BMI160_OUT_OF_RANGE;
  11942. }
  11943. }
  11944. return com_rslt;
  11945. }
  11946. /*!
  11947. * @brief This API read accel offset compensation
  11948. * target value for x-axis is
  11949. * from the register 0x69 bit 4 and 5
  11950. *
  11951. * @param v_foc_accel_x_u8 : the value of accel offset compensation x axis
  11952. * value | Behaviour
  11953. * ----------|-------------------
  11954. * 0x00 | disable
  11955. * 0x01 | +1g
  11956. * 0x01 | -1g
  11957. * 0x01 | 0g
  11958. *
  11959. *
  11960. *
  11961. * @return results of bus communication function
  11962. * @retval 0 -> Success
  11963. * @retval -1 -> Error
  11964. *
  11965. *
  11966. */
  11967. BMI160_RETURN_FUNCTION_TYPE bmi160_get_foc_accel_x(u8 *v_foc_accel_x_u8)
  11968. {
  11969. /* variable used for return the status of communication result*/
  11970. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  11971. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  11972. /* check the p_bmi160 structure as NULL*/
  11973. if (p_bmi160 == BMI160_NULL) {
  11974. return E_BMI160_NULL_PTR;
  11975. } else {
  11976. /* read the accel offset compensation for x axis*/
  11977. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  11978. p_bmi160->dev_addr,
  11979. BMI160_USER_FOC_ACCEL_X__REG,
  11980. &v_data_u8, C_BMI160_ONE_U8X);
  11981. *v_foc_accel_x_u8 = BMI160_GET_BITSLICE(v_data_u8,
  11982. BMI160_USER_FOC_ACCEL_X);
  11983. }
  11984. return com_rslt;
  11985. }
  11986. /*!
  11987. * @brief This API write accel offset compensation
  11988. * target value for x-axis is
  11989. * from the register 0x69 bit 4 and 5
  11990. *
  11991. * @param v_foc_accel_x_u8 : the value of accel offset compensation x axis
  11992. * value | Behaviour
  11993. * ----------|-------------------
  11994. * 0x00 | disable
  11995. * 0x01 | +1g
  11996. * 0x01 | -1g
  11997. * 0x01 | 0g
  11998. *
  11999. *
  12000. *
  12001. * @return results of bus communication function
  12002. * @retval 0 -> Success
  12003. * @retval -1 -> Error
  12004. *
  12005. *
  12006. */
  12007. BMI160_RETURN_FUNCTION_TYPE bmi160_set_foc_accel_x(u8 v_foc_accel_x_u8)
  12008. {
  12009. /* variable used for return the status of communication result*/
  12010. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12011. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  12012. /* check the p_bmi160 structure as NULL*/
  12013. if (p_bmi160 == BMI160_NULL) {
  12014. return E_BMI160_NULL_PTR;
  12015. } else {
  12016. if (v_foc_accel_x_u8 < C_BMI160_FOUR_U8X) {
  12017. /* write the accel offset compensation for x axis*/
  12018. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  12019. p_bmi160->dev_addr,
  12020. BMI160_USER_FOC_ACCEL_X__REG,
  12021. &v_data_u8, C_BMI160_ONE_U8X);
  12022. if (com_rslt == SUCCESS) {
  12023. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  12024. BMI160_USER_FOC_ACCEL_X,
  12025. v_foc_accel_x_u8);
  12026. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  12027. p_bmi160->dev_addr,
  12028. BMI160_USER_FOC_ACCEL_X__REG,
  12029. &v_data_u8, C_BMI160_ONE_U8X);
  12030. }
  12031. } else {
  12032. com_rslt = E_BMI160_OUT_OF_RANGE;
  12033. }
  12034. }
  12035. return com_rslt;
  12036. }
  12037. /*!
  12038. * @brief This API writes accel fast offset compensation
  12039. * from the register 0x69 bit 0 to 5
  12040. * @brief This API writes each axis individually
  12041. * FOC_X_AXIS - bit 4 and 5
  12042. * FOC_Y_AXIS - bit 2 and 3
  12043. * FOC_Z_AXIS - bit 0 and 1
  12044. *
  12045. * @param v_foc_accel_u8: The value of accel offset compensation
  12046. * value | Behaviour
  12047. * ----------|-------------------
  12048. * 0x00 | disable
  12049. * 0x01 | +1g
  12050. * 0x01 | -1g
  12051. * 0x01 | 0g
  12052. *
  12053. * @param v_axis_u8: The value of accel offset axis selection
  12054. * value | axis
  12055. * ----------|-------------------
  12056. * 0 | FOC_X_AXIS
  12057. * 1 | FOC_Y_AXIS
  12058. * 2 | FOC_Z_AXIS
  12059. *
  12060. * @param v_accel_offset_s8: The accel offset value
  12061. *
  12062. * @return results of bus communication function
  12063. * @retval 0 -> Success
  12064. * @retval -1 -> Error
  12065. *
  12066. *
  12067. */
  12068. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_foc_trigger(u8 v_axis_u8,
  12069. u8 v_foc_accel_u8, s8 *v_accel_offset_s8)
  12070. {
  12071. /* variable used for return the status of communication result*/
  12072. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12073. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  12074. s8 v_status_s8 = SUCCESS;
  12075. u8 v_timeout_u8 = C_BMI160_ZERO_U8X;
  12076. s8 v_foc_accel_offset_x_s8 = C_BMI160_ZERO_U8X;
  12077. s8 v_foc_accel_offset_y_s8 = C_BMI160_ZERO_U8X;
  12078. s8 v_foc_accel_offset_z_s8 = C_BMI160_ZERO_U8X;
  12079. u8 focstatus = C_BMI160_ZERO_U8X;
  12080. /* check the p_bmi160 structure as NULL*/
  12081. if (p_bmi160 == BMI160_NULL) {
  12082. return E_BMI160_NULL_PTR;
  12083. } else {
  12084. v_status_s8 = bmi160_set_accel_offset_enable(
  12085. ACCEL_OFFSET_ENABLE);
  12086. if (v_status_s8 == SUCCESS) {
  12087. switch (v_axis_u8) {
  12088. case FOC_X_AXIS:
  12089. com_rslt =
  12090. p_bmi160->BMI160_BUS_READ_FUNC(
  12091. p_bmi160->dev_addr,
  12092. BMI160_USER_FOC_ACCEL_X__REG,
  12093. &v_data_u8, C_BMI160_ONE_U8X);
  12094. if (com_rslt == SUCCESS) {
  12095. v_data_u8 =
  12096. BMI160_SET_BITSLICE(v_data_u8,
  12097. BMI160_USER_FOC_ACCEL_X,
  12098. v_foc_accel_u8);
  12099. com_rslt +=
  12100. p_bmi160->BMI160_BUS_WRITE_FUNC(
  12101. p_bmi160->dev_addr,
  12102. BMI160_USER_FOC_ACCEL_X__REG,
  12103. &v_data_u8, C_BMI160_ONE_U8X);
  12104. }
  12105. /* trigger the
  12106. FOC need to write
  12107. 0x03 in the register 0x7e*/
  12108. com_rslt +=
  12109. bmi160_set_command_register(
  12110. START_FOC_ACCEL_GYRO);
  12111. com_rslt +=
  12112. bmi160_get_foc_rdy(&focstatus);
  12113. if ((com_rslt != SUCCESS) ||
  12114. (focstatus != C_BMI160_ONE_U8X)) {
  12115. while ((com_rslt != SUCCESS) ||
  12116. (focstatus != C_BMI160_ONE_U8X
  12117. && v_timeout_u8 <
  12118. BMI160_MAXIMUM_TIMEOUT)) {
  12119. p_bmi160->delay_msec(
  12120. BMI160_DELAY_SETTLING_TIME);
  12121. com_rslt = bmi160_get_foc_rdy(
  12122. &focstatus);
  12123. v_timeout_u8++;
  12124. }
  12125. }
  12126. if ((com_rslt == SUCCESS) &&
  12127. (focstatus == C_BMI160_ONE_U8X)) {
  12128. com_rslt +=
  12129. bmi160_get_accel_offset_compensation_xaxis(
  12130. &v_foc_accel_offset_x_s8);
  12131. *v_accel_offset_s8 =
  12132. v_foc_accel_offset_x_s8;
  12133. }
  12134. break;
  12135. case FOC_Y_AXIS:
  12136. com_rslt =
  12137. p_bmi160->BMI160_BUS_READ_FUNC(
  12138. p_bmi160->dev_addr,
  12139. BMI160_USER_FOC_ACCEL_Y__REG,
  12140. &v_data_u8, C_BMI160_ONE_U8X);
  12141. if (com_rslt == SUCCESS) {
  12142. v_data_u8 =
  12143. BMI160_SET_BITSLICE(v_data_u8,
  12144. BMI160_USER_FOC_ACCEL_Y,
  12145. v_foc_accel_u8);
  12146. com_rslt +=
  12147. p_bmi160->BMI160_BUS_WRITE_FUNC(
  12148. p_bmi160->dev_addr,
  12149. BMI160_USER_FOC_ACCEL_Y__REG,
  12150. &v_data_u8, C_BMI160_ONE_U8X);
  12151. }
  12152. /* trigger the FOC
  12153. need to write 0x03
  12154. in the register 0x7e*/
  12155. com_rslt +=
  12156. bmi160_set_command_register(
  12157. START_FOC_ACCEL_GYRO);
  12158. com_rslt +=
  12159. bmi160_get_foc_rdy(&focstatus);
  12160. if ((com_rslt != SUCCESS) ||
  12161. (focstatus != C_BMI160_ONE_U8X)) {
  12162. while ((com_rslt != SUCCESS) ||
  12163. (focstatus != C_BMI160_ONE_U8X
  12164. && v_timeout_u8 <
  12165. BMI160_MAXIMUM_TIMEOUT)) {
  12166. p_bmi160->delay_msec(
  12167. BMI160_DELAY_SETTLING_TIME);
  12168. com_rslt = bmi160_get_foc_rdy(
  12169. &focstatus);
  12170. v_timeout_u8++;
  12171. }
  12172. }
  12173. if ((com_rslt == SUCCESS) &&
  12174. (focstatus == C_BMI160_ONE_U8X)) {
  12175. com_rslt +=
  12176. bmi160_get_accel_offset_compensation_yaxis(
  12177. &v_foc_accel_offset_y_s8);
  12178. *v_accel_offset_s8 =
  12179. v_foc_accel_offset_y_s8;
  12180. }
  12181. break;
  12182. case FOC_Z_AXIS:
  12183. com_rslt =
  12184. p_bmi160->BMI160_BUS_READ_FUNC(
  12185. p_bmi160->dev_addr,
  12186. BMI160_USER_FOC_ACCEL_Z__REG,
  12187. &v_data_u8, C_BMI160_ONE_U8X);
  12188. if (com_rslt == SUCCESS) {
  12189. v_data_u8 =
  12190. BMI160_SET_BITSLICE(v_data_u8,
  12191. BMI160_USER_FOC_ACCEL_Z,
  12192. v_foc_accel_u8);
  12193. com_rslt +=
  12194. p_bmi160->BMI160_BUS_WRITE_FUNC(
  12195. p_bmi160->dev_addr,
  12196. BMI160_USER_FOC_ACCEL_Z__REG,
  12197. &v_data_u8, C_BMI160_ONE_U8X);
  12198. }
  12199. /* trigger the FOC need to write
  12200. 0x03 in the register 0x7e*/
  12201. com_rslt +=
  12202. bmi160_set_command_register(
  12203. START_FOC_ACCEL_GYRO);
  12204. com_rslt +=
  12205. bmi160_get_foc_rdy(&focstatus);
  12206. if ((com_rslt != SUCCESS) ||
  12207. (focstatus != C_BMI160_ONE_U8X)) {
  12208. while ((com_rslt != SUCCESS) ||
  12209. (focstatus != C_BMI160_ONE_U8X
  12210. && v_timeout_u8 <
  12211. BMI160_MAXIMUM_TIMEOUT)) {
  12212. p_bmi160->delay_msec(
  12213. BMI160_DELAY_SETTLING_TIME);
  12214. com_rslt = bmi160_get_foc_rdy(
  12215. &focstatus);
  12216. v_timeout_u8++;
  12217. }
  12218. }
  12219. if ((com_rslt == SUCCESS) &&
  12220. (focstatus == C_BMI160_ONE_U8X)) {
  12221. com_rslt +=
  12222. bmi160_get_accel_offset_compensation_zaxis(
  12223. &v_foc_accel_offset_z_s8);
  12224. *v_accel_offset_s8 =
  12225. v_foc_accel_offset_z_s8;
  12226. }
  12227. break;
  12228. default:
  12229. break;
  12230. }
  12231. } else {
  12232. com_rslt = ERROR;
  12233. }
  12234. }
  12235. return com_rslt;
  12236. }
  12237. /*!
  12238. * @brief This API write fast accel offset compensation
  12239. * it writes all axis together.To the register 0x69 bit 0 to 5
  12240. * FOC_X_AXIS - bit 4 and 5
  12241. * FOC_Y_AXIS - bit 2 and 3
  12242. * FOC_Z_AXIS - bit 0 and 1
  12243. *
  12244. * @param v_foc_accel_x_u8: The value of accel offset x compensation
  12245. * value | Behaviour
  12246. * ----------|-------------------
  12247. * 0x00 | disable
  12248. * 0x01 | +1g
  12249. * 0x01 | -1g
  12250. * 0x01 | 0g
  12251. *
  12252. * @param v_foc_accel_y_u8: The value of accel offset y compensation
  12253. * value | Behaviour
  12254. * ----------|-------------------
  12255. * 0x00 | disable
  12256. * 0x01 | +1g
  12257. * 0x01 | -1g
  12258. * 0x01 | 0g
  12259. *
  12260. * @param v_foc_accel_z_u8: The value of accel offset z compensation
  12261. * value | Behaviour
  12262. * ----------|-------------------
  12263. * 0x00 | disable
  12264. * 0x01 | +1g
  12265. * 0x01 | -1g
  12266. * 0x01 | 0g
  12267. *
  12268. * @param v_accel_off_x_s8: The value of accel offset x axis
  12269. * @param v_accel_off_y_s8: The value of accel offset y axis
  12270. * @param v_accel_off_z_s8: The value of accel offset z axis
  12271. *
  12272. *
  12273. * @return results of bus communication function
  12274. * @retval 0 -> Success
  12275. * @retval -1 -> Error
  12276. *
  12277. */
  12278. BMI160_RETURN_FUNCTION_TYPE bmi160_accel_foc_trigger_xyz(u8 v_foc_accel_x_u8,
  12279. u8 v_foc_accel_y_u8, u8 v_foc_accel_z_u8, s8 *v_accel_off_x_s8,
  12280. s8 *v_accel_off_y_s8, s8 *v_accel_off_z_s8)
  12281. {
  12282. /* variable used for return the status of communication result*/
  12283. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12284. u8 focx = C_BMI160_ZERO_U8X;
  12285. u8 focy = C_BMI160_ZERO_U8X;
  12286. u8 focz = C_BMI160_ZERO_U8X;
  12287. s8 v_foc_accel_offset_x_s8 = C_BMI160_ZERO_U8X;
  12288. s8 v_foc_accel_offset_y_s8 = C_BMI160_ZERO_U8X;
  12289. s8 v_foc_accel_offset_z_s8 = C_BMI160_ZERO_U8X;
  12290. u8 v_status_s8 = SUCCESS;
  12291. u8 v_timeout_u8 = C_BMI160_ZERO_U8X;
  12292. u8 focstatus = C_BMI160_ZERO_U8X;
  12293. /* check the p_bmi160 structure as NULL*/
  12294. if (p_bmi160 == BMI160_NULL) {
  12295. return E_BMI160_NULL_PTR;
  12296. } else {
  12297. v_status_s8 = bmi160_set_accel_offset_enable(
  12298. ACCEL_OFFSET_ENABLE);
  12299. if (v_status_s8 == SUCCESS) {
  12300. /* foc x axis*/
  12301. com_rslt =
  12302. p_bmi160->BMI160_BUS_READ_FUNC(
  12303. p_bmi160->dev_addr,
  12304. BMI160_USER_FOC_ACCEL_X__REG,
  12305. &focx, C_BMI160_ONE_U8X);
  12306. if (com_rslt == SUCCESS) {
  12307. focx = BMI160_SET_BITSLICE(focx,
  12308. BMI160_USER_FOC_ACCEL_X,
  12309. v_foc_accel_x_u8);
  12310. com_rslt +=
  12311. p_bmi160->BMI160_BUS_WRITE_FUNC(
  12312. p_bmi160->dev_addr,
  12313. BMI160_USER_FOC_ACCEL_X__REG,
  12314. &focx, C_BMI160_ONE_U8X);
  12315. }
  12316. /* foc y axis*/
  12317. com_rslt +=
  12318. p_bmi160->BMI160_BUS_READ_FUNC(
  12319. p_bmi160->dev_addr,
  12320. BMI160_USER_FOC_ACCEL_Y__REG,
  12321. &focy, C_BMI160_ONE_U8X);
  12322. if (com_rslt == SUCCESS) {
  12323. focy = BMI160_SET_BITSLICE(focy,
  12324. BMI160_USER_FOC_ACCEL_Y,
  12325. v_foc_accel_y_u8);
  12326. com_rslt +=
  12327. p_bmi160->BMI160_BUS_WRITE_FUNC(
  12328. p_bmi160->dev_addr,
  12329. BMI160_USER_FOC_ACCEL_Y__REG,
  12330. &focy, C_BMI160_ONE_U8X);
  12331. }
  12332. /* foc z axis*/
  12333. com_rslt +=
  12334. p_bmi160->BMI160_BUS_READ_FUNC(
  12335. p_bmi160->dev_addr,
  12336. BMI160_USER_FOC_ACCEL_Z__REG,
  12337. &focz, C_BMI160_ONE_U8X);
  12338. if (com_rslt == SUCCESS) {
  12339. focz = BMI160_SET_BITSLICE(focz,
  12340. BMI160_USER_FOC_ACCEL_Z,
  12341. v_foc_accel_z_u8);
  12342. com_rslt +=
  12343. p_bmi160->BMI160_BUS_WRITE_FUNC(
  12344. p_bmi160->dev_addr,
  12345. BMI160_USER_FOC_ACCEL_Z__REG,
  12346. &focz, C_BMI160_ONE_U8X);
  12347. }
  12348. /* trigger the FOC need to
  12349. write 0x03 in the register 0x7e*/
  12350. com_rslt += bmi160_set_command_register(
  12351. START_FOC_ACCEL_GYRO);
  12352. com_rslt += bmi160_get_foc_rdy(
  12353. &focstatus);
  12354. if ((com_rslt != SUCCESS) ||
  12355. (focstatus != C_BMI160_ONE_U8X)) {
  12356. while ((com_rslt != SUCCESS) ||
  12357. (focstatus != C_BMI160_ONE_U8X
  12358. && v_timeout_u8 <
  12359. BMI160_MAXIMUM_TIMEOUT)) {
  12360. p_bmi160->delay_msec(
  12361. BMI160_DELAY_SETTLING_TIME);
  12362. com_rslt = bmi160_get_foc_rdy(
  12363. &focstatus);
  12364. v_timeout_u8++;
  12365. }
  12366. }
  12367. if ((com_rslt == SUCCESS) &&
  12368. (focstatus == C_BMI160_ONE_U8X)) {
  12369. com_rslt +=
  12370. bmi160_get_accel_offset_compensation_xaxis(
  12371. &v_foc_accel_offset_x_s8);
  12372. *v_accel_off_x_s8 =
  12373. v_foc_accel_offset_x_s8;
  12374. com_rslt +=
  12375. bmi160_get_accel_offset_compensation_yaxis(
  12376. &v_foc_accel_offset_y_s8);
  12377. *v_accel_off_y_s8 =
  12378. v_foc_accel_offset_y_s8;
  12379. com_rslt +=
  12380. bmi160_get_accel_offset_compensation_zaxis(
  12381. &v_foc_accel_offset_z_s8);
  12382. *v_accel_off_z_s8 =
  12383. v_foc_accel_offset_z_s8;
  12384. }
  12385. } else {
  12386. com_rslt = ERROR;
  12387. }
  12388. }
  12389. return com_rslt;
  12390. }
  12391. /*!
  12392. * @brief This API read gyro fast offset enable
  12393. * from the register 0x69 bit 6
  12394. *
  12395. * @param v_foc_gyro_u8 : The value of gyro fast offset enable
  12396. * value | Description
  12397. * ----------|-------------
  12398. * 0 | fast offset compensation disabled
  12399. * 1 | fast offset compensation enabled
  12400. *
  12401. *
  12402. *
  12403. * @return results of bus communication function
  12404. * @retval 0 -> Success
  12405. * @retval -1 -> Error
  12406. *
  12407. *
  12408. */
  12409. BMI160_RETURN_FUNCTION_TYPE bmi160_get_foc_gyro_enable(
  12410. u8 *v_foc_gyro_u8)
  12411. {
  12412. /* used for return the status of bus communication */
  12413. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12414. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  12415. /* check the p_bmi160 structure as NULL*/
  12416. if (p_bmi160 == BMI160_NULL) {
  12417. return E_BMI160_NULL_PTR;
  12418. } else {
  12419. /* read the gyro fast offset enable*/
  12420. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  12421. p_bmi160->dev_addr,
  12422. BMI160_USER_FOC_GYRO_ENABLE__REG,
  12423. &v_data_u8, C_BMI160_ONE_U8X);
  12424. *v_foc_gyro_u8 = BMI160_GET_BITSLICE(v_data_u8,
  12425. BMI160_USER_FOC_GYRO_ENABLE);
  12426. }
  12427. return com_rslt;
  12428. }
  12429. /*!
  12430. * @brief This API write gyro fast offset enable
  12431. * from the register 0x69 bit 6
  12432. *
  12433. * @param v_foc_gyro_u8 : The value of gyro fast offset enable
  12434. * value | Description
  12435. * ----------|-------------
  12436. * 0 | fast offset compensation disabled
  12437. * 1 | fast offset compensation enabled
  12438. *
  12439. * @param v_gyro_off_x_s16 : The value of gyro fast offset x axis data
  12440. * @param v_gyro_off_y_s16 : The value of gyro fast offset y axis data
  12441. * @param v_gyro_off_z_s16 : The value of gyro fast offset z axis data
  12442. *
  12443. * @return results of bus communication function
  12444. * @retval 0 -> Success
  12445. * @retval -1 -> Error
  12446. *
  12447. *
  12448. */
  12449. BMI160_RETURN_FUNCTION_TYPE bmi160_set_foc_gyro_enable(
  12450. u8 v_foc_gyro_u8, s16 *v_gyro_off_x_s16,
  12451. s16 *v_gyro_off_y_s16, s16 *v_gyro_off_z_s16)
  12452. {
  12453. /* variable used for return the status of communication result*/
  12454. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12455. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  12456. u8 v_status_s8 = SUCCESS;
  12457. u8 v_timeout_u8 = C_BMI160_ZERO_U8X;
  12458. s16 offsetx = C_BMI160_ZERO_U8X;
  12459. s16 offsety = C_BMI160_ZERO_U8X;
  12460. s16 offsetz = C_BMI160_ZERO_U8X;
  12461. u8 focstatus = C_BMI160_ZERO_U8X;
  12462. /* check the p_bmi160 structure as NULL*/
  12463. if (p_bmi160 == BMI160_NULL) {
  12464. return E_BMI160_NULL_PTR;
  12465. } else {
  12466. v_status_s8 = bmi160_set_gyro_offset_enable(
  12467. GYRO_OFFSET_ENABLE);
  12468. if (v_status_s8 == SUCCESS) {
  12469. com_rslt =
  12470. p_bmi160->BMI160_BUS_READ_FUNC
  12471. (p_bmi160->dev_addr,
  12472. BMI160_USER_FOC_GYRO_ENABLE__REG,
  12473. &v_data_u8, C_BMI160_ONE_U8X);
  12474. if (com_rslt == SUCCESS) {
  12475. v_data_u8 =
  12476. BMI160_SET_BITSLICE(v_data_u8,
  12477. BMI160_USER_FOC_GYRO_ENABLE,
  12478. v_foc_gyro_u8);
  12479. com_rslt +=
  12480. p_bmi160->BMI160_BUS_WRITE_FUNC
  12481. (p_bmi160->dev_addr,
  12482. BMI160_USER_FOC_GYRO_ENABLE__REG,
  12483. &v_data_u8, C_BMI160_ONE_U8X);
  12484. }
  12485. /* trigger the FOC need to write 0x03
  12486. in the register 0x7e*/
  12487. com_rslt += bmi160_set_command_register
  12488. (START_FOC_ACCEL_GYRO);
  12489. com_rslt += bmi160_get_foc_rdy(&focstatus);
  12490. if ((com_rslt != SUCCESS) ||
  12491. (focstatus != C_BMI160_ONE_U8X)) {
  12492. while ((com_rslt != SUCCESS) ||
  12493. (focstatus != C_BMI160_ONE_U8X
  12494. && v_timeout_u8 <
  12495. BMI160_MAXIMUM_TIMEOUT)) {
  12496. p_bmi160->delay_msec(
  12497. BMI160_DELAY_SETTLING_TIME);
  12498. com_rslt = bmi160_get_foc_rdy(
  12499. &focstatus);
  12500. v_timeout_u8++;
  12501. }
  12502. }
  12503. if ((com_rslt == SUCCESS) &&
  12504. (focstatus == C_BMI160_ONE_U8X)) {
  12505. com_rslt +=
  12506. bmi160_get_gyro_offset_compensation_xaxis
  12507. (&offsetx);
  12508. *v_gyro_off_x_s16 = offsetx;
  12509. com_rslt +=
  12510. bmi160_get_gyro_offset_compensation_yaxis
  12511. (&offsety);
  12512. *v_gyro_off_y_s16 = offsety;
  12513. com_rslt +=
  12514. bmi160_get_gyro_offset_compensation_zaxis(
  12515. &offsetz);
  12516. *v_gyro_off_z_s16 = offsetz;
  12517. }
  12518. } else {
  12519. com_rslt = ERROR;
  12520. }
  12521. }
  12522. return com_rslt;
  12523. }
  12524. /*!
  12525. * @brief This API read NVM program enable
  12526. * from the register 0x6A bit 1
  12527. *
  12528. * @param v_nvm_prog_u8 : The value of NVM program enable
  12529. * Value | Description
  12530. * --------|-------------
  12531. * 0 | DISABLE
  12532. * 1 | ENABLE
  12533. *
  12534. * @return results of bus communication function
  12535. * @retval 0 -> Success
  12536. * @retval -1 -> Error
  12537. *
  12538. *
  12539. */
  12540. BMI160_RETURN_FUNCTION_TYPE bmi160_get_nvm_prog_enable(
  12541. u8 *v_nvm_prog_u8)
  12542. {
  12543. /* variable used for return the status of communication result*/
  12544. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12545. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  12546. /* check the p_bmi160 structure as NULL*/
  12547. if (p_bmi160 == BMI160_NULL) {
  12548. return E_BMI160_NULL_PTR;
  12549. } else {
  12550. /* read NVM program*/
  12551. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  12552. p_bmi160->dev_addr,
  12553. BMI160_USER_CONFIG_NVM_PROG_ENABLE__REG,
  12554. &v_data_u8, C_BMI160_ONE_U8X);
  12555. *v_nvm_prog_u8 = BMI160_GET_BITSLICE(v_data_u8,
  12556. BMI160_USER_CONFIG_NVM_PROG_ENABLE);
  12557. }
  12558. return com_rslt;
  12559. }
  12560. /*!
  12561. * @brief This API write NVM program enable
  12562. * from the register 0x6A bit 1
  12563. *
  12564. * @param v_nvm_prog_u8 : The value of NVM program enable
  12565. * Value | Description
  12566. * --------|-------------
  12567. * 0 | DISABLE
  12568. * 1 | ENABLE
  12569. *
  12570. * @return results of bus communication function
  12571. * @retval 0 -> Success
  12572. * @retval -1 -> Error
  12573. *
  12574. *
  12575. */
  12576. BMI160_RETURN_FUNCTION_TYPE bmi160_set_nvm_prog_enable(
  12577. u8 v_nvm_prog_u8)
  12578. {
  12579. /* variable used for return the status of communication result*/
  12580. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12581. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  12582. /* check the p_bmi160 structure as NULL*/
  12583. if (p_bmi160 == BMI160_NULL) {
  12584. return E_BMI160_NULL_PTR;
  12585. } else {
  12586. if (v_nvm_prog_u8 < C_BMI160_TWO_U8X) {
  12587. /* write the NVM program*/
  12588. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  12589. p_bmi160->dev_addr,
  12590. BMI160_USER_CONFIG_NVM_PROG_ENABLE__REG,
  12591. &v_data_u8, C_BMI160_ONE_U8X);
  12592. if (com_rslt == SUCCESS) {
  12593. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  12594. BMI160_USER_CONFIG_NVM_PROG_ENABLE,
  12595. v_nvm_prog_u8);
  12596. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  12597. p_bmi160->dev_addr,
  12598. BMI160_USER_CONFIG_NVM_PROG_ENABLE__REG,
  12599. &v_data_u8, C_BMI160_ONE_U8X);
  12600. }
  12601. } else {
  12602. com_rslt = E_BMI160_OUT_OF_RANGE;
  12603. }
  12604. }
  12605. return com_rslt;
  12606. }
  12607. /*!
  12608. * @brief This API read to configure SPI
  12609. * Interface Mode for primary and OIS interface
  12610. * from the register 0x6B bit 0
  12611. *
  12612. * @param v_spi3_u8 : The value of SPI mode selection
  12613. * Value | Description
  12614. * --------|-------------
  12615. * 0 | SPI 4-wire mode
  12616. * 1 | SPI 3-wire mode
  12617. *
  12618. *
  12619. * @return results of bus communication function
  12620. * @retval 0 -> Success
  12621. * @retval -1 -> Error
  12622. *
  12623. *
  12624. */
  12625. BMI160_RETURN_FUNCTION_TYPE bmi160_get_spi3(
  12626. u8 *v_spi3_u8)
  12627. {
  12628. /* variable used for return the status of communication result*/
  12629. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12630. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  12631. /* check the p_bmi160 structure as NULL*/
  12632. if (p_bmi160 == BMI160_NULL) {
  12633. return E_BMI160_NULL_PTR;
  12634. } else {
  12635. /* read SPI mode*/
  12636. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  12637. p_bmi160->dev_addr,
  12638. BMI160_USER_IF_CONFIG_SPI3__REG,
  12639. &v_data_u8, C_BMI160_ONE_U8X);
  12640. *v_spi3_u8 = BMI160_GET_BITSLICE(v_data_u8,
  12641. BMI160_USER_IF_CONFIG_SPI3);
  12642. }
  12643. return com_rslt;
  12644. }
  12645. /*!
  12646. * @brief This API write to configure SPI
  12647. * Interface Mode for primary and OIS interface
  12648. * from the register 0x6B bit 0
  12649. *
  12650. * @param v_spi3_u8 : The value of SPI mode selection
  12651. * Value | Description
  12652. * --------|-------------
  12653. * 0 | SPI 4-wire mode
  12654. * 1 | SPI 3-wire mode
  12655. *
  12656. *
  12657. * @return results of bus communication function
  12658. * @retval 0 -> Success
  12659. * @retval -1 -> Error
  12660. *
  12661. *
  12662. */
  12663. BMI160_RETURN_FUNCTION_TYPE bmi160_set_spi3(
  12664. u8 v_spi3_u8)
  12665. {
  12666. /* variable used for return the status of communication result*/
  12667. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12668. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  12669. /* check the p_bmi160 structure as NULL*/
  12670. if (p_bmi160 == BMI160_NULL) {
  12671. return E_BMI160_NULL_PTR;
  12672. } else {
  12673. if (v_spi3_u8 < C_BMI160_TWO_U8X) {
  12674. /* write SPI mode*/
  12675. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  12676. p_bmi160->dev_addr,
  12677. BMI160_USER_IF_CONFIG_SPI3__REG,
  12678. &v_data_u8, C_BMI160_ONE_U8X);
  12679. if (com_rslt == SUCCESS) {
  12680. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  12681. BMI160_USER_IF_CONFIG_SPI3,
  12682. v_spi3_u8);
  12683. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  12684. p_bmi160->dev_addr,
  12685. BMI160_USER_IF_CONFIG_SPI3__REG,
  12686. &v_data_u8, C_BMI160_ONE_U8X);
  12687. }
  12688. } else {
  12689. com_rslt = E_BMI160_OUT_OF_RANGE;
  12690. }
  12691. }
  12692. return com_rslt;
  12693. }
  12694. /*!
  12695. * @brief This API read I2C Watchdog timer
  12696. * from the register 0x70 bit 1
  12697. *
  12698. * @param v_i2c_wdt_u8 : The value of I2C watch dog timer
  12699. * Value | Description
  12700. * --------|-------------
  12701. * 0 | I2C watchdog v_timeout_u8 after 1 ms
  12702. * 1 | I2C watchdog v_timeout_u8 after 50 ms
  12703. *
  12704. *
  12705. * @return results of bus communication function
  12706. * @retval 0 -> Success
  12707. * @retval -1 -> Error
  12708. *
  12709. *
  12710. */
  12711. BMI160_RETURN_FUNCTION_TYPE bmi160_get_i2c_wdt_select(
  12712. u8 *v_i2c_wdt_u8)
  12713. {
  12714. /* variable used for return the status of communication result*/
  12715. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12716. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  12717. /* check the p_bmi160 structure as NULL*/
  12718. if (p_bmi160 == BMI160_NULL) {
  12719. return E_BMI160_NULL_PTR;
  12720. } else {
  12721. /* read I2C watch dog timer */
  12722. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  12723. p_bmi160->dev_addr,
  12724. BMI160_USER_IF_CONFIG_I2C_WDT_SELECT__REG,
  12725. &v_data_u8, C_BMI160_ONE_U8X);
  12726. *v_i2c_wdt_u8 = BMI160_GET_BITSLICE(v_data_u8,
  12727. BMI160_USER_IF_CONFIG_I2C_WDT_SELECT);
  12728. }
  12729. return com_rslt;
  12730. }
  12731. /*!
  12732. * @brief This API write I2C Watchdog timer
  12733. * from the register 0x70 bit 1
  12734. *
  12735. * @param v_i2c_wdt_u8 : The value of I2C watch dog timer
  12736. * Value | Description
  12737. * --------|-------------
  12738. * 0 | I2C watchdog v_timeout_u8 after 1 ms
  12739. * 1 | I2C watchdog v_timeout_u8 after 50 ms
  12740. *
  12741. *
  12742. * @return results of bus communication function
  12743. * @retval 0 -> Success
  12744. * @retval -1 -> Error
  12745. *
  12746. *
  12747. */
  12748. BMI160_RETURN_FUNCTION_TYPE bmi160_set_i2c_wdt_select(
  12749. u8 v_i2c_wdt_u8)
  12750. {
  12751. /* variable used for return the status of communication result*/
  12752. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12753. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  12754. /* check the p_bmi160 structure as NULL*/
  12755. if (p_bmi160 == BMI160_NULL) {
  12756. return E_BMI160_NULL_PTR;
  12757. } else {
  12758. if (v_i2c_wdt_u8 < C_BMI160_TWO_U8X) {
  12759. /* write I2C watch dog timer */
  12760. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  12761. p_bmi160->dev_addr,
  12762. BMI160_USER_IF_CONFIG_I2C_WDT_SELECT__REG,
  12763. &v_data_u8, C_BMI160_ONE_U8X);
  12764. if (com_rslt == SUCCESS) {
  12765. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  12766. BMI160_USER_IF_CONFIG_I2C_WDT_SELECT,
  12767. v_i2c_wdt_u8);
  12768. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  12769. p_bmi160->dev_addr,
  12770. BMI160_USER_IF_CONFIG_I2C_WDT_SELECT__REG,
  12771. &v_data_u8, C_BMI160_ONE_U8X);
  12772. }
  12773. } else {
  12774. com_rslt = E_BMI160_OUT_OF_RANGE;
  12775. }
  12776. }
  12777. return com_rslt;
  12778. }
  12779. /*!
  12780. * @brief This API read I2C watchdog enable
  12781. * from the register 0x70 bit 2
  12782. *
  12783. * @param v_i2c_wdt_u8 : The value of I2C watchdog enable
  12784. * Value | Description
  12785. * --------|-------------
  12786. * 0 | DISABLE
  12787. * 1 | ENABLE
  12788. *
  12789. * @return results of bus communication function
  12790. * @retval 0 -> Success
  12791. * @retval -1 -> Error
  12792. *
  12793. *
  12794. */
  12795. BMI160_RETURN_FUNCTION_TYPE bmi160_get_i2c_wdt_enable(
  12796. u8 *v_i2c_wdt_u8)
  12797. {
  12798. /* variable used for return the status of communication result*/
  12799. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12800. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  12801. /* check the p_bmi160 structure as NULL*/
  12802. if (p_bmi160 == BMI160_NULL) {
  12803. return E_BMI160_NULL_PTR;
  12804. } else {
  12805. /* read i2c watch dog eneble */
  12806. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  12807. p_bmi160->dev_addr,
  12808. BMI160_USER_IF_CONFIG_I2C_WDT_ENABLE__REG,
  12809. &v_data_u8, C_BMI160_ONE_U8X);
  12810. *v_i2c_wdt_u8 = BMI160_GET_BITSLICE(v_data_u8,
  12811. BMI160_USER_IF_CONFIG_I2C_WDT_ENABLE);
  12812. }
  12813. return com_rslt;
  12814. }
  12815. /*!
  12816. * @brief This API write I2C watchdog enable
  12817. * from the register 0x70 bit 2
  12818. *
  12819. * @param v_i2c_wdt_u8 : The value of I2C watchdog enable
  12820. * Value | Description
  12821. * --------|-------------
  12822. * 0 | DISABLE
  12823. * 1 | ENABLE
  12824. *
  12825. * @return results of bus communication function
  12826. * @retval 0 -> Success
  12827. * @retval -1 -> Error
  12828. *
  12829. *
  12830. */
  12831. BMI160_RETURN_FUNCTION_TYPE bmi160_set_i2c_wdt_enable(
  12832. u8 v_i2c_wdt_u8)
  12833. {
  12834. /* variable used for return the status of communication result*/
  12835. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12836. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  12837. /* check the p_bmi160 structure as NULL*/
  12838. if (p_bmi160 == BMI160_NULL) {
  12839. return E_BMI160_NULL_PTR;
  12840. } else {
  12841. if (v_i2c_wdt_u8 < C_BMI160_TWO_U8X) {
  12842. /* write i2c watch dog eneble */
  12843. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  12844. p_bmi160->dev_addr,
  12845. BMI160_USER_IF_CONFIG_I2C_WDT_ENABLE__REG,
  12846. &v_data_u8, C_BMI160_ONE_U8X);
  12847. if (com_rslt == SUCCESS) {
  12848. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  12849. BMI160_USER_IF_CONFIG_I2C_WDT_ENABLE,
  12850. v_i2c_wdt_u8);
  12851. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  12852. p_bmi160->dev_addr,
  12853. BMI160_USER_IF_CONFIG_I2C_WDT_ENABLE__REG,
  12854. &v_data_u8, C_BMI160_ONE_U8X);
  12855. }
  12856. } else {
  12857. com_rslt = E_BMI160_OUT_OF_RANGE;
  12858. }
  12859. }
  12860. return com_rslt;
  12861. }
  12862. /*!
  12863. * @brief This API read I2C interface configuration(if) moe
  12864. * from the register 0x6B bit 4 and 5
  12865. *
  12866. * @param v_if_mode_u8 : The value of interface configuration mode
  12867. * Value | Description
  12868. * --------|-------------
  12869. * 0x00 | Primary interface:autoconfig / secondary interface:off
  12870. * 0x01 | Primary interface:I2C / secondary interface:OIS
  12871. * 0x02 | Primary interface:autoconfig/secondary interface:Magnetometer
  12872. * 0x03 | Reserved
  12873. *
  12874. *
  12875. * @return results of bus communication function
  12876. * @retval 0 -> Success
  12877. * @retval -1 -> Error
  12878. *
  12879. *
  12880. */
  12881. BMI160_RETURN_FUNCTION_TYPE bmi160_get_if_mode(
  12882. u8 *v_if_mode_u8)
  12883. {
  12884. /* variable used for return the status of communication result*/
  12885. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12886. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  12887. /* check the p_bmi160 structure as NULL*/
  12888. if (p_bmi160 == BMI160_NULL) {
  12889. return E_BMI160_NULL_PTR;
  12890. } else {
  12891. /* read if mode*/
  12892. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  12893. p_bmi160->dev_addr,
  12894. BMI160_USER_IF_CONFIG_IF_MODE__REG,
  12895. &v_data_u8, C_BMI160_ONE_U8X);
  12896. *v_if_mode_u8 = BMI160_GET_BITSLICE(v_data_u8,
  12897. BMI160_USER_IF_CONFIG_IF_MODE);
  12898. }
  12899. return com_rslt;
  12900. }
  12901. /*!
  12902. * @brief This API write I2C interface configuration(if) moe
  12903. * from the register 0x6B bit 4 and 5
  12904. *
  12905. * @param v_if_mode_u8 : The value of interface configuration mode
  12906. * Value | Description
  12907. * --------|-------------
  12908. * 0x00 | Primary interface:autoconfig / secondary interface:off
  12909. * 0x01 | Primary interface:I2C / secondary interface:OIS
  12910. * 0x02 | Primary interface:autoconfig/secondary interface:Magnetometer
  12911. * 0x03 | Reserved
  12912. *
  12913. *
  12914. * @return results of bus communication function
  12915. * @retval 0 -> Success
  12916. * @retval -1 -> Error
  12917. *
  12918. *
  12919. */
  12920. BMI160_RETURN_FUNCTION_TYPE bmi160_set_if_mode(
  12921. u8 v_if_mode_u8)
  12922. {
  12923. /* variable used for return the status of communication result*/
  12924. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12925. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  12926. /* check the p_bmi160 structure as NULL*/
  12927. if (p_bmi160 == BMI160_NULL) {
  12928. return E_BMI160_NULL_PTR;
  12929. } else {
  12930. if (v_if_mode_u8 <= C_BMI160_FOUR_U8X) {
  12931. /* write if mode*/
  12932. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  12933. p_bmi160->dev_addr,
  12934. BMI160_USER_IF_CONFIG_IF_MODE__REG,
  12935. &v_data_u8, C_BMI160_ONE_U8X);
  12936. if (com_rslt == SUCCESS) {
  12937. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  12938. BMI160_USER_IF_CONFIG_IF_MODE,
  12939. v_if_mode_u8);
  12940. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  12941. p_bmi160->dev_addr,
  12942. BMI160_USER_IF_CONFIG_IF_MODE__REG,
  12943. &v_data_u8, C_BMI160_ONE_U8X);
  12944. }
  12945. } else {
  12946. com_rslt = E_BMI160_OUT_OF_RANGE;
  12947. }
  12948. }
  12949. return com_rslt;
  12950. }
  12951. /*!
  12952. * @brief This API read gyro sleep trigger
  12953. * from the register 0x6C bit 0 to 2
  12954. *
  12955. * @param v_gyro_sleep_trigger_u8 : The value of gyro sleep trigger
  12956. * Value | Description
  12957. * --------|-------------
  12958. * 0x00 | nomotion: no / Not INT1 pin: no / INT2 pin: no
  12959. * 0x01 | nomotion: no / Not INT1 pin: no / INT2 pin: yes
  12960. * 0x02 | nomotion: no / Not INT1 pin: yes / INT2 pin: no
  12961. * 0x03 | nomotion: no / Not INT1 pin: yes / INT2 pin: yes
  12962. * 0x04 | nomotion: yes / Not INT1 pin: no / INT2 pin: no
  12963. * 0x05 | anymotion: yes / Not INT1 pin: no / INT2 pin: yes
  12964. * 0x06 | anymotion: yes / Not INT1 pin: yes / INT2 pin: no
  12965. * 0x07 | anymotion: yes / Not INT1 pin: yes / INT2 pin: yes
  12966. *
  12967. *
  12968. *
  12969. * @return results of bus communication function
  12970. * @retval 0 -> Success
  12971. * @retval -1 -> Error
  12972. *
  12973. *
  12974. */
  12975. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_sleep_trigger(
  12976. u8 *v_gyro_sleep_trigger_u8)
  12977. {
  12978. /* variable used for return the status of communication result*/
  12979. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  12980. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  12981. /* check the p_bmi160 structure as NULL*/
  12982. if (p_bmi160 == BMI160_NULL) {
  12983. return E_BMI160_NULL_PTR;
  12984. } else {
  12985. /* read gyro sleep trigger */
  12986. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  12987. p_bmi160->dev_addr,
  12988. BMI160_USER_GYRO_SLEEP_TRIGGER__REG,
  12989. &v_data_u8, C_BMI160_ONE_U8X);
  12990. *v_gyro_sleep_trigger_u8 =
  12991. BMI160_GET_BITSLICE(v_data_u8,
  12992. BMI160_USER_GYRO_SLEEP_TRIGGER);
  12993. }
  12994. return com_rslt;
  12995. }
  12996. /*!
  12997. * @brief This API write gyro sleep trigger
  12998. * from the register 0x6C bit 0 to 2
  12999. *
  13000. * @param v_gyro_sleep_trigger_u8 : The value of gyro sleep trigger
  13001. * Value | Description
  13002. * --------|-------------
  13003. * 0x00 | nomotion: no / Not INT1 pin: no / INT2 pin: no
  13004. * 0x01 | nomotion: no / Not INT1 pin: no / INT2 pin: yes
  13005. * 0x02 | nomotion: no / Not INT1 pin: yes / INT2 pin: no
  13006. * 0x03 | nomotion: no / Not INT1 pin: yes / INT2 pin: yes
  13007. * 0x04 | nomotion: yes / Not INT1 pin: no / INT2 pin: no
  13008. * 0x05 | anymotion: yes / Not INT1 pin: no / INT2 pin: yes
  13009. * 0x06 | anymotion: yes / Not INT1 pin: yes / INT2 pin: no
  13010. * 0x07 | anymotion: yes / Not INT1 pin: yes / INT2 pin: yes
  13011. *
  13012. *
  13013. *
  13014. * @return results of bus communication function
  13015. * @retval 0 -> Success
  13016. * @retval -1 -> Error
  13017. *
  13018. *
  13019. */
  13020. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_sleep_trigger(
  13021. u8 v_gyro_sleep_trigger_u8)
  13022. {
  13023. /* variable used for return the status of communication result*/
  13024. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13025. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13026. /* check the p_bmi160 structure as NULL*/
  13027. if (p_bmi160 == BMI160_NULL) {
  13028. return E_BMI160_NULL_PTR;
  13029. } else {
  13030. if (v_gyro_sleep_trigger_u8 <= C_BMI160_SEVEN_U8X) {
  13031. /* write gyro sleep trigger */
  13032. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13033. p_bmi160->dev_addr,
  13034. BMI160_USER_GYRO_SLEEP_TRIGGER__REG,
  13035. &v_data_u8, C_BMI160_ONE_U8X);
  13036. if (com_rslt == SUCCESS) {
  13037. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  13038. BMI160_USER_GYRO_SLEEP_TRIGGER,
  13039. v_gyro_sleep_trigger_u8);
  13040. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  13041. p_bmi160->dev_addr,
  13042. BMI160_USER_GYRO_SLEEP_TRIGGER__REG,
  13043. &v_data_u8, C_BMI160_ONE_U8X);
  13044. }
  13045. } else {
  13046. com_rslt = E_BMI160_OUT_OF_RANGE;
  13047. }
  13048. }
  13049. return com_rslt;
  13050. }
  13051. /*!
  13052. * @brief This API read gyro wakeup trigger
  13053. * from the register 0x6C bit 3 and 4
  13054. *
  13055. * @param v_gyro_wakeup_trigger_u8 : The value of gyro wakeup trigger
  13056. * Value | Description
  13057. * --------|-------------
  13058. * 0x00 | anymotion: no / INT1 pin: no
  13059. * 0x01 | anymotion: no / INT1 pin: yes
  13060. * 0x02 | anymotion: yes / INT1 pin: no
  13061. * 0x03 | anymotion: yes / INT1 pin: yes
  13062. *
  13063. *
  13064. * @return results of bus communication function
  13065. * @retval 0 -> Success
  13066. * @retval -1 -> Error
  13067. *
  13068. *
  13069. */
  13070. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_wakeup_trigger(
  13071. u8 *v_gyro_wakeup_trigger_u8)
  13072. {
  13073. /* variable used for return the status of communication result*/
  13074. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13075. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13076. /* check the p_bmi160 structure as NULL*/
  13077. if (p_bmi160 == BMI160_NULL) {
  13078. return E_BMI160_NULL_PTR;
  13079. } else {
  13080. /* read gyro wakeup trigger */
  13081. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13082. p_bmi160->dev_addr,
  13083. BMI160_USER_GYRO_WAKEUP_TRIGGER__REG,
  13084. &v_data_u8, C_BMI160_ONE_U8X);
  13085. *v_gyro_wakeup_trigger_u8 = BMI160_GET_BITSLICE(
  13086. v_data_u8,
  13087. BMI160_USER_GYRO_WAKEUP_TRIGGER);
  13088. }
  13089. return com_rslt;
  13090. }
  13091. /*!
  13092. * @brief This API write gyro wakeup trigger
  13093. * from the register 0x6C bit 3 and 4
  13094. *
  13095. * @param v_gyro_wakeup_trigger_u8 : The value of gyro wakeup trigger
  13096. * Value | Description
  13097. * --------|-------------
  13098. * 0x00 | anymotion: no / INT1 pin: no
  13099. * 0x01 | anymotion: no / INT1 pin: yes
  13100. * 0x02 | anymotion: yes / INT1 pin: no
  13101. * 0x03 | anymotion: yes / INT1 pin: yes
  13102. *
  13103. *
  13104. * @return results of bus communication function
  13105. * @retval 0 -> Success
  13106. * @retval -1 -> Error
  13107. *
  13108. *
  13109. */
  13110. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_wakeup_trigger(
  13111. u8 v_gyro_wakeup_trigger_u8)
  13112. {
  13113. /* variable used for return the status of communication result*/
  13114. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13115. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13116. /* check the p_bmi160 structure as NULL*/
  13117. if (p_bmi160 == BMI160_NULL) {
  13118. return E_BMI160_NULL_PTR;
  13119. } else {
  13120. if (v_gyro_wakeup_trigger_u8 <= C_BMI160_THREE_U8X) {
  13121. /* write gyro wakeup trigger */
  13122. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13123. p_bmi160->dev_addr,
  13124. BMI160_USER_GYRO_WAKEUP_TRIGGER__REG,
  13125. &v_data_u8, C_BMI160_ONE_U8X);
  13126. if (com_rslt == SUCCESS) {
  13127. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  13128. BMI160_USER_GYRO_WAKEUP_TRIGGER,
  13129. v_gyro_wakeup_trigger_u8);
  13130. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  13131. p_bmi160->dev_addr,
  13132. BMI160_USER_GYRO_WAKEUP_TRIGGER__REG,
  13133. &v_data_u8, C_BMI160_ONE_U8X);
  13134. }
  13135. } else {
  13136. com_rslt = E_BMI160_OUT_OF_RANGE;
  13137. }
  13138. }
  13139. return com_rslt;
  13140. }
  13141. /*!
  13142. * @brief This API read Target state for gyro sleep mode
  13143. * from the register 0x6C bit 5
  13144. *
  13145. * @param v_gyro_sleep_state_u8 : The value of gyro sleep mode
  13146. * Value | Description
  13147. * --------|-------------
  13148. * 0x00 | Sleep transition to fast wake up state
  13149. * 0x01 | Sleep transition to suspend state
  13150. *
  13151. *
  13152. * @return results of bus communication function
  13153. * @retval 0 -> Success
  13154. * @retval -1 -> Error
  13155. *
  13156. *
  13157. */
  13158. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_sleep_state(
  13159. u8 *v_gyro_sleep_state_u8)
  13160. {
  13161. /* variable used for return the status of communication result*/
  13162. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13163. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13164. /* check the p_bmi160 structure as NULL*/
  13165. if (p_bmi160 == BMI160_NULL) {
  13166. return E_BMI160_NULL_PTR;
  13167. } else {
  13168. /* read gyro sleep state*/
  13169. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13170. p_bmi160->dev_addr,
  13171. BMI160_USER_GYRO_SLEEP_STATE__REG,
  13172. &v_data_u8, C_BMI160_ONE_U8X);
  13173. *v_gyro_sleep_state_u8 = BMI160_GET_BITSLICE(
  13174. v_data_u8,
  13175. BMI160_USER_GYRO_SLEEP_STATE);
  13176. }
  13177. return com_rslt;
  13178. }
  13179. /*!
  13180. * @brief This API write Target state for gyro sleep mode
  13181. * from the register 0x6C bit 5
  13182. *
  13183. * @param v_gyro_sleep_state_u8 : The value of gyro sleep mode
  13184. * Value | Description
  13185. * --------|-------------
  13186. * 0x00 | Sleep transition to fast wake up state
  13187. * 0x01 | Sleep transition to suspend state
  13188. *
  13189. *
  13190. * @return results of bus communication function
  13191. * @retval 0 -> Success
  13192. * @retval -1 -> Error
  13193. *
  13194. *
  13195. */
  13196. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_sleep_state(
  13197. u8 v_gyro_sleep_state_u8)
  13198. {
  13199. /* variable used for return the status of communication result*/
  13200. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13201. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13202. /* check the p_bmi160 structure as NULL*/
  13203. if (p_bmi160 == BMI160_NULL) {
  13204. return E_BMI160_NULL_PTR;
  13205. } else {
  13206. if (v_gyro_sleep_state_u8 < C_BMI160_TWO_U8X) {
  13207. /* write gyro sleep state*/
  13208. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13209. p_bmi160->dev_addr,
  13210. BMI160_USER_GYRO_SLEEP_STATE__REG,
  13211. &v_data_u8, C_BMI160_ONE_U8X);
  13212. if (com_rslt == SUCCESS) {
  13213. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  13214. BMI160_USER_GYRO_SLEEP_STATE,
  13215. v_gyro_sleep_state_u8);
  13216. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  13217. p_bmi160->dev_addr,
  13218. BMI160_USER_GYRO_SLEEP_STATE__REG,
  13219. &v_data_u8, C_BMI160_ONE_U8X);
  13220. }
  13221. } else {
  13222. com_rslt = E_BMI160_OUT_OF_RANGE;
  13223. }
  13224. }
  13225. return com_rslt;
  13226. }
  13227. /*!
  13228. * @brief This API read gyro wakeup interrupt
  13229. * from the register 0x6C bit 6
  13230. *
  13231. * @param v_gyro_wakeup_intr_u8 : The valeu of gyro wakeup interrupt
  13232. * Value | Description
  13233. * --------|-------------
  13234. * 0x00 | DISABLE
  13235. * 0x01 | ENABLE
  13236. *
  13237. *
  13238. * @return results of bus communication function
  13239. * @retval 0 -> Success
  13240. * @retval -1 -> Error
  13241. *
  13242. *
  13243. */
  13244. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_wakeup_intr(
  13245. u8 *v_gyro_wakeup_intr_u8)
  13246. {
  13247. /* variable used for return the status of communication result*/
  13248. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13249. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13250. /* check the p_bmi160 structure as NULL*/
  13251. if (p_bmi160 == BMI160_NULL) {
  13252. return E_BMI160_NULL_PTR;
  13253. } else {
  13254. /* read gyro wakeup interrupt */
  13255. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13256. p_bmi160->dev_addr,
  13257. BMI160_USER_GYRO_WAKEUP_INTR__REG,
  13258. &v_data_u8, C_BMI160_ONE_U8X);
  13259. *v_gyro_wakeup_intr_u8 = BMI160_GET_BITSLICE(
  13260. v_data_u8,
  13261. BMI160_USER_GYRO_WAKEUP_INTR);
  13262. }
  13263. return com_rslt;
  13264. }
  13265. /*!
  13266. * @brief This API write gyro wakeup interrupt
  13267. * from the register 0x6C bit 6
  13268. *
  13269. * @param v_gyro_wakeup_intr_u8 : The valeu of gyro wakeup interrupt
  13270. * Value | Description
  13271. * --------|-------------
  13272. * 0x00 | DISABLE
  13273. * 0x01 | ENABLE
  13274. *
  13275. *
  13276. * @return results of bus communication function
  13277. * @retval 0 -> Success
  13278. * @retval -1 -> Error
  13279. *
  13280. *
  13281. */
  13282. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_wakeup_intr(
  13283. u8 v_gyro_wakeup_intr_u8)
  13284. {
  13285. /* variable used for return the status of communication result*/
  13286. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13287. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13288. /* check the p_bmi160 structure as NULL*/
  13289. if (p_bmi160 == BMI160_NULL) {
  13290. return E_BMI160_NULL_PTR;
  13291. } else {
  13292. if (v_gyro_wakeup_intr_u8 < C_BMI160_TWO_U8X) {
  13293. /* write gyro wakeup interrupt */
  13294. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13295. p_bmi160->dev_addr,
  13296. BMI160_USER_GYRO_WAKEUP_INTR__REG,
  13297. &v_data_u8, C_BMI160_ONE_U8X);
  13298. if (com_rslt == SUCCESS) {
  13299. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  13300. BMI160_USER_GYRO_WAKEUP_INTR,
  13301. v_gyro_wakeup_intr_u8);
  13302. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  13303. p_bmi160->dev_addr,
  13304. BMI160_USER_GYRO_WAKEUP_INTR__REG,
  13305. &v_data_u8, C_BMI160_ONE_U8X);
  13306. }
  13307. } else {
  13308. com_rslt = E_BMI160_OUT_OF_RANGE;
  13309. }
  13310. }
  13311. return com_rslt;
  13312. }
  13313. /*!
  13314. * @brief This API read accel select axis to be self-test
  13315. *
  13316. * @param v_accel_selftest_axis_u8 :
  13317. * The value of accel self test axis selection
  13318. * Value | Description
  13319. * --------|-------------
  13320. * 0x00 | disabled
  13321. * 0x01 | x-axis
  13322. * 0x02 | y-axis
  13323. * 0x03 | z-axis
  13324. *
  13325. *
  13326. * @return results of bus communication function
  13327. * @retval 0 -> Success
  13328. * @retval -1 -> Error
  13329. *
  13330. *
  13331. */
  13332. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_selftest_axis(
  13333. u8 *v_accel_selftest_axis_u8)
  13334. {
  13335. /* variable used for return the status of communication result*/
  13336. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13337. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13338. /* check the p_bmi160 structure as NULL*/
  13339. if (p_bmi160 == BMI160_NULL) {
  13340. return E_BMI160_NULL_PTR;
  13341. } else {
  13342. /* read accel self test axis*/
  13343. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13344. p_bmi160->dev_addr,
  13345. BMI160_USER_ACCEL_SELFTEST_AXIS__REG,
  13346. &v_data_u8, C_BMI160_ONE_U8X);
  13347. *v_accel_selftest_axis_u8 = BMI160_GET_BITSLICE(
  13348. v_data_u8,
  13349. BMI160_USER_ACCEL_SELFTEST_AXIS);
  13350. }
  13351. return com_rslt;
  13352. }
  13353. /*!
  13354. * @brief This API write accel select axis to be self-test
  13355. *
  13356. * @param v_accel_selftest_axis_u8 :
  13357. * The value of accel self test axis selection
  13358. * Value | Description
  13359. * --------|-------------
  13360. * 0x00 | disabled
  13361. * 0x01 | x-axis
  13362. * 0x02 | y-axis
  13363. * 0x03 | z-axis
  13364. *
  13365. *
  13366. * @return results of bus communication function
  13367. * @retval 0 -> Success
  13368. * @retval -1 -> Error
  13369. *
  13370. *
  13371. */
  13372. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_selftest_axis(
  13373. u8 v_accel_selftest_axis_u8)
  13374. {
  13375. /* variable used for return the status of communication result*/
  13376. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13377. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13378. /* check the p_bmi160 structure as NULL*/
  13379. if (p_bmi160 == BMI160_NULL) {
  13380. return E_BMI160_NULL_PTR;
  13381. } else {
  13382. if (v_accel_selftest_axis_u8 <= C_BMI160_THREE_U8X) {
  13383. /* write accel self test axis*/
  13384. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13385. p_bmi160->dev_addr,
  13386. BMI160_USER_ACCEL_SELFTEST_AXIS__REG,
  13387. &v_data_u8, C_BMI160_ONE_U8X);
  13388. if (com_rslt == SUCCESS) {
  13389. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  13390. BMI160_USER_ACCEL_SELFTEST_AXIS,
  13391. v_accel_selftest_axis_u8);
  13392. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  13393. p_bmi160->dev_addr,
  13394. BMI160_USER_ACCEL_SELFTEST_AXIS__REG,
  13395. &v_data_u8, C_BMI160_ONE_U8X);
  13396. }
  13397. } else {
  13398. com_rslt = E_BMI160_OUT_OF_RANGE;
  13399. }
  13400. }
  13401. return com_rslt;
  13402. }
  13403. /*!
  13404. * @brief This API read accel self test axis sign
  13405. * from the register 0x6D bit 2
  13406. *
  13407. * @param v_accel_selftest_sign_u8: The value of accel self test axis sign
  13408. * Value | Description
  13409. * --------|-------------
  13410. * 0x00 | negative
  13411. * 0x01 | positive
  13412. *
  13413. *
  13414. * @return results of bus communication function
  13415. * @retval 0 -> Success
  13416. * @retval -1 -> Error
  13417. *
  13418. *
  13419. */
  13420. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_selftest_sign(
  13421. u8 *v_accel_selftest_sign_u8)
  13422. {
  13423. /* variable used for return the status of communication result*/
  13424. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13425. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13426. /* check the p_bmi160 structure as NULL*/
  13427. if (p_bmi160 == BMI160_NULL) {
  13428. return E_BMI160_NULL_PTR;
  13429. } else {
  13430. /* read accel self test axis sign*/
  13431. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13432. p_bmi160->dev_addr,
  13433. BMI160_USER_ACCEL_SELFTEST_SIGN__REG,
  13434. &v_data_u8, C_BMI160_ONE_U8X);
  13435. *v_accel_selftest_sign_u8 = BMI160_GET_BITSLICE(
  13436. v_data_u8,
  13437. BMI160_USER_ACCEL_SELFTEST_SIGN);
  13438. }
  13439. return com_rslt;
  13440. }
  13441. /*!
  13442. * @brief This API write accel self test axis sign
  13443. * from the register 0x6D bit 2
  13444. *
  13445. * @param v_accel_selftest_sign_u8: The value of accel self test axis sign
  13446. * Value | Description
  13447. * --------|-------------
  13448. * 0x00 | negative
  13449. * 0x01 | positive
  13450. *
  13451. *
  13452. * @return results of bus communication function
  13453. * @retval 0 -> Success
  13454. * @retval -1 -> Error
  13455. *
  13456. *
  13457. */
  13458. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_selftest_sign(
  13459. u8 v_accel_selftest_sign_u8)
  13460. {
  13461. /* variable used for return the status of communication result*/
  13462. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13463. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13464. /* check the p_bmi160 structure as NULL*/
  13465. if (p_bmi160 == BMI160_NULL) {
  13466. return E_BMI160_NULL_PTR;
  13467. } else {
  13468. if (v_accel_selftest_sign_u8 < C_BMI160_TWO_U8X) {
  13469. /* write accel self test axis sign*/
  13470. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13471. p_bmi160->dev_addr,
  13472. BMI160_USER_ACCEL_SELFTEST_SIGN__REG,
  13473. &v_data_u8, C_BMI160_ONE_U8X);
  13474. if (com_rslt == SUCCESS) {
  13475. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  13476. BMI160_USER_ACCEL_SELFTEST_SIGN,
  13477. v_accel_selftest_sign_u8);
  13478. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  13479. p_bmi160->dev_addr,
  13480. BMI160_USER_ACCEL_SELFTEST_SIGN__REG,
  13481. &v_data_u8, C_BMI160_ONE_U8X);
  13482. }
  13483. } else {
  13484. com_rslt = E_BMI160_OUT_OF_RANGE;
  13485. }
  13486. }
  13487. return com_rslt;
  13488. }
  13489. /*!
  13490. * @brief This API read accel self test amplitude
  13491. * from the register 0x6D bit 3
  13492. * select amplitude of the selftest deflection:
  13493. *
  13494. * @param v_accel_selftest_amp_u8 : The value of accel self test amplitude
  13495. * Value | Description
  13496. * --------|-------------
  13497. * 0x00 | LOW
  13498. * 0x01 | HIGH
  13499. *
  13500. *
  13501. * @return results of bus communication function
  13502. * @retval 0 -> Success
  13503. * @retval -1 -> Error
  13504. *
  13505. *
  13506. */
  13507. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_selftest_amp(
  13508. u8 *v_accel_selftest_amp_u8)
  13509. {
  13510. /* variable used for return the status of communication result*/
  13511. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13512. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13513. /* check the p_bmi160 structure as NULL*/
  13514. if (p_bmi160 == BMI160_NULL) {
  13515. return E_BMI160_NULL_PTR;
  13516. } else {
  13517. /* read self test amplitude*/
  13518. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13519. p_bmi160->dev_addr,
  13520. BMI160_USER_SELFTEST_AMP__REG,
  13521. &v_data_u8, C_BMI160_ONE_U8X);
  13522. *v_accel_selftest_amp_u8 = BMI160_GET_BITSLICE(
  13523. v_data_u8,
  13524. BMI160_USER_SELFTEST_AMP);
  13525. }
  13526. return com_rslt;
  13527. }
  13528. /*!
  13529. * @brief This API write accel self test amplitude
  13530. * from the register 0x6D bit 3
  13531. * select amplitude of the selftest deflection:
  13532. *
  13533. * @param v_accel_selftest_amp_u8 : The value of accel self test amplitude
  13534. * Value | Description
  13535. * --------|-------------
  13536. * 0x00 | LOW
  13537. * 0x01 | HIGH
  13538. *
  13539. *
  13540. * @return results of bus communication function
  13541. * @retval 0 -> Success
  13542. * @retval -1 -> Error
  13543. *
  13544. *
  13545. */
  13546. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_selftest_amp(
  13547. u8 v_accel_selftest_amp_u8)
  13548. {
  13549. /* variable used for return the status of communication result*/
  13550. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13551. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13552. /* check the p_bmi160 structure as NULL*/
  13553. if (p_bmi160 == BMI160_NULL) {
  13554. return E_BMI160_NULL_PTR;
  13555. } else {
  13556. if (v_accel_selftest_amp_u8 < C_BMI160_TWO_U8X) {
  13557. /* write self test amplitude*/
  13558. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13559. p_bmi160->dev_addr,
  13560. BMI160_USER_SELFTEST_AMP__REG,
  13561. &v_data_u8, C_BMI160_ONE_U8X);
  13562. if (com_rslt == SUCCESS) {
  13563. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  13564. BMI160_USER_SELFTEST_AMP,
  13565. v_accel_selftest_amp_u8);
  13566. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  13567. p_bmi160->dev_addr,
  13568. BMI160_USER_SELFTEST_AMP__REG,
  13569. &v_data_u8, C_BMI160_ONE_U8X);
  13570. }
  13571. } else {
  13572. com_rslt = E_BMI160_OUT_OF_RANGE;
  13573. }
  13574. }
  13575. return com_rslt;
  13576. }
  13577. /*!
  13578. * @brief This API read gyro self test trigger
  13579. *
  13580. * @param v_gyro_selftest_start_u8: The value of gyro self test start
  13581. *
  13582. * @return results of bus communication function
  13583. * @retval 0 -> Success
  13584. * @retval -1 -> Error
  13585. *
  13586. *
  13587. */
  13588. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_selftest_start(
  13589. u8 *v_gyro_selftest_start_u8)
  13590. {
  13591. /* variable used for return the status of communication result*/
  13592. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13593. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13594. /* check the p_bmi160 structure as NULL*/
  13595. if (p_bmi160 == BMI160_NULL) {
  13596. return E_BMI160_NULL_PTR;
  13597. } else {
  13598. /* read gyro self test start */
  13599. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13600. p_bmi160->dev_addr,
  13601. BMI160_USER_GYRO_SELFTEST_START__REG,
  13602. &v_data_u8, C_BMI160_ONE_U8X);
  13603. *v_gyro_selftest_start_u8 = BMI160_GET_BITSLICE(
  13604. v_data_u8,
  13605. BMI160_USER_GYRO_SELFTEST_START);
  13606. }
  13607. return com_rslt;
  13608. }
  13609. /*!
  13610. * @brief This API write gyro self test trigger
  13611. *
  13612. * @param v_gyro_selftest_start_u8: The value of gyro self test start
  13613. *
  13614. * @return results of bus communication function
  13615. * @retval 0 -> Success
  13616. * @retval -1 -> Error
  13617. *
  13618. *
  13619. */
  13620. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_selftest_start(
  13621. u8 v_gyro_selftest_start_u8)
  13622. {
  13623. /* variable used for return the status of communication result*/
  13624. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13625. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13626. /* check the p_bmi160 structure as NULL*/
  13627. if (p_bmi160 == BMI160_NULL) {
  13628. return E_BMI160_NULL_PTR;
  13629. } else {
  13630. if (v_gyro_selftest_start_u8 < C_BMI160_TWO_U8X) {
  13631. /* write gyro self test start */
  13632. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13633. p_bmi160->dev_addr,
  13634. BMI160_USER_GYRO_SELFTEST_START__REG,
  13635. &v_data_u8, C_BMI160_ONE_U8X);
  13636. if (com_rslt == SUCCESS) {
  13637. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  13638. BMI160_USER_GYRO_SELFTEST_START,
  13639. v_gyro_selftest_start_u8);
  13640. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  13641. p_bmi160->dev_addr,
  13642. BMI160_USER_GYRO_SELFTEST_START__REG,
  13643. &v_data_u8, C_BMI160_ONE_U8X);
  13644. }
  13645. } else {
  13646. com_rslt = E_BMI160_OUT_OF_RANGE;
  13647. }
  13648. }
  13649. return com_rslt;
  13650. }
  13651. /*!
  13652. * @brief This API read primary interface selection I2C or SPI
  13653. * from the register 0x70 bit 0
  13654. *
  13655. * @param v_spi_enable_u8: The value of Interface selection
  13656. * Value | Description
  13657. * --------|-------------
  13658. * 0x00 | I2C Enable
  13659. * 0x01 | I2C DISBALE
  13660. *
  13661. *
  13662. * @return results of bus communication function
  13663. * @retval 0 -> Success
  13664. * @retval -1 -> Error
  13665. *
  13666. *
  13667. */
  13668. BMI160_RETURN_FUNCTION_TYPE bmi160_get_spi_enable(u8 *v_spi_enable_u8)
  13669. {
  13670. /* variable used for return the status of communication result*/
  13671. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13672. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13673. /* check the p_bmi160 structure as NULL*/
  13674. if (p_bmi160 == BMI160_NULL) {
  13675. return E_BMI160_NULL_PTR;
  13676. } else {
  13677. /* read interface section*/
  13678. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13679. p_bmi160->dev_addr,
  13680. BMI160_USER_NV_CONFIG_SPI_ENABLE__REG,
  13681. &v_data_u8, C_BMI160_ONE_U8X);
  13682. *v_spi_enable_u8 = BMI160_GET_BITSLICE(v_data_u8,
  13683. BMI160_USER_NV_CONFIG_SPI_ENABLE);
  13684. }
  13685. return com_rslt;
  13686. }
  13687. /*!
  13688. * @brief This API write primary interface selection I2C or SPI
  13689. * from the register 0x70 bit 0
  13690. *
  13691. * @param v_spi_enable_u8: The value of Interface selection
  13692. * Value | Description
  13693. * --------|-------------
  13694. * 0x00 | I2C Enable
  13695. * 0x01 | I2C DISBALE
  13696. *
  13697. *
  13698. * @return results of bus communication function
  13699. * @retval 0 -> Success
  13700. * @retval -1 -> Error
  13701. *
  13702. *
  13703. */
  13704. BMI160_RETURN_FUNCTION_TYPE bmi160_set_spi_enable(u8 v_spi_enable_u8)
  13705. {
  13706. /* variable used for return the status of communication result*/
  13707. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13708. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13709. /* check the p_bmi160 structure as NULL*/
  13710. if (p_bmi160 == BMI160_NULL) {
  13711. return E_BMI160_NULL_PTR;
  13712. } else {
  13713. /* write interface section*/
  13714. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13715. p_bmi160->dev_addr,
  13716. BMI160_USER_NV_CONFIG_SPI_ENABLE__REG,
  13717. &v_data_u8, C_BMI160_ONE_U8X);
  13718. if (com_rslt == SUCCESS) {
  13719. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  13720. BMI160_USER_NV_CONFIG_SPI_ENABLE,
  13721. v_spi_enable_u8);
  13722. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC
  13723. (p_bmi160->dev_addr,
  13724. BMI160_USER_NV_CONFIG_SPI_ENABLE__REG,
  13725. &v_data_u8, C_BMI160_ONE_U8X);
  13726. }
  13727. }
  13728. return com_rslt;
  13729. }
  13730. /*!
  13731. * @brief This API read the spare zero
  13732. * form register 0x70 bit 3
  13733. *
  13734. *
  13735. * @param v_spare0_trim_u8: The value of spare zero
  13736. *
  13737. *
  13738. *
  13739. * @return results of bus communication function
  13740. * @retval 0 -> Success
  13741. * @retval -1 -> Error
  13742. *
  13743. *
  13744. */
  13745. BMI160_RETURN_FUNCTION_TYPE bmi160_get_spare0_trim(u8 *v_spare0_trim_u8)
  13746. {
  13747. /* variable used for return the status of communication result*/
  13748. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13749. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13750. /* check the p_bmi160 structure as NULL*/
  13751. if (p_bmi160 == BMI160_NULL) {
  13752. return E_BMI160_NULL_PTR;
  13753. } else {
  13754. /* read spare zero*/
  13755. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13756. p_bmi160->dev_addr,
  13757. BMI160_USER_NV_CONFIG_SPARE0__REG,
  13758. &v_data_u8, C_BMI160_ONE_U8X);
  13759. *v_spare0_trim_u8 = BMI160_GET_BITSLICE(v_data_u8,
  13760. BMI160_USER_NV_CONFIG_SPARE0);
  13761. }
  13762. return com_rslt;
  13763. }
  13764. /*!
  13765. * @brief This API write the spare zero
  13766. * form register 0x70 bit 3
  13767. *
  13768. *
  13769. * @param v_spare0_trim_u8: The value of spare zero
  13770. *
  13771. *
  13772. *
  13773. * @return results of bus communication function
  13774. * @retval 0 -> Success
  13775. * @retval -1 -> Error
  13776. *
  13777. *
  13778. */
  13779. BMI160_RETURN_FUNCTION_TYPE bmi160_set_spare0_trim(u8 v_spare0_trim_u8)
  13780. {
  13781. /* variable used for return the status of communication result*/
  13782. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13783. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13784. /* check the p_bmi160 structure as NULL*/
  13785. if (p_bmi160 == BMI160_NULL) {
  13786. return E_BMI160_NULL_PTR;
  13787. } else {
  13788. /* write spare zero*/
  13789. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13790. p_bmi160->dev_addr,
  13791. BMI160_USER_NV_CONFIG_SPARE0__REG,
  13792. &v_data_u8, C_BMI160_ONE_U8X);
  13793. if (com_rslt == SUCCESS) {
  13794. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  13795. BMI160_USER_NV_CONFIG_SPARE0,
  13796. v_spare0_trim_u8);
  13797. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  13798. p_bmi160->dev_addr,
  13799. BMI160_USER_NV_CONFIG_SPARE0__REG,
  13800. &v_data_u8, C_BMI160_ONE_U8X);
  13801. }
  13802. }
  13803. return com_rslt;
  13804. }
  13805. /*!
  13806. * @brief This API read the NVM counter
  13807. * form register 0x70 bit 4 to 7
  13808. *
  13809. *
  13810. * @param v_nvm_counter_u8: The value of NVM counter
  13811. *
  13812. *
  13813. *
  13814. * @return results of bus communication function
  13815. * @retval 0 -> Success
  13816. * @retval -1 -> Error
  13817. *
  13818. *
  13819. */
  13820. BMI160_RETURN_FUNCTION_TYPE bmi160_get_nvm_counter(u8 *v_nvm_counter_u8)
  13821. {
  13822. /* variable used for return the status of communication result*/
  13823. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13824. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13825. /* check the p_bmi160 structure as NULL*/
  13826. if (p_bmi160 == BMI160_NULL) {
  13827. return E_BMI160_NULL_PTR;
  13828. } else {
  13829. /* read NVM counter*/
  13830. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13831. p_bmi160->dev_addr,
  13832. BMI160_USER_NV_CONFIG_NVM_COUNTER__REG,
  13833. &v_data_u8, C_BMI160_ONE_U8X);
  13834. *v_nvm_counter_u8 = BMI160_GET_BITSLICE(v_data_u8,
  13835. BMI160_USER_NV_CONFIG_NVM_COUNTER);
  13836. }
  13837. return com_rslt;
  13838. }
  13839. /*!
  13840. * @brief This API write the NVM counter
  13841. * form register 0x70 bit 4 to 7
  13842. *
  13843. *
  13844. * @param v_nvm_counter_u8: The value of NVM counter
  13845. *
  13846. *
  13847. *
  13848. * @return results of bus communication function
  13849. * @retval 0 -> Success
  13850. * @retval -1 -> Error
  13851. *
  13852. *
  13853. */
  13854. BMI160_RETURN_FUNCTION_TYPE bmi160_set_nvm_counter(
  13855. u8 v_nvm_counter_u8)
  13856. {
  13857. /* variable used for return the status of communication result*/
  13858. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13859. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13860. /* check the p_bmi160 structure as NULL*/
  13861. if (p_bmi160 == BMI160_NULL) {
  13862. return E_BMI160_NULL_PTR;
  13863. } else {
  13864. /* write NVM counter*/
  13865. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13866. p_bmi160->dev_addr,
  13867. BMI160_USER_NV_CONFIG_NVM_COUNTER__REG,
  13868. &v_data_u8, C_BMI160_ONE_U8X);
  13869. if (com_rslt == SUCCESS) {
  13870. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  13871. BMI160_USER_NV_CONFIG_NVM_COUNTER,
  13872. v_nvm_counter_u8);
  13873. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  13874. p_bmi160->dev_addr,
  13875. BMI160_USER_NV_CONFIG_NVM_COUNTER__REG,
  13876. &v_data_u8, C_BMI160_ONE_U8X);
  13877. }
  13878. }
  13879. return com_rslt;
  13880. }
  13881. /*!
  13882. * @brief This API read accel manual offset compensation of x axis
  13883. * from the register 0x71 bit 0 to 7
  13884. *
  13885. *
  13886. *
  13887. * @param v_accel_off_x_s8:
  13888. * The value of accel manual offset compensation of x axis
  13889. *
  13890. *
  13891. *
  13892. * @return results of bus communication function
  13893. * @retval 0 -> Success
  13894. * @retval -1 -> Error
  13895. *
  13896. *
  13897. */
  13898. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_offset_compensation_xaxis(
  13899. s8 *v_accel_off_x_s8)
  13900. {
  13901. /* variable used for return the status of communication result*/
  13902. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13903. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13904. /* check the p_bmi160 structure as NULL*/
  13905. if (p_bmi160 == BMI160_NULL) {
  13906. return E_BMI160_NULL_PTR;
  13907. } else {
  13908. /* read accel manual offset compensation of x axis*/
  13909. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  13910. p_bmi160->dev_addr,
  13911. BMI160_USER_OFFSET_0_ACCEL_OFF_X__REG,
  13912. &v_data_u8, C_BMI160_ONE_U8X);
  13913. *v_accel_off_x_s8 = BMI160_GET_BITSLICE(v_data_u8,
  13914. BMI160_USER_OFFSET_0_ACCEL_OFF_X);
  13915. }
  13916. return com_rslt;
  13917. }
  13918. /*!
  13919. * @brief This API write accel manual offset compensation of x axis
  13920. * from the register 0x71 bit 0 to 7
  13921. *
  13922. *
  13923. *
  13924. * @param v_accel_off_x_s8:
  13925. * The value of accel manual offset compensation of x axis
  13926. *
  13927. *
  13928. *
  13929. * @return results of bus communication function
  13930. * @retval 0 -> Success
  13931. * @retval -1 -> Error
  13932. *
  13933. *
  13934. */
  13935. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_offset_compensation_xaxis(
  13936. s8 v_accel_off_x_s8)
  13937. {
  13938. /* variable used for return the status of communication result*/
  13939. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13940. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13941. u8 v_status_s8 = SUCCESS;
  13942. /* check the p_bmi160 structure as NULL*/
  13943. if (p_bmi160 == BMI160_NULL) {
  13944. return E_BMI160_NULL_PTR;
  13945. } else {
  13946. /* enable accel offset */
  13947. v_status_s8 = bmi160_set_accel_offset_enable(
  13948. ACCEL_OFFSET_ENABLE);
  13949. if (v_status_s8 == SUCCESS) {
  13950. /* write accel manual offset compensation of x axis*/
  13951. com_rslt =
  13952. p_bmi160->BMI160_BUS_READ_FUNC(
  13953. p_bmi160->dev_addr,
  13954. BMI160_USER_OFFSET_0_ACCEL_OFF_X__REG,
  13955. &v_data_u8, C_BMI160_ONE_U8X);
  13956. if (com_rslt == SUCCESS) {
  13957. v_data_u8 =
  13958. BMI160_SET_BITSLICE(
  13959. v_data_u8,
  13960. BMI160_USER_OFFSET_0_ACCEL_OFF_X,
  13961. v_accel_off_x_s8);
  13962. com_rslt +=
  13963. p_bmi160->BMI160_BUS_WRITE_FUNC(
  13964. p_bmi160->dev_addr,
  13965. BMI160_USER_OFFSET_0_ACCEL_OFF_X__REG,
  13966. &v_data_u8, C_BMI160_ONE_U8X);
  13967. }
  13968. } else {
  13969. com_rslt = ERROR;
  13970. }
  13971. }
  13972. return com_rslt;
  13973. }
  13974. /*!
  13975. * @brief This API read accel manual offset compensation of y axis
  13976. * from the register 0x72 bit 0 to 7
  13977. *
  13978. *
  13979. *
  13980. * @param v_accel_off_y_s8:
  13981. * The value of accel manual offset compensation of y axis
  13982. *
  13983. *
  13984. *
  13985. * @return results of bus communication function
  13986. * @retval 0 -> Success
  13987. * @retval -1 -> Error
  13988. *
  13989. *
  13990. */
  13991. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_offset_compensation_yaxis(
  13992. s8 *v_accel_off_y_s8)
  13993. {
  13994. /* variable used for return the status of communication result*/
  13995. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  13996. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  13997. /* check the p_bmi160 structure as NULL*/
  13998. if (p_bmi160 == BMI160_NULL) {
  13999. return E_BMI160_NULL_PTR;
  14000. } else {
  14001. /* read accel manual offset compensation of y axis*/
  14002. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14003. p_bmi160->dev_addr,
  14004. BMI160_USER_OFFSET_1_ACCEL_OFF_Y__REG,
  14005. &v_data_u8, C_BMI160_ONE_U8X);
  14006. *v_accel_off_y_s8 = BMI160_GET_BITSLICE(v_data_u8,
  14007. BMI160_USER_OFFSET_1_ACCEL_OFF_Y);
  14008. }
  14009. return com_rslt;
  14010. }
  14011. /*!
  14012. * @brief This API write accel manual offset compensation of y axis
  14013. * from the register 0x72 bit 0 to 7
  14014. *
  14015. *
  14016. *
  14017. * @param v_accel_off_y_s8:
  14018. * The value of accel manual offset compensation of y axis
  14019. *
  14020. *
  14021. *
  14022. * @return results of bus communication function
  14023. * @retval 0 -> Success
  14024. * @retval -1 -> Error
  14025. *
  14026. *
  14027. */
  14028. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_offset_compensation_yaxis(
  14029. s8 v_accel_off_y_s8)
  14030. {
  14031. /* variable used for return the status of communication result*/
  14032. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14033. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  14034. u8 v_status_s8 = SUCCESS;
  14035. /* check the p_bmi160 structure as NULL*/
  14036. if (p_bmi160 == BMI160_NULL) {
  14037. return E_BMI160_NULL_PTR;
  14038. } else {
  14039. /* enable accel offset */
  14040. v_status_s8 = bmi160_set_accel_offset_enable(
  14041. ACCEL_OFFSET_ENABLE);
  14042. if (v_status_s8 == SUCCESS) {
  14043. /* write accel manual offset compensation of y axis*/
  14044. com_rslt =
  14045. p_bmi160->BMI160_BUS_READ_FUNC(
  14046. p_bmi160->dev_addr,
  14047. BMI160_USER_OFFSET_1_ACCEL_OFF_Y__REG,
  14048. &v_data_u8, C_BMI160_ONE_U8X);
  14049. if (com_rslt == SUCCESS) {
  14050. v_data_u8 =
  14051. BMI160_SET_BITSLICE(
  14052. v_data_u8,
  14053. BMI160_USER_OFFSET_1_ACCEL_OFF_Y,
  14054. v_accel_off_y_s8);
  14055. com_rslt +=
  14056. p_bmi160->BMI160_BUS_WRITE_FUNC(
  14057. p_bmi160->dev_addr,
  14058. BMI160_USER_OFFSET_1_ACCEL_OFF_Y__REG,
  14059. &v_data_u8, C_BMI160_ONE_U8X);
  14060. }
  14061. } else {
  14062. com_rslt = ERROR;
  14063. }
  14064. }
  14065. return com_rslt;
  14066. }
  14067. /*!
  14068. * @brief This API read accel manual offset compensation of z axis
  14069. * from the register 0x73 bit 0 to 7
  14070. *
  14071. *
  14072. *
  14073. * @param v_accel_off_z_s8:
  14074. * The value of accel manual offset compensation of z axis
  14075. *
  14076. *
  14077. *
  14078. * @return results of bus communication function
  14079. * @retval 0 -> Success
  14080. * @retval -1 -> Error
  14081. *
  14082. *
  14083. */
  14084. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_offset_compensation_zaxis(
  14085. s8 *v_accel_off_z_s8)
  14086. {
  14087. /* variable used for return the status of communication result*/
  14088. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14089. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  14090. /* check the p_bmi160 structure as NULL*/
  14091. if (p_bmi160 == BMI160_NULL) {
  14092. return E_BMI160_NULL_PTR;
  14093. } else {
  14094. /* read accel manual offset compensation of z axis*/
  14095. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14096. p_bmi160->dev_addr,
  14097. BMI160_USER_OFFSET_2_ACCEL_OFF_Z__REG,
  14098. &v_data_u8, C_BMI160_ONE_U8X);
  14099. *v_accel_off_z_s8 = BMI160_GET_BITSLICE(v_data_u8,
  14100. BMI160_USER_OFFSET_2_ACCEL_OFF_Z);
  14101. }
  14102. return com_rslt;
  14103. }
  14104. /*!
  14105. * @brief This API write accel manual offset compensation of z axis
  14106. * from the register 0x73 bit 0 to 7
  14107. *
  14108. *
  14109. *
  14110. * @param v_accel_off_z_s8:
  14111. * The value of accel manual offset compensation of z axis
  14112. *
  14113. *
  14114. *
  14115. * @return results of bus communication function
  14116. * @retval 0 -> Success
  14117. * @retval -1 -> Error
  14118. *
  14119. *
  14120. */
  14121. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_offset_compensation_zaxis(
  14122. s8 v_accel_off_z_s8)
  14123. {
  14124. /* variable used for return the status of communication result*/
  14125. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14126. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  14127. u8 v_status_s8 = SUCCESS;
  14128. /* check the p_bmi160 structure as NULL*/
  14129. if (p_bmi160 == BMI160_NULL) {
  14130. return E_BMI160_NULL_PTR;
  14131. } else {
  14132. /* enable accel offset */
  14133. v_status_s8 = bmi160_set_accel_offset_enable(
  14134. ACCEL_OFFSET_ENABLE);
  14135. if (v_status_s8 == SUCCESS) {
  14136. /* write accel manual offset
  14137. compensation of z axis*/
  14138. com_rslt =
  14139. p_bmi160->BMI160_BUS_READ_FUNC(
  14140. p_bmi160->dev_addr,
  14141. BMI160_USER_OFFSET_2_ACCEL_OFF_Z__REG,
  14142. &v_data_u8, C_BMI160_ONE_U8X);
  14143. if (com_rslt == SUCCESS) {
  14144. v_data_u8 =
  14145. BMI160_SET_BITSLICE(v_data_u8,
  14146. BMI160_USER_OFFSET_2_ACCEL_OFF_Z,
  14147. v_accel_off_z_s8);
  14148. com_rslt +=
  14149. p_bmi160->BMI160_BUS_WRITE_FUNC(
  14150. p_bmi160->dev_addr,
  14151. BMI160_USER_OFFSET_2_ACCEL_OFF_Z__REG,
  14152. &v_data_u8, C_BMI160_ONE_U8X);
  14153. }
  14154. } else {
  14155. com_rslt = ERROR;
  14156. }
  14157. }
  14158. return com_rslt;
  14159. }
  14160. /*!
  14161. * @brief This API read gyro manual offset compensation of x axis
  14162. * from the register 0x74 bit 0 to 7 and 0x77 bit 0 and 1
  14163. *
  14164. *
  14165. *
  14166. * @param v_gyro_off_x_s16:
  14167. * The value of gyro manual offset compensation of x axis
  14168. *
  14169. *
  14170. *
  14171. * @return results of bus communication function
  14172. * @retval 0 -> Success
  14173. * @retval -1 -> Error
  14174. *
  14175. *
  14176. */
  14177. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_offset_compensation_xaxis(
  14178. s16 *v_gyro_off_x_s16)
  14179. {
  14180. /* variable used for return the status of communication result*/
  14181. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14182. u8 v_data1_u8r = C_BMI160_ZERO_U8X;
  14183. u8 v_data2_u8r = C_BMI160_ZERO_U8X;
  14184. s16 v_data3_u8r, v_data4_u8r = C_BMI160_ZERO_U8X;
  14185. /* check the p_bmi160 structure as NULL*/
  14186. if (p_bmi160 == BMI160_NULL) {
  14187. return E_BMI160_NULL_PTR;
  14188. } else {
  14189. /* read gyro offset x*/
  14190. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14191. p_bmi160->dev_addr,
  14192. BMI160_USER_OFFSET_3_GYRO_OFF_X__REG,
  14193. &v_data1_u8r, C_BMI160_ONE_U8X);
  14194. v_data1_u8r = BMI160_GET_BITSLICE(v_data1_u8r,
  14195. BMI160_USER_OFFSET_3_GYRO_OFF_X);
  14196. com_rslt += p_bmi160->BMI160_BUS_READ_FUNC(
  14197. p_bmi160->dev_addr,
  14198. BMI160_USER_OFFSET_6_GYRO_OFF_X__REG,
  14199. &v_data2_u8r, C_BMI160_ONE_U8X);
  14200. v_data2_u8r = BMI160_GET_BITSLICE(v_data2_u8r,
  14201. BMI160_USER_OFFSET_6_GYRO_OFF_X);
  14202. v_data3_u8r = v_data2_u8r << C_BMI160_FOURTEEN_U8X;
  14203. v_data4_u8r = v_data1_u8r << C_BMI160_SIX_U8X;
  14204. v_data3_u8r = v_data3_u8r | v_data4_u8r;
  14205. *v_gyro_off_x_s16 = v_data3_u8r >> C_BMI160_SIX_U8X;
  14206. }
  14207. return com_rslt;
  14208. }
  14209. /*!
  14210. * @brief This API write gyro manual offset compensation of x axis
  14211. * from the register 0x74 bit 0 to 7 and 0x77 bit 0 and 1
  14212. *
  14213. *
  14214. *
  14215. * @param v_gyro_off_x_s16:
  14216. * The value of gyro manual offset compensation of x axis
  14217. *
  14218. *
  14219. *
  14220. * @return results of bus communication function
  14221. * @retval 0 -> Success
  14222. * @retval -1 -> Error
  14223. *
  14224. *
  14225. */
  14226. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_offset_compensation_xaxis(
  14227. s16 v_gyro_off_x_s16)
  14228. {
  14229. /* variable used for return the status of communication result*/
  14230. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14231. u8 v_data1_u8r, v_data2_u8r = C_BMI160_ZERO_U8X;
  14232. u16 v_data3_u8r = C_BMI160_ZERO_U8X;
  14233. u8 v_status_s8 = SUCCESS;
  14234. /* check the p_bmi160 structure as NULL*/
  14235. if (p_bmi160 == BMI160_NULL) {
  14236. return E_BMI160_NULL_PTR;
  14237. } else {
  14238. /* write gyro offset x*/
  14239. v_status_s8 = bmi160_set_gyro_offset_enable(
  14240. GYRO_OFFSET_ENABLE);
  14241. if (v_status_s8 == SUCCESS) {
  14242. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14243. p_bmi160->dev_addr,
  14244. BMI160_USER_OFFSET_3_GYRO_OFF_X__REG,
  14245. &v_data2_u8r, C_BMI160_ONE_U8X);
  14246. if (com_rslt == SUCCESS) {
  14247. v_data1_u8r =
  14248. ((s8) (v_gyro_off_x_s16 &
  14249. BMI160_GYRO_MANUAL_OFFSET_0_7));
  14250. v_data2_u8r = BMI160_SET_BITSLICE(
  14251. v_data2_u8r,
  14252. BMI160_USER_OFFSET_3_GYRO_OFF_X,
  14253. v_data1_u8r);
  14254. /* write 0x74 bit 0 to 7*/
  14255. com_rslt +=
  14256. p_bmi160->BMI160_BUS_WRITE_FUNC(
  14257. p_bmi160->dev_addr,
  14258. BMI160_USER_OFFSET_3_GYRO_OFF_X__REG,
  14259. &v_data2_u8r, C_BMI160_ONE_U8X);
  14260. }
  14261. com_rslt += p_bmi160->BMI160_BUS_READ_FUNC(
  14262. p_bmi160->dev_addr,
  14263. BMI160_USER_OFFSET_6_GYRO_OFF_X__REG,
  14264. &v_data2_u8r, C_BMI160_ONE_U8X);
  14265. if (com_rslt == SUCCESS) {
  14266. v_data3_u8r =
  14267. (u16) (v_gyro_off_x_s16 &
  14268. BMI160_GYRO_MANUAL_OFFSET_8_9);
  14269. v_data1_u8r = (u8)(v_data3_u8r
  14270. >> BMI160_SHIFT_8_POSITION);
  14271. v_data2_u8r = BMI160_SET_BITSLICE(
  14272. v_data2_u8r,
  14273. BMI160_USER_OFFSET_6_GYRO_OFF_X,
  14274. v_data1_u8r);
  14275. /* write 0x77 bit 0 and 1*/
  14276. com_rslt +=
  14277. p_bmi160->BMI160_BUS_WRITE_FUNC(
  14278. p_bmi160->dev_addr,
  14279. BMI160_USER_OFFSET_6_GYRO_OFF_X__REG,
  14280. &v_data2_u8r, C_BMI160_ONE_U8X);
  14281. }
  14282. } else {
  14283. return ERROR;
  14284. }
  14285. }
  14286. return com_rslt;
  14287. }
  14288. /*!
  14289. * @brief This API read gyro manual offset compensation of y axis
  14290. * from the register 0x75 bit 0 to 7 and 0x77 bit 2 and 3
  14291. *
  14292. *
  14293. *
  14294. * @param v_gyro_off_y_s16:
  14295. * The value of gyro manual offset compensation of y axis
  14296. *
  14297. *
  14298. *
  14299. * @return results of bus communication function
  14300. * @retval 0 -> Success
  14301. * @retval -1 -> Error
  14302. *
  14303. *
  14304. */
  14305. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_offset_compensation_yaxis(
  14306. s16 *v_gyro_off_y_s16)
  14307. {
  14308. /* variable used for return the status of communication result*/
  14309. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14310. u8 v_data1_u8r = C_BMI160_ZERO_U8X;
  14311. u8 v_data2_u8r = C_BMI160_ZERO_U8X;
  14312. s16 v_data3_u8r, v_data4_u8r = C_BMI160_ZERO_U8X;
  14313. /* check the p_bmi160 structure as NULL*/
  14314. if (p_bmi160 == BMI160_NULL) {
  14315. return E_BMI160_NULL_PTR;
  14316. } else {
  14317. /* read gyro offset y*/
  14318. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14319. p_bmi160->dev_addr,
  14320. BMI160_USER_OFFSET_4_GYRO_OFF_Y__REG,
  14321. &v_data1_u8r, C_BMI160_ONE_U8X);
  14322. v_data1_u8r = BMI160_GET_BITSLICE(v_data1_u8r,
  14323. BMI160_USER_OFFSET_4_GYRO_OFF_Y);
  14324. com_rslt += p_bmi160->BMI160_BUS_READ_FUNC
  14325. (p_bmi160->dev_addr,
  14326. BMI160_USER_OFFSET_6_GYRO_OFF_Y__REG,
  14327. &v_data2_u8r, C_BMI160_ONE_U8X);
  14328. v_data2_u8r = BMI160_GET_BITSLICE(v_data2_u8r,
  14329. BMI160_USER_OFFSET_6_GYRO_OFF_Y);
  14330. v_data3_u8r = v_data2_u8r << C_BMI160_FOURTEEN_U8X;
  14331. v_data4_u8r = v_data1_u8r << C_BMI160_SIX_U8X;
  14332. v_data3_u8r = v_data3_u8r | v_data4_u8r;
  14333. *v_gyro_off_y_s16 = v_data3_u8r >> C_BMI160_SIX_U8X;
  14334. }
  14335. return com_rslt;
  14336. }
  14337. /*!
  14338. * @brief This API write gyro manual offset compensation of y axis
  14339. * from the register 0x75 bit 0 to 7 and 0x77 bit 2 and 3
  14340. *
  14341. *
  14342. *
  14343. * @param v_gyro_off_y_s16:
  14344. * The value of gyro manual offset compensation of y axis
  14345. *
  14346. *
  14347. *
  14348. * @return results of bus communication function
  14349. * @retval 0 -> Success
  14350. * @retval -1 -> Error
  14351. *
  14352. *
  14353. */
  14354. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_offset_compensation_yaxis(
  14355. s16 v_gyro_off_y_s16)
  14356. {
  14357. /* variable used for return the status of communication result*/
  14358. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14359. u8 v_data1_u8r, v_data2_u8r = C_BMI160_ZERO_U8X;
  14360. u16 v_data3_u8r = C_BMI160_ZERO_U8X;
  14361. u8 v_status_s8 = SUCCESS;
  14362. /* check the p_bmi160 structure as NULL*/
  14363. if (p_bmi160 == BMI160_NULL) {
  14364. return E_BMI160_NULL_PTR;
  14365. } else {
  14366. /* enable gyro offset bit */
  14367. v_status_s8 = bmi160_set_gyro_offset_enable(
  14368. GYRO_OFFSET_ENABLE);
  14369. /* write gyro offset y*/
  14370. if (v_status_s8 == SUCCESS) {
  14371. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  14372. (p_bmi160->dev_addr,
  14373. BMI160_USER_OFFSET_4_GYRO_OFF_Y__REG,
  14374. &v_data2_u8r, C_BMI160_ONE_U8X);
  14375. if (com_rslt == SUCCESS) {
  14376. v_data1_u8r =
  14377. ((s8) (v_gyro_off_y_s16 &
  14378. BMI160_GYRO_MANUAL_OFFSET_0_7));
  14379. v_data2_u8r = BMI160_SET_BITSLICE(
  14380. v_data2_u8r,
  14381. BMI160_USER_OFFSET_4_GYRO_OFF_Y,
  14382. v_data1_u8r);
  14383. /* write 0x75 bit 0 to 7*/
  14384. com_rslt +=
  14385. p_bmi160->BMI160_BUS_WRITE_FUNC
  14386. (p_bmi160->dev_addr,
  14387. BMI160_USER_OFFSET_4_GYRO_OFF_Y__REG,
  14388. &v_data2_u8r, C_BMI160_ONE_U8X);
  14389. }
  14390. com_rslt += p_bmi160->BMI160_BUS_READ_FUNC
  14391. (p_bmi160->dev_addr,
  14392. BMI160_USER_OFFSET_6_GYRO_OFF_Y__REG,
  14393. &v_data2_u8r, C_BMI160_ONE_U8X);
  14394. if (com_rslt == SUCCESS) {
  14395. v_data3_u8r =
  14396. (u16) (v_gyro_off_y_s16 &
  14397. BMI160_GYRO_MANUAL_OFFSET_8_9);
  14398. v_data1_u8r = (u8)(v_data3_u8r
  14399. >> BMI160_SHIFT_8_POSITION);
  14400. v_data2_u8r = BMI160_SET_BITSLICE(
  14401. v_data2_u8r,
  14402. BMI160_USER_OFFSET_6_GYRO_OFF_Y,
  14403. v_data1_u8r);
  14404. /* write 0x77 bit 2 and 3*/
  14405. com_rslt +=
  14406. p_bmi160->BMI160_BUS_WRITE_FUNC
  14407. (p_bmi160->dev_addr,
  14408. BMI160_USER_OFFSET_6_GYRO_OFF_Y__REG,
  14409. &v_data2_u8r, C_BMI160_ONE_U8X);
  14410. }
  14411. } else {
  14412. return ERROR;
  14413. }
  14414. }
  14415. return com_rslt;
  14416. }
  14417. /*!
  14418. * @brief This API read gyro manual offset compensation of z axis
  14419. * from the register 0x76 bit 0 to 7 and 0x77 bit 4 and 5
  14420. *
  14421. *
  14422. *
  14423. * @param v_gyro_off_z_s16:
  14424. * The value of gyro manual offset compensation of z axis
  14425. *
  14426. *
  14427. *
  14428. * @return results of bus communication function
  14429. * @retval 0 -> Success
  14430. * @retval -1 -> Error
  14431. *
  14432. *
  14433. */
  14434. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_offset_compensation_zaxis(
  14435. s16 *v_gyro_off_z_s16)
  14436. {
  14437. /* variable used for return the status of communication result*/
  14438. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14439. u8 v_data1_u8r = C_BMI160_ZERO_U8X;
  14440. u8 v_data2_u8r = C_BMI160_ZERO_U8X;
  14441. s16 v_data3_u8r, v_data4_u8r = C_BMI160_ZERO_U8X;
  14442. /* check the p_bmi160 structure as NULL*/
  14443. if (p_bmi160 == BMI160_NULL) {
  14444. return E_BMI160_NULL_PTR;
  14445. } else {
  14446. /* read gyro manual offset z axis*/
  14447. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  14448. (p_bmi160->dev_addr,
  14449. BMI160_USER_OFFSET_5_GYRO_OFF_Z__REG,
  14450. &v_data1_u8r, C_BMI160_ONE_U8X);
  14451. v_data1_u8r = BMI160_GET_BITSLICE
  14452. (v_data1_u8r,
  14453. BMI160_USER_OFFSET_5_GYRO_OFF_Z);
  14454. com_rslt +=
  14455. p_bmi160->BMI160_BUS_READ_FUNC
  14456. (p_bmi160->dev_addr,
  14457. BMI160_USER_OFFSET_6_GYRO_OFF_Z__REG,
  14458. &v_data2_u8r, C_BMI160_ONE_U8X);
  14459. v_data2_u8r = BMI160_GET_BITSLICE(
  14460. v_data2_u8r,
  14461. BMI160_USER_OFFSET_6_GYRO_OFF_Z);
  14462. v_data3_u8r = v_data2_u8r << C_BMI160_FOURTEEN_U8X;
  14463. v_data4_u8r = v_data1_u8r << C_BMI160_SIX_U8X;
  14464. v_data3_u8r = v_data3_u8r | v_data4_u8r;
  14465. *v_gyro_off_z_s16 = v_data3_u8r >> C_BMI160_SIX_U8X;
  14466. }
  14467. return com_rslt;
  14468. }
  14469. /*!
  14470. * @brief This API write gyro manual offset compensation of z axis
  14471. * from the register 0x76 bit 0 to 7 and 0x77 bit 4 and 5
  14472. *
  14473. *
  14474. *
  14475. * @param v_gyro_off_z_s16:
  14476. * The value of gyro manual offset compensation of z axis
  14477. *
  14478. *
  14479. *
  14480. * @return results of bus communication function
  14481. * @retval 0 -> Success
  14482. * @retval -1 -> Error
  14483. *
  14484. *
  14485. */
  14486. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_offset_compensation_zaxis(
  14487. s16 v_gyro_off_z_s16)
  14488. {
  14489. /* variable used for return the status of communication result*/
  14490. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14491. u8 v_data1_u8r, v_data2_u8r = C_BMI160_ZERO_U8X;
  14492. u16 v_data3_u8r = C_BMI160_ZERO_U8X;
  14493. u8 v_status_s8 = SUCCESS;
  14494. /* check the p_bmi160 structure as NULL*/
  14495. if (p_bmi160 == BMI160_NULL) {
  14496. return E_BMI160_NULL_PTR;
  14497. } else {
  14498. /* enable gyro offset*/
  14499. v_status_s8 = bmi160_set_gyro_offset_enable(
  14500. GYRO_OFFSET_ENABLE);
  14501. /* write gyro manual offset z axis*/
  14502. if (v_status_s8 == SUCCESS) {
  14503. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  14504. (p_bmi160->dev_addr,
  14505. BMI160_USER_OFFSET_5_GYRO_OFF_Z__REG,
  14506. &v_data2_u8r, C_BMI160_ONE_U8X);
  14507. if (com_rslt == SUCCESS) {
  14508. v_data1_u8r =
  14509. ((u8) (v_gyro_off_z_s16 &
  14510. BMI160_GYRO_MANUAL_OFFSET_0_7));
  14511. v_data2_u8r = BMI160_SET_BITSLICE(
  14512. v_data2_u8r,
  14513. BMI160_USER_OFFSET_5_GYRO_OFF_Z,
  14514. v_data1_u8r);
  14515. /* write 0x76 bit 0 to 7*/
  14516. com_rslt +=
  14517. p_bmi160->BMI160_BUS_WRITE_FUNC
  14518. (p_bmi160->dev_addr,
  14519. BMI160_USER_OFFSET_5_GYRO_OFF_Z__REG,
  14520. &v_data2_u8r, C_BMI160_ONE_U8X);
  14521. }
  14522. com_rslt += p_bmi160->BMI160_BUS_READ_FUNC
  14523. (p_bmi160->dev_addr,
  14524. BMI160_USER_OFFSET_6_GYRO_OFF_Z__REG,
  14525. &v_data2_u8r, C_BMI160_ONE_U8X);
  14526. if (com_rslt == SUCCESS) {
  14527. v_data3_u8r =
  14528. (u16) (v_gyro_off_z_s16 &
  14529. BMI160_GYRO_MANUAL_OFFSET_8_9);
  14530. v_data1_u8r = (u8)(v_data3_u8r
  14531. >> BMI160_SHIFT_8_POSITION);
  14532. v_data2_u8r = BMI160_SET_BITSLICE(
  14533. v_data2_u8r,
  14534. BMI160_USER_OFFSET_6_GYRO_OFF_Z,
  14535. v_data1_u8r);
  14536. /* write 0x77 bit 4 and 5*/
  14537. com_rslt +=
  14538. p_bmi160->BMI160_BUS_WRITE_FUNC
  14539. (p_bmi160->dev_addr,
  14540. BMI160_USER_OFFSET_6_GYRO_OFF_Z__REG,
  14541. &v_data2_u8r, C_BMI160_ONE_U8X);
  14542. }
  14543. } else {
  14544. return ERROR;
  14545. }
  14546. }
  14547. return com_rslt;
  14548. }
  14549. /*!
  14550. * @brief This API read the accel offset enable bit
  14551. * from the register 0x77 bit 6
  14552. *
  14553. *
  14554. *
  14555. * @param v_accel_off_enable_u8: The value of accel offset enable
  14556. * value | Description
  14557. * ----------|--------------
  14558. * 0x01 | ENABLE
  14559. * 0x00 | DISABLE
  14560. *
  14561. *
  14562. * @return results of bus communication function
  14563. * @retval 0 -> Success
  14564. * @retval -1 -> Error
  14565. *
  14566. *
  14567. */
  14568. BMI160_RETURN_FUNCTION_TYPE bmi160_get_accel_offset_enable(
  14569. u8 *v_accel_off_enable_u8)
  14570. {
  14571. /* variable used for return the status of communication result*/
  14572. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14573. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  14574. /* check the p_bmi160 structure as NULL*/
  14575. if (p_bmi160 == BMI160_NULL) {
  14576. return E_BMI160_NULL_PTR;
  14577. } else {
  14578. /* read accel offset enable */
  14579. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  14580. (p_bmi160->dev_addr,
  14581. BMI160_USER_OFFSET_6_ACCEL_OFF_ENABLE__REG,
  14582. &v_data_u8, C_BMI160_ONE_U8X);
  14583. *v_accel_off_enable_u8 = BMI160_GET_BITSLICE(v_data_u8,
  14584. BMI160_USER_OFFSET_6_ACCEL_OFF_ENABLE);
  14585. }
  14586. return com_rslt;
  14587. }
  14588. /*!
  14589. * @brief This API write the accel offset enable bit
  14590. * from the register 0x77 bit 6
  14591. *
  14592. *
  14593. *
  14594. * @param v_accel_off_enable_u8: The value of accel offset enable
  14595. * value | Description
  14596. * ----------|--------------
  14597. * 0x01 | ENABLE
  14598. * 0x00 | DISABLE
  14599. *
  14600. *
  14601. * @return results of bus communication function
  14602. * @retval 0 -> Success
  14603. * @retval -1 -> Error
  14604. *
  14605. *
  14606. */
  14607. BMI160_RETURN_FUNCTION_TYPE bmi160_set_accel_offset_enable(
  14608. u8 v_accel_off_enable_u8)
  14609. {
  14610. /* variable used for return the status of communication result*/
  14611. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14612. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  14613. /* check the p_bmi160 structure as NULL*/
  14614. if (p_bmi160 == BMI160_NULL) {
  14615. return E_BMI160_NULL_PTR;
  14616. } else {
  14617. /* write accel offset enable */
  14618. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14619. p_bmi160->dev_addr,
  14620. BMI160_USER_OFFSET_6_ACCEL_OFF_ENABLE__REG,
  14621. &v_data_u8, C_BMI160_ONE_U8X);
  14622. if (com_rslt == SUCCESS) {
  14623. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  14624. BMI160_USER_OFFSET_6_ACCEL_OFF_ENABLE,
  14625. v_accel_off_enable_u8);
  14626. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  14627. p_bmi160->dev_addr,
  14628. BMI160_USER_OFFSET_6_ACCEL_OFF_ENABLE__REG,
  14629. &v_data_u8, C_BMI160_ONE_U8X);
  14630. }
  14631. }
  14632. return com_rslt;
  14633. }
  14634. /*!
  14635. * @brief This API read the accel offset enable bit
  14636. * from the register 0x77 bit 7
  14637. *
  14638. *
  14639. *
  14640. * @param v_gyro_off_enable_u8: The value of gyro offset enable
  14641. * value | Description
  14642. * ----------|--------------
  14643. * 0x01 | ENABLE
  14644. * 0x00 | DISABLE
  14645. *
  14646. *
  14647. * @return results of bus communication function
  14648. * @retval 0 -> Success
  14649. * @retval -1 -> Error
  14650. *
  14651. *
  14652. */
  14653. BMI160_RETURN_FUNCTION_TYPE bmi160_get_gyro_offset_enable(
  14654. u8 *v_gyro_off_enable_u8)
  14655. {
  14656. /* variable used for return the status of communication result*/
  14657. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14658. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  14659. /* check the p_bmi160 structure as NULL*/
  14660. if (p_bmi160 == BMI160_NULL) {
  14661. return E_BMI160_NULL_PTR;
  14662. } else {
  14663. /* read gyro offset*/
  14664. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14665. p_bmi160->dev_addr,
  14666. BMI160_USER_OFFSET_6_GYRO_OFF_EN__REG,
  14667. &v_data_u8, C_BMI160_ONE_U8X);
  14668. *v_gyro_off_enable_u8 = BMI160_GET_BITSLICE(v_data_u8,
  14669. BMI160_USER_OFFSET_6_GYRO_OFF_EN);
  14670. }
  14671. return com_rslt;
  14672. }
  14673. /*!
  14674. * @brief This API write the accel offset enable bit
  14675. * from the register 0x77 bit 7
  14676. *
  14677. *
  14678. *
  14679. * @param v_gyro_off_enable_u8: The value of gyro offset enable
  14680. * value | Description
  14681. * ----------|--------------
  14682. * 0x01 | ENABLE
  14683. * 0x00 | DISABLE
  14684. *
  14685. *
  14686. * @return results of bus communication function
  14687. * @retval 0 -> Success
  14688. * @retval -1 -> Error
  14689. *
  14690. *
  14691. */
  14692. BMI160_RETURN_FUNCTION_TYPE bmi160_set_gyro_offset_enable(
  14693. u8 v_gyro_off_enable_u8)
  14694. {
  14695. /* variable used for return the status of communication result*/
  14696. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14697. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  14698. /* check the p_bmi160 structure as NULL*/
  14699. if (p_bmi160 == BMI160_NULL) {
  14700. return E_BMI160_NULL_PTR;
  14701. } else {
  14702. /* write gyro offset*/
  14703. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14704. p_bmi160->dev_addr,
  14705. BMI160_USER_OFFSET_6_GYRO_OFF_EN__REG,
  14706. &v_data_u8, C_BMI160_ONE_U8X);
  14707. if (com_rslt == SUCCESS) {
  14708. v_data_u8 = BMI160_SET_BITSLICE(v_data_u8,
  14709. BMI160_USER_OFFSET_6_GYRO_OFF_EN,
  14710. v_gyro_off_enable_u8);
  14711. com_rslt += p_bmi160->BMI160_BUS_WRITE_FUNC(
  14712. p_bmi160->dev_addr,
  14713. BMI160_USER_OFFSET_6_GYRO_OFF_EN__REG,
  14714. &v_data_u8, C_BMI160_ONE_U8X);
  14715. }
  14716. }
  14717. return com_rslt;
  14718. }
  14719. /*!
  14720. * @brief This API reads step counter value
  14721. * form the register 0x78 and 0x79
  14722. *
  14723. *
  14724. *
  14725. *
  14726. * @param v_step_cnt_s16 : The value of step counter
  14727. *
  14728. *
  14729. *
  14730. * @return results of bus communication function
  14731. * @retval 0 -> Success
  14732. * @retval -1 -> Error
  14733. *
  14734. *
  14735. */
  14736. BMI160_RETURN_FUNCTION_TYPE bmi160_read_step_count(s16 *v_step_cnt_s16)
  14737. {
  14738. /* variable used for return the status of communication result*/
  14739. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14740. /* array having the step counter LSB and MSB data
  14741. v_data_u8[0] - LSB
  14742. v_data_u8[1] - MSB*/
  14743. u8 a_data_u8r[ARRAY_SIZE_TWO] = {C_BMI160_ZERO_U8X,
  14744. C_BMI160_ZERO_U8X};
  14745. /* check the p_bmi160 structure as NULL*/
  14746. if (p_bmi160 == BMI160_NULL) {
  14747. return E_BMI160_NULL_PTR;
  14748. } else {
  14749. /* read step counter */
  14750. com_rslt =
  14751. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  14752. BMI160_USER_STEP_COUNT_LSB__REG,
  14753. a_data_u8r, C_BMI160_TWO_U8X);
  14754. *v_step_cnt_s16 = (s16)
  14755. ((((s32)((s8)a_data_u8r[MSB_ONE]))
  14756. << BMI160_SHIFT_8_POSITION) | (a_data_u8r[LSB_ZERO]));
  14757. }
  14758. return com_rslt;
  14759. }
  14760. /*!
  14761. * @brief This API Reads
  14762. * step counter configuration
  14763. * from the register 0x7A bit 0 to 7
  14764. * and from the register 0x7B bit 0 to 2 and 4 to 7
  14765. *
  14766. *
  14767. * @param v_step_config_u16 : The value of step configuration
  14768. *
  14769. * @return results of bus communication function
  14770. * @retval 0 -> Success
  14771. * @retval -1 -> Error
  14772. *
  14773. *
  14774. */
  14775. BMI160_RETURN_FUNCTION_TYPE bmi160_get_step_config(
  14776. u16 *v_step_config_u16)
  14777. {
  14778. /* variable used for return the status of communication result*/
  14779. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14780. u8 v_data1_u8r = C_BMI160_ZERO_U8X;
  14781. u8 v_data2_u8r = C_BMI160_ZERO_U8X;
  14782. u16 v_data3_u8r = C_BMI160_ZERO_U8X;
  14783. /* Read the 0 to 7 bit*/
  14784. com_rslt =
  14785. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  14786. BMI160_USER_STEP_CONFIG_ZERO__REG,
  14787. &v_data1_u8r, C_BMI160_ONE_U8X);
  14788. /* Read the 8 to 10 bit*/
  14789. com_rslt +=
  14790. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  14791. BMI160_USER_STEP_CONFIG_ONE_CNF1__REG,
  14792. &v_data2_u8r, C_BMI160_ONE_U8X);
  14793. v_data2_u8r = BMI160_GET_BITSLICE(v_data2_u8r,
  14794. BMI160_USER_STEP_CONFIG_ONE_CNF1);
  14795. v_data3_u8r = ((u16)((((u32)
  14796. ((u8)v_data2_u8r))
  14797. << BMI160_SHIFT_8_POSITION) | (v_data1_u8r)));
  14798. /* Read the 11 to 14 bit*/
  14799. com_rslt +=
  14800. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  14801. BMI160_USER_STEP_CONFIG_ONE_CNF2__REG,
  14802. &v_data1_u8r, C_BMI160_ONE_U8X);
  14803. v_data1_u8r = BMI160_GET_BITSLICE(v_data1_u8r,
  14804. BMI160_USER_STEP_CONFIG_ONE_CNF2);
  14805. *v_step_config_u16 = ((u16)((((u32)
  14806. ((u8)v_data1_u8r))
  14807. << BMI160_SHIFT_8_POSITION) | (v_data3_u8r)));
  14808. return com_rslt;
  14809. }
  14810. /*!
  14811. * @brief This API write
  14812. * step counter configuration
  14813. * from the register 0x7A bit 0 to 7
  14814. * and from the register 0x7B bit 0 to 2 and 4 to 7
  14815. *
  14816. *
  14817. * @param v_step_config_u16 :
  14818. * the value of Enable step configuration
  14819. *
  14820. * @return results of bus communication function
  14821. * @retval 0 -> Success
  14822. * @retval -1 -> Error
  14823. *
  14824. *
  14825. */
  14826. BMI160_RETURN_FUNCTION_TYPE bmi160_set_step_config(
  14827. u16 v_step_config_u16)
  14828. {
  14829. /* variable used for return the status of communication result*/
  14830. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14831. u8 v_data1_u8r = C_BMI160_ZERO_U8X;
  14832. u8 v_data2_u8r = C_BMI160_ZERO_U8X;
  14833. u16 v_data3_u16 = C_BMI160_ZERO_U8X;
  14834. /* write the 0 to 7 bit*/
  14835. v_data1_u8r = (u8)(v_step_config_u16 &
  14836. BMI160_STEP_CONFIG_0_7);
  14837. p_bmi160->BMI160_BUS_WRITE_FUNC
  14838. (p_bmi160->dev_addr,
  14839. BMI160_USER_STEP_CONFIG_ZERO__REG,
  14840. &v_data1_u8r, C_BMI160_ONE_U8X);
  14841. /* write the 8 to 10 bit*/
  14842. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  14843. (p_bmi160->dev_addr,
  14844. BMI160_USER_STEP_CONFIG_ONE_CNF1__REG,
  14845. &v_data2_u8r, C_BMI160_ONE_U8X);
  14846. if (com_rslt == SUCCESS) {
  14847. v_data3_u16 = (u16) (v_step_config_u16 &
  14848. BMI160_STEP_CONFIG_8_10);
  14849. v_data1_u8r = (u8)(v_data3_u16 >> BMI160_SHIFT_8_POSITION);
  14850. v_data2_u8r = BMI160_SET_BITSLICE(v_data2_u8r,
  14851. BMI160_USER_STEP_CONFIG_ONE_CNF1, v_data1_u8r);
  14852. p_bmi160->BMI160_BUS_WRITE_FUNC
  14853. (p_bmi160->dev_addr,
  14854. BMI160_USER_STEP_CONFIG_ONE_CNF1__REG,
  14855. &v_data2_u8r, C_BMI160_ONE_U8X);
  14856. }
  14857. /* write the 11 to 14 bit*/
  14858. com_rslt += p_bmi160->BMI160_BUS_READ_FUNC
  14859. (p_bmi160->dev_addr,
  14860. BMI160_USER_STEP_CONFIG_ONE_CNF2__REG,
  14861. &v_data2_u8r, C_BMI160_ONE_U8X);
  14862. if (com_rslt == SUCCESS) {
  14863. v_data3_u16 = (u16) (v_step_config_u16 &
  14864. BMI160_STEP_CONFIG_11_14);
  14865. v_data1_u8r = (u8)(v_data3_u16 >> BMI160_SHIFT_12_POSITION);
  14866. v_data2_u8r = BMI160_SET_BITSLICE(v_data2_u8r,
  14867. BMI160_USER_STEP_CONFIG_ONE_CNF2, v_data1_u8r);
  14868. p_bmi160->BMI160_BUS_WRITE_FUNC
  14869. (p_bmi160->dev_addr,
  14870. BMI160_USER_STEP_CONFIG_ONE_CNF2__REG,
  14871. &v_data2_u8r, C_BMI160_ONE_U8X);
  14872. }
  14873. return com_rslt;
  14874. }
  14875. /*!
  14876. * @brief This API read enable step counter
  14877. * from the register 0x7B bit 3
  14878. *
  14879. *
  14880. * @param v_step_counter_u8 : The value of step counter enable
  14881. *
  14882. * @return results of bus communication function
  14883. * @retval 0 -> Success
  14884. * @retval -1 -> Error
  14885. *
  14886. *
  14887. */
  14888. BMI160_RETURN_FUNCTION_TYPE bmi160_get_step_counter_enable(
  14889. u8 *v_step_counter_u8)
  14890. {
  14891. /* variable used for return the status of communication result*/
  14892. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14893. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  14894. /* check the p_bmi160 structure as NULL*/
  14895. if (p_bmi160 == BMI160_NULL) {
  14896. return E_BMI160_NULL_PTR;
  14897. } else {
  14898. /* read the step counter */
  14899. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  14900. p_bmi160->dev_addr,
  14901. BMI160_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE__REG,
  14902. &v_data_u8, C_BMI160_ONE_U8X);
  14903. *v_step_counter_u8 = BMI160_GET_BITSLICE(v_data_u8,
  14904. BMI160_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE);
  14905. }
  14906. return com_rslt;
  14907. }
  14908. /*!
  14909. * @brief This API write enable step counter
  14910. * from the register 0x7B bit 3
  14911. *
  14912. *
  14913. * @param v_step_counter_u8 : The value of step counter enable
  14914. *
  14915. * @return results of bus communication function
  14916. * @retval 0 -> Success
  14917. * @retval -1 -> Error
  14918. *
  14919. *
  14920. */
  14921. BMI160_RETURN_FUNCTION_TYPE bmi160_set_step_counter_enable(u8 v_step_counter_u8)
  14922. {
  14923. /* variable used for return the status of communication result*/
  14924. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14925. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  14926. /* check the p_bmi160 structure as NULL*/
  14927. if (p_bmi160 == BMI160_NULL) {
  14928. return E_BMI160_NULL_PTR;
  14929. } else {
  14930. if (v_step_counter_u8 < C_BMI160_THREE_U8X) {
  14931. /* write the step counter */
  14932. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  14933. (p_bmi160->dev_addr,
  14934. BMI160_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE__REG,
  14935. &v_data_u8, C_BMI160_ONE_U8X);
  14936. if (com_rslt == SUCCESS) {
  14937. v_data_u8 =
  14938. BMI160_SET_BITSLICE(v_data_u8,
  14939. BMI160_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE,
  14940. v_step_counter_u8);
  14941. com_rslt +=
  14942. p_bmi160->BMI160_BUS_WRITE_FUNC
  14943. (p_bmi160->dev_addr,
  14944. BMI160_USER_STEP_CONFIG_1_STEP_COUNT_ENABLE__REG,
  14945. &v_data_u8, C_BMI160_ONE_U8X);
  14946. }
  14947. } else {
  14948. com_rslt = E_BMI160_OUT_OF_RANGE;
  14949. }
  14950. }
  14951. return com_rslt;
  14952. }
  14953. /*!
  14954. * @brief This API set Step counter modes
  14955. *
  14956. *
  14957. * @param v_step_mode_u8 : The value of step counter mode
  14958. * value | mode
  14959. * ----------|-----------
  14960. * 0 | BMI160_STEP_NORMAL_MODE
  14961. * 1 | BMI160_STEP_SENSITIVE_MODE
  14962. * 2 | BMI160_STEP_ROBUST_MODE
  14963. *
  14964. * @return results of bus communication function
  14965. * @retval 0 -> Success
  14966. * @retval -1 -> Error
  14967. *
  14968. *
  14969. */
  14970. BMI160_RETURN_FUNCTION_TYPE bmi160_set_step_mode(u8 v_step_mode_u8)
  14971. {
  14972. /* variable used for return the status of communication result*/
  14973. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  14974. switch (v_step_mode_u8) {
  14975. case BMI160_STEP_NORMAL_MODE:
  14976. com_rslt = bmi160_set_step_config(
  14977. STEP_CONFIG_NORMAL);
  14978. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  14979. break;
  14980. case BMI160_STEP_SENSITIVE_MODE:
  14981. com_rslt = bmi160_set_step_config(
  14982. STEP_CONFIG_SENSITIVE);
  14983. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  14984. break;
  14985. case BMI160_STEP_ROBUST_MODE:
  14986. com_rslt = bmi160_set_step_config(
  14987. STEP_CONFIG_ROBUST);
  14988. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  14989. break;
  14990. default:
  14991. com_rslt = E_BMI160_OUT_OF_RANGE;
  14992. break;
  14993. }
  14994. return com_rslt;
  14995. }
  14996. /*!
  14997. * @brief This API used to trigger the signification motion
  14998. * interrupt
  14999. *
  15000. *
  15001. * @param v_significant_u8 : The value of interrupt selection
  15002. * value | interrupt
  15003. * ----------|-----------
  15004. * 0 | BMI160_MAP_INTR1
  15005. * 1 | BMI160_MAP_INTR2
  15006. *
  15007. * @return results of bus communication function
  15008. * @retval 0 -> Success
  15009. * @retval -1 -> Error
  15010. *
  15011. *
  15012. */
  15013. BMI160_RETURN_FUNCTION_TYPE bmi160_map_significant_motion_intr(
  15014. u8 v_significant_u8)
  15015. {
  15016. /* variable used for return the status of communication result*/
  15017. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15018. u8 v_sig_motion_u8 = C_BMI160_ZERO_U8X;
  15019. u8 v_any_motion_intr1_stat_u8 = BMI160_HEX_0_4_DATA;
  15020. u8 v_any_motion_intr2_stat_u8 = BMI160_HEX_0_4_DATA;
  15021. u8 v_any_motion_axis_stat_u8 = BMI160_HEX_0_7_DATA;
  15022. /* enable the significant motion interrupt */
  15023. com_rslt = bmi160_get_intr_significant_motion_select(&v_sig_motion_u8);
  15024. if (v_sig_motion_u8 != C_BMI160_ONE_U8X)
  15025. com_rslt += bmi160_set_intr_significant_motion_select(
  15026. BMI160_HEX_0_1_DATA);
  15027. switch (v_significant_u8) {
  15028. case BMI160_MAP_INTR1:
  15029. /* map the signification interrupt to any-motion interrupt1*/
  15030. com_rslt = bmi160_write_reg(
  15031. BMI160_USER_INTR_MAP_0_INTR1_ANY_MOTION__REG,
  15032. &v_any_motion_intr1_stat_u8, C_BMI160_ONE_U8X);
  15033. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  15034. com_rslt += bmi160_write_reg(
  15035. BMI160_USER_INTR_ENABLE_0_ADDR,
  15036. &v_any_motion_axis_stat_u8, C_BMI160_ONE_U8X);
  15037. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  15038. break;
  15039. case BMI160_MAP_INTR2:
  15040. /* map the signification interrupt to any-motion interrupt2*/
  15041. com_rslt = bmi160_write_reg(
  15042. BMI160_USER_INTR_MAP_2_INTR2_ANY_MOTION__REG,
  15043. &v_any_motion_intr2_stat_u8, C_BMI160_ONE_U8X);
  15044. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  15045. com_rslt += bmi160_write_reg(
  15046. BMI160_USER_INTR_ENABLE_0_ADDR,
  15047. &v_any_motion_axis_stat_u8, C_BMI160_ONE_U8X);
  15048. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  15049. break;
  15050. default:
  15051. com_rslt = E_BMI160_OUT_OF_RANGE;
  15052. break;
  15053. }
  15054. return com_rslt;
  15055. }
  15056. /*!
  15057. * @brief This API used to trigger the step detector
  15058. * interrupt
  15059. *
  15060. *
  15061. * @param v_step_detector_u8 : The value of interrupt selection
  15062. * value | interrupt
  15063. * ----------|-----------
  15064. * 0 | BMI160_MAP_INTR1
  15065. * 1 | BMI160_MAP_INTR2
  15066. *
  15067. * @return results of bus communication function
  15068. * @retval 0 -> Success
  15069. * @retval -1 -> Error
  15070. *
  15071. *
  15072. */
  15073. BMI160_RETURN_FUNCTION_TYPE bmi160_map_step_detector_intr(
  15074. u8 v_step_detector_u8)
  15075. {
  15076. /* variable used for return the status of communication result*/
  15077. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15078. u8 v_step_det_u8 = C_BMI160_ZERO_U8X;
  15079. u8 v_low_g_intr_u81_stat_u8 = BMI160_HEX_0_1_DATA;
  15080. u8 v_low_g_intr_u82_stat_u8 = BMI160_HEX_0_1_DATA;
  15081. u8 v_low_g_enable_u8 = BMI160_HEX_0_8_DATA;
  15082. /* read the v_status_s8 of step detector interrupt*/
  15083. com_rslt = bmi160_get_step_detector_enable(&v_step_det_u8);
  15084. if (v_step_det_u8 != C_BMI160_ONE_U8X)
  15085. com_rslt += bmi160_set_step_detector_enable(
  15086. BMI160_HEX_0_1_DATA);
  15087. switch (v_step_detector_u8) {
  15088. case BMI160_MAP_INTR1:
  15089. /* map the step detector interrupt
  15090. to Low-g interrupt 1*/
  15091. com_rslt = bmi160_write_reg(
  15092. BMI160_USER_INTR_MAP_0_INTR1_LOW_G__REG,
  15093. &v_low_g_intr_u81_stat_u8, C_BMI160_ONE_U8X);
  15094. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  15095. /* Enable the Low-g interrupt*/
  15096. com_rslt += bmi160_write_reg(
  15097. BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG,
  15098. &v_low_g_enable_u8, C_BMI160_ONE_U8X);
  15099. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  15100. break;
  15101. case BMI160_MAP_INTR2:
  15102. /* map the step detector interrupt
  15103. to Low-g interrupt 1*/
  15104. com_rslt = bmi160_write_reg(
  15105. BMI160_USER_INTR_MAP_2_INTR2_LOW_G__REG,
  15106. &v_low_g_intr_u82_stat_u8, C_BMI160_ONE_U8X);
  15107. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  15108. /* Enable the Low-g interrupt*/
  15109. com_rslt += bmi160_write_reg(
  15110. BMI160_USER_INTR_ENABLE_1_LOW_G_ENABLE__REG,
  15111. &v_low_g_enable_u8, C_BMI160_ONE_U8X);
  15112. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  15113. break;
  15114. default:
  15115. com_rslt = E_BMI160_OUT_OF_RANGE;
  15116. break;
  15117. }
  15118. return com_rslt;
  15119. }
  15120. /*!
  15121. * @brief This API used to clear the step counter interrupt
  15122. * interrupt
  15123. *
  15124. *
  15125. * @param : None
  15126. *
  15127. *
  15128. * @return results of bus communication function
  15129. * @retval 0 -> Success
  15130. * @retval -1 -> Error
  15131. *
  15132. *
  15133. */
  15134. BMI160_RETURN_FUNCTION_TYPE bmi160_clear_step_counter(void)
  15135. {
  15136. /* variable used for return the status of communication result*/
  15137. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15138. /* clear the step counter*/
  15139. com_rslt = bmi160_set_command_register(RESET_STEP_COUNTER);
  15140. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  15141. return com_rslt;
  15142. }
  15143. /*!
  15144. * @brief This API writes value to the register 0x7E bit 0 to 7
  15145. *
  15146. *
  15147. * @param v_command_reg_u8 : The value to write command register
  15148. * value | Description
  15149. * ---------|--------------------------------------------------------
  15150. * 0x00 | Reserved
  15151. * 0x03 | Starts fast offset calibration for the accel and gyro
  15152. * 0x10 | Sets the PMU mode for the Accelerometer to suspend
  15153. * 0x11 | Sets the PMU mode for the Accelerometer to normal
  15154. * 0x12 | Sets the PMU mode for the Accelerometer Lowpower
  15155. * 0x14 | Sets the PMU mode for the Gyroscope to suspend
  15156. * 0x15 | Sets the PMU mode for the Gyroscope to normal
  15157. * 0x16 | Reserved
  15158. * 0x17 | Sets the PMU mode for the Gyroscope to fast start-up
  15159. * 0x18 | Sets the PMU mode for the Magnetometer to suspend
  15160. * 0x19 | Sets the PMU mode for the Magnetometer to normal
  15161. * 0x1A | Sets the PMU mode for the Magnetometer to Lowpower
  15162. * 0xB0 | Clears all data in the FIFO
  15163. * 0xB1 | Resets the interrupt engine
  15164. * 0xB2 | step_cnt_clr Clears the step counter
  15165. * 0xB6 | Triggers a reset
  15166. * 0x37 | See extmode_en_last
  15167. * 0x9A | See extmode_en_last
  15168. * 0xC0 | Enable the extended mode
  15169. * 0xC4 | Erase NVM cell
  15170. * 0xC8 | Load NVM cell
  15171. * 0xF0 | Reset acceleration data path
  15172. *
  15173. *
  15174. *
  15175. * @return results of bus communication function
  15176. * @retval 0 -> Success
  15177. * @retval -1 -> Error
  15178. *
  15179. *
  15180. */
  15181. BMI160_RETURN_FUNCTION_TYPE bmi160_set_command_register(u8 v_command_reg_u8)
  15182. {
  15183. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15184. /* check the p_bmi160 structure as NULL*/
  15185. if (p_bmi160 == BMI160_NULL) {
  15186. return E_BMI160_NULL_PTR;
  15187. } else {
  15188. /* write command register */
  15189. com_rslt = p_bmi160->BMI160_BUS_WRITE_FUNC(
  15190. p_bmi160->dev_addr,
  15191. BMI160_CMD_COMMANDS__REG,
  15192. &v_command_reg_u8, C_BMI160_ONE_U8X);
  15193. }
  15194. return com_rslt;
  15195. }
  15196. /*!
  15197. * @brief This API read target page from the register 0x7F bit 4 and 5
  15198. *
  15199. * @param v_target_page_u8: The value of target page
  15200. * value | page
  15201. * ---------|-----------
  15202. * 0 | User data/configure page
  15203. * 1 | Chip level trim/test page
  15204. *
  15205. * @return results of bus communication function
  15206. * @retval 0 -> Success
  15207. * @retval -1 -> Error
  15208. *
  15209. *
  15210. */
  15211. BMI160_RETURN_FUNCTION_TYPE bmi160_get_target_page(u8 *v_target_page_u8)
  15212. {
  15213. /* variable used for return the status of communication result*/
  15214. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15215. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  15216. /* check the p_bmi160 structure as NULL*/
  15217. if (p_bmi160 == BMI160_NULL) {
  15218. return E_BMI160_NULL_PTR;
  15219. } else {
  15220. /* read the page*/
  15221. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  15222. p_bmi160->dev_addr,
  15223. BMI160_CMD_TARGET_PAGE__REG,
  15224. &v_data_u8, C_BMI160_ONE_U8X);
  15225. *v_target_page_u8 = BMI160_GET_BITSLICE(v_data_u8,
  15226. BMI160_CMD_TARGET_PAGE);
  15227. }
  15228. return com_rslt;
  15229. }
  15230. /*!
  15231. * @brief This API write target page from the register 0x7F bit 4 and 5
  15232. *
  15233. * @param v_target_page_u8: The value of target page
  15234. * value | page
  15235. * ---------|-----------
  15236. * 0 | User data/configure page
  15237. * 1 | Chip level trim/test page
  15238. *
  15239. * @return results of bus communication function
  15240. * @retval 0 -> Success
  15241. * @retval -1 -> Error
  15242. *
  15243. *
  15244. */
  15245. BMI160_RETURN_FUNCTION_TYPE bmi160_set_target_page(u8 v_target_page_u8)
  15246. {
  15247. /* variable used for return the status of communication result*/
  15248. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15249. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  15250. /* check the p_bmi160 structure as NULL*/
  15251. if (p_bmi160 == BMI160_NULL) {
  15252. return E_BMI160_NULL_PTR;
  15253. } else {
  15254. if (v_target_page_u8 < C_BMI160_FOUR_U8X) {
  15255. /* write the page*/
  15256. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  15257. (p_bmi160->dev_addr,
  15258. BMI160_CMD_TARGET_PAGE__REG,
  15259. &v_data_u8, C_BMI160_ONE_U8X);
  15260. if (com_rslt == SUCCESS) {
  15261. v_data_u8 =
  15262. BMI160_SET_BITSLICE(v_data_u8,
  15263. BMI160_CMD_TARGET_PAGE,
  15264. v_target_page_u8);
  15265. com_rslt +=
  15266. p_bmi160->BMI160_BUS_WRITE_FUNC
  15267. (p_bmi160->dev_addr,
  15268. BMI160_CMD_TARGET_PAGE__REG,
  15269. &v_data_u8, C_BMI160_ONE_U8X);
  15270. }
  15271. } else {
  15272. com_rslt = E_BMI160_OUT_OF_RANGE;
  15273. }
  15274. }
  15275. return com_rslt;
  15276. }
  15277. /*!
  15278. * @brief This API read page enable from the register 0x7F bit 7
  15279. *
  15280. *
  15281. *
  15282. * @param v_page_enable_u8: The value of page enable
  15283. * value | page
  15284. * ---------|-----------
  15285. * 0 | DISABLE
  15286. * 1 | ENABLE
  15287. *
  15288. *
  15289. *
  15290. * @return results of bus communication function
  15291. * @retval 0 -> Success
  15292. * @retval -1 -> Error
  15293. *
  15294. *
  15295. */
  15296. BMI160_RETURN_FUNCTION_TYPE bmi160_get_paging_enable(u8 *v_page_enable_u8)
  15297. {
  15298. /* variable used for return the status of communication result*/
  15299. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15300. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  15301. /* check the p_bmi160 structure as NULL*/
  15302. if (p_bmi160 == BMI160_NULL) {
  15303. return E_BMI160_NULL_PTR;
  15304. } else {
  15305. /* read the page enable */
  15306. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  15307. p_bmi160->dev_addr,
  15308. BMI160_CMD_PAGING_EN__REG,
  15309. &v_data_u8, C_BMI160_ONE_U8X);
  15310. *v_page_enable_u8 = BMI160_GET_BITSLICE(v_data_u8,
  15311. BMI160_CMD_PAGING_EN);
  15312. }
  15313. return com_rslt;
  15314. }
  15315. /*!
  15316. * @brief This API write page enable from the register 0x7F bit 7
  15317. *
  15318. *
  15319. *
  15320. * @param v_page_enable_u8: The value of page enable
  15321. * value | page
  15322. * ---------|-----------
  15323. * 0 | DISABLE
  15324. * 1 | ENABLE
  15325. *
  15326. *
  15327. *
  15328. * @return results of bus communication function
  15329. * @retval 0 -> Success
  15330. * @retval -1 -> Error
  15331. *
  15332. *
  15333. */
  15334. BMI160_RETURN_FUNCTION_TYPE bmi160_set_paging_enable(
  15335. u8 v_page_enable_u8)
  15336. {
  15337. /* variable used for return the status of communication result*/
  15338. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15339. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  15340. /* check the p_bmi160 structure as NULL*/
  15341. if (p_bmi160 == BMI160_NULL) {
  15342. return E_BMI160_NULL_PTR;
  15343. } else {
  15344. if (v_page_enable_u8 < C_BMI160_TWO_U8X) {
  15345. /* write the page enable */
  15346. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  15347. (p_bmi160->dev_addr,
  15348. BMI160_CMD_PAGING_EN__REG,
  15349. &v_data_u8, C_BMI160_ONE_U8X);
  15350. if (com_rslt == SUCCESS) {
  15351. v_data_u8 =
  15352. BMI160_SET_BITSLICE(v_data_u8,
  15353. BMI160_CMD_PAGING_EN,
  15354. v_page_enable_u8);
  15355. com_rslt +=
  15356. p_bmi160->BMI160_BUS_WRITE_FUNC
  15357. (p_bmi160->dev_addr,
  15358. BMI160_CMD_PAGING_EN__REG,
  15359. &v_data_u8, C_BMI160_ONE_U8X);
  15360. }
  15361. } else {
  15362. com_rslt = E_BMI160_OUT_OF_RANGE;
  15363. }
  15364. }
  15365. return com_rslt;
  15366. }
  15367. /*!
  15368. * @brief This API read
  15369. * pull up configuration from the register 0X85 bit 4 an 5
  15370. *
  15371. *
  15372. *
  15373. * @param v_control_pullup_u8: The value of pull up register
  15374. *
  15375. *
  15376. *
  15377. * @return results of bus communication function
  15378. * @retval 0 -> Success
  15379. * @retval -1 -> Error
  15380. *
  15381. *
  15382. */
  15383. BMI160_RETURN_FUNCTION_TYPE bmi160_get_pullup_configuration(
  15384. u8 *v_control_pullup_u8)
  15385. {
  15386. /* variable used for return the status of communication result*/
  15387. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15388. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  15389. /* check the p_bmi160 structure as NULL*/
  15390. if (p_bmi160 == BMI160_NULL) {
  15391. return E_BMI160_NULL_PTR;
  15392. } else {
  15393. /* read pull up value */
  15394. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC(
  15395. p_bmi160->dev_addr,
  15396. BMI160_COM_C_TRIM_FIVE__REG,
  15397. &v_data_u8, C_BMI160_ONE_U8X);
  15398. *v_control_pullup_u8 = BMI160_GET_BITSLICE(v_data_u8,
  15399. BMI160_COM_C_TRIM_FIVE);
  15400. }
  15401. return com_rslt;
  15402. }
  15403. /*!
  15404. * @brief This API write
  15405. * pull up configuration from the register 0X85 bit 4 an 5
  15406. *
  15407. *
  15408. *
  15409. * @param v_control_pullup_u8: The value of pull up register
  15410. *
  15411. *
  15412. *
  15413. * @return results of bus communication function
  15414. * @retval 0 -> Success
  15415. * @retval -1 -> Error
  15416. *
  15417. *
  15418. */
  15419. BMI160_RETURN_FUNCTION_TYPE bmi160_set_pullup_configuration(
  15420. u8 v_control_pullup_u8)
  15421. {
  15422. /* variable used for return the status of communication result*/
  15423. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15424. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  15425. /* check the p_bmi160 structure as NULL*/
  15426. if (p_bmi160 == BMI160_NULL) {
  15427. return E_BMI160_NULL_PTR;
  15428. } else {
  15429. if (v_control_pullup_u8 < C_BMI160_FOUR_U8X) {
  15430. /* write pull up value */
  15431. com_rslt = p_bmi160->BMI160_BUS_READ_FUNC
  15432. (p_bmi160->dev_addr,
  15433. BMI160_COM_C_TRIM_FIVE__REG,
  15434. &v_data_u8, C_BMI160_ONE_U8X);
  15435. if (com_rslt == SUCCESS) {
  15436. v_data_u8 =
  15437. BMI160_SET_BITSLICE(v_data_u8,
  15438. BMI160_COM_C_TRIM_FIVE,
  15439. v_control_pullup_u8);
  15440. com_rslt +=
  15441. p_bmi160->BMI160_BUS_WRITE_FUNC
  15442. (p_bmi160->dev_addr,
  15443. BMI160_COM_C_TRIM_FIVE__REG,
  15444. &v_data_u8, C_BMI160_ONE_U8X);
  15445. }
  15446. } else {
  15447. com_rslt = E_BMI160_OUT_OF_RANGE;
  15448. }
  15449. }
  15450. return com_rslt;
  15451. }
  15452. /*!
  15453. * @brief This function used for reading the
  15454. * fifo data of header mode
  15455. *
  15456. * @param v_fifo_length_u32 : The value of FIFO length
  15457. *
  15458. * @note Configure the below functions for FIFO header mode
  15459. * @note 1. bmi160_set_fifo_down_gyro()
  15460. * @note 2. bmi160_set_gyro_fifo_filter_data()
  15461. * @note 3. bmi160_set_fifo_down_accel()
  15462. * @note 4. bmi160_set_accel_fifo_filter_dat()
  15463. * @note 5. bmi160_set_fifo_mag_enable()
  15464. * @note 6. bmi160_set_fifo_accel_enable()
  15465. * @note 7. bmi160_set_fifo_gyro_enable()
  15466. * @note 8. bmi160_set_fifo_header_enable()
  15467. * @note For interrupt configuration
  15468. * @note 1. bmi160_set_intr_fifo_full()
  15469. * @note 2. bmi160_set_intr_fifo_wm()
  15470. * @note 3. bmi160_set_fifo_tag_intr2_enable()
  15471. * @note 4. bmi160_set_fifo_tag_intr1_enable()
  15472. * @return results of bus communication function
  15473. * @retval 0 -> Success
  15474. * @retval -1 -> Error
  15475. *
  15476. *
  15477. */
  15478. BMI160_RETURN_FUNCTION_TYPE bmi160_read_fifo_header_data(u32 v_fifo_length_u32)
  15479. {
  15480. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  15481. u8 v_accel_index_u8 = C_BMI160_ZERO_U8X;
  15482. u8 v_gyro_index_u8 = C_BMI160_ZERO_U8X;
  15483. u8 v_mag_index_u8 = C_BMI160_ZERO_U8X;
  15484. s8 v_last_return_stat_s8 = C_BMI160_ZERO_U8X;
  15485. u32 v_fifo_index_u32 = C_BMI160_ZERO_U8X;
  15486. u16 v_mag_data_r_u16 = C_BMI160_ZERO_U8X;
  15487. u8 v_frame_head_u8 = C_BMI160_ZERO_U8X;
  15488. s16 v_mag_data_s16 = C_BMI160_ZERO_U8X;
  15489. s16 v_mag_x_s16, v_mag_y_s16, v_mag_z_s16 = C_BMI160_ZERO_U8X;
  15490. u16 v_mag_r_s16 = C_BMI160_ZERO_U8X;
  15491. /* read fifo v_data_u8*/
  15492. com_rslt = bmi160_fifo_data(&v_fifo_data_u8[C_BMI160_ZERO_U8X]);
  15493. for (v_fifo_index_u32 = C_BMI160_ZERO_U8X;
  15494. v_fifo_index_u32 < v_fifo_length_u32;) {
  15495. v_frame_head_u8 = v_fifo_data_u8[v_fifo_index_u32];
  15496. switch (v_frame_head_u8) {
  15497. /* Header frame of accel */
  15498. case FIFO_HEAD_A:
  15499. { /*fifo v_data_u8 frame index + 1*/
  15500. v_fifo_index_u32 = v_fifo_index_u32 +
  15501. C_BMI160_ONE_U8X;
  15502. if ((v_fifo_index_u32 + C_BMI160_SIX_U8X)
  15503. > v_fifo_length_u32) {
  15504. v_last_return_stat_s8 = FIFO_A_OVER_LEN;
  15505. break;
  15506. }
  15507. /* Accel raw x v_data_u8 */
  15508. accel_fifo[v_accel_index_u8].x =
  15509. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15510. C_BMI160_ONE_U8X]) << C_BMI160_EIGHT_U8X)
  15511. | (v_fifo_data_u8[v_fifo_index_u32 +
  15512. C_BMI160_ZERO_U8X]));
  15513. /* Accel raw y v_data_u8 */
  15514. accel_fifo[v_accel_index_u8].y =
  15515. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15516. C_BMI160_THREE_U8X]) << C_BMI160_EIGHT_U8X)
  15517. | (v_fifo_data_u8[v_fifo_index_u32 +
  15518. C_BMI160_TWO_U8X]));
  15519. /* Accel raw z v_data_u8 */
  15520. accel_fifo[v_accel_index_u8].z =
  15521. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15522. C_BMI160_FIVE_U8X]) << C_BMI160_EIGHT_U8X)
  15523. | (v_fifo_data_u8[v_fifo_index_u32 +
  15524. C_BMI160_FOUR_U8X]));
  15525. /* index adde to 6 accel alone*/
  15526. v_fifo_index_u32 = v_fifo_index_u32 +
  15527. C_BMI160_SIX_U8X;
  15528. v_accel_index_u8++;
  15529. break;
  15530. }
  15531. /* Header frame of gyro */
  15532. case FIFO_HEAD_G:
  15533. { /*fifo v_data_u8 frame index + 1*/
  15534. v_fifo_index_u32 = v_fifo_index_u32 + C_BMI160_ONE_U8X;
  15535. if ((v_fifo_index_u32 + C_BMI160_SIX_U8X) >
  15536. v_fifo_length_u32) {
  15537. v_last_return_stat_s8 = FIFO_G_OVER_LEN;
  15538. break;
  15539. }
  15540. /* Gyro raw x v_data_u8 */
  15541. gyro_fifo[v_gyro_index_u8].x =
  15542. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15543. C_BMI160_ONE_U8X])
  15544. << C_BMI160_EIGHT_U8X)
  15545. | (v_fifo_data_u8[v_fifo_index_u32 +
  15546. C_BMI160_ZERO_U8X]));
  15547. /* Gyro raw y v_data_u8 */
  15548. gyro_fifo[v_gyro_index_u8].y =
  15549. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15550. C_BMI160_THREE_U8X])
  15551. << C_BMI160_EIGHT_U8X)
  15552. | (v_fifo_data_u8[v_fifo_index_u32 +
  15553. C_BMI160_TWO_U8X]));
  15554. /* Gyro raw z v_data_u8 */
  15555. gyro_fifo[v_gyro_index_u8].z =
  15556. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15557. C_BMI160_FIVE_U8X])
  15558. << C_BMI160_EIGHT_U8X)
  15559. | (v_fifo_data_u8[v_fifo_index_u32 +
  15560. C_BMI160_FOUR_U8X]));
  15561. /*fifo G v_data_u8 frame index + 6*/
  15562. v_fifo_index_u32 = v_fifo_index_u32 +
  15563. C_BMI160_SIX_U8X;
  15564. v_gyro_index_u8++;
  15565. break;
  15566. }
  15567. /* Header frame of mag */
  15568. case FIFO_HEAD_M:
  15569. { /*fifo v_data_u8 frame index + 1*/
  15570. v_fifo_index_u32 = v_fifo_index_u32 + C_BMI160_ONE_U8X;
  15571. if ((v_fifo_index_u32 + C_BMI160_EIGHT_U8X) >
  15572. (v_fifo_length_u32)) {
  15573. v_last_return_stat_s8 = FIFO_M_OVER_LEN;
  15574. break;
  15575. }
  15576. /* Raw mag x*/
  15577. v_mag_data_s16 =
  15578. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15579. C_BMI160_ONE_U8X]) << C_BMI160_EIGHT_U8X)
  15580. | (v_fifo_data_u8[v_fifo_index_u32 +
  15581. C_BMI160_ZERO_U8X]));
  15582. v_mag_x_s16 = (s16) (v_mag_data_s16 >>
  15583. C_BMI160_THREE_U8X);
  15584. /* Raw mag y*/
  15585. v_mag_data_s16 =
  15586. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15587. C_BMI160_THREE_U8X])
  15588. << C_BMI160_EIGHT_U8X)
  15589. | (v_fifo_data_u8[v_fifo_index_u32 +
  15590. C_BMI160_TWO_U8X]));
  15591. v_mag_y_s16 = (s16) (v_mag_data_s16 >>
  15592. C_BMI160_THREE_U8X);
  15593. /* Raw mag z*/
  15594. v_mag_data_s16 =
  15595. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15596. C_BMI160_FIVE_U8X])
  15597. << C_BMI160_EIGHT_U8X)
  15598. | (v_fifo_data_u8[v_fifo_index_u32 +
  15599. C_BMI160_FOUR_U8X]));
  15600. v_mag_z_s16 = (s16)(v_mag_data_s16 >>
  15601. C_BMI160_ONE_U8X);
  15602. /* Raw mag r*/
  15603. v_mag_data_r_u16 =
  15604. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15605. C_BMI160_SEVEN_U8X])
  15606. << C_BMI160_EIGHT_U8X)
  15607. |(v_fifo_data_u8[v_fifo_index_u32 +
  15608. C_BMI160_SIX_U8X]));
  15609. v_mag_r_s16 = (u16) (v_mag_data_r_u16 >>
  15610. C_BMI160_TWO_U8X);
  15611. /* Compensated mag x v_data_u8 */
  15612. mag_fifo[v_mag_index_u8].x =
  15613. bmi160_bmm150_mag_compensate_X(v_mag_x_s16,
  15614. v_mag_r_s16);
  15615. /* Compensated mag y v_data_u8 */
  15616. mag_fifo[v_mag_index_u8].y =
  15617. bmi160_bmm150_mag_compensate_Y(v_mag_y_s16,
  15618. v_mag_r_s16);
  15619. /* Compensated mag z v_data_u8 */
  15620. mag_fifo[v_mag_index_u8].z =
  15621. bmi160_bmm150_mag_compensate_Z(v_mag_z_s16,
  15622. v_mag_r_s16);
  15623. v_mag_index_u8++;
  15624. /*fifo M v_data_u8 frame index + 8*/
  15625. v_fifo_index_u32 = v_fifo_index_u32 +
  15626. C_BMI160_EIGHT_U8X;
  15627. break;
  15628. }
  15629. /* Header frame of gyro and accel */
  15630. case FIFO_HEAD_G_A:
  15631. v_fifo_index_u32 = v_fifo_index_u32 +
  15632. C_BMI160_ONE_U8X;
  15633. if ((v_fifo_index_u32 + C_BMI160_SIX_U8X)
  15634. > v_fifo_length_u32) {
  15635. v_last_return_stat_s8 = FIFO_G_A_OVER_LEN;
  15636. break;
  15637. }
  15638. /* Raw gyro x */
  15639. gyro_fifo[v_gyro_index_u8].x =
  15640. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15641. C_BMI160_ONE_U8X]) << C_BMI160_EIGHT_U8X)
  15642. |(v_fifo_data_u8[v_fifo_index_u32 +
  15643. C_BMI160_ZERO_U8X]));
  15644. /* Raw gyro y */
  15645. gyro_fifo[v_gyro_index_u8].y =
  15646. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15647. C_BMI160_THREE_U8X]) << C_BMI160_EIGHT_U8X)
  15648. |(v_fifo_data_u8[v_fifo_index_u32 +
  15649. C_BMI160_TWO_U8X]));
  15650. /* Raw gyro z */
  15651. gyro_fifo[v_gyro_index_u8].z =
  15652. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15653. C_BMI160_FIVE_U8X]) << C_BMI160_EIGHT_U8X)
  15654. |(v_fifo_data_u8[v_fifo_index_u32 +
  15655. C_BMI160_FOUR_U8X]));
  15656. /* Raw accel x */
  15657. accel_fifo[v_accel_index_u8].x =
  15658. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15659. C_BMI160_SEVEN_U8X]) << C_BMI160_EIGHT_U8X)
  15660. |(v_fifo_data_u8[v_fifo_index_u32 +
  15661. C_BMI160_SIX_U8X]));
  15662. /* Raw accel y */
  15663. accel_fifo[v_accel_index_u8].y =
  15664. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15665. C_BMI160_NINE_U8X]) << C_BMI160_EIGHT_U8X)
  15666. |(v_fifo_data_u8[v_fifo_index_u32 +
  15667. C_BMI160_EIGHT_U8X]));
  15668. /* Raw accel z */
  15669. accel_fifo[v_accel_index_u8].z =
  15670. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15671. C_BMI160_ELEVEN_U8X]) << C_BMI160_EIGHT_U8X)
  15672. |(v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_TEN_U8X]));
  15673. /* Index added to 12 for gyro and accel*/
  15674. v_fifo_index_u32 = v_fifo_index_u32 +
  15675. C_BMI160_TWELVE_U8X;
  15676. v_gyro_index_u8++;
  15677. v_accel_index_u8++;
  15678. break;
  15679. /* Header frame of mag, gyro and accel */
  15680. case FIFO_HEAD_M_G_A:
  15681. { /*fifo v_data_u8 frame index + 1*/
  15682. v_fifo_index_u32 = v_fifo_index_u32 + C_BMI160_ONE_U8X;
  15683. if ((v_fifo_index_u32 + C_BMI160_TWENTY_U8X)
  15684. > (v_fifo_length_u32)) {
  15685. v_last_return_stat_s8 = FIFO_M_G_A_OVER_LEN;
  15686. break;
  15687. }
  15688. /* Mag raw x v_data_u8 */
  15689. v_mag_data_s16 =
  15690. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15691. C_BMI160_ONE_U8X])
  15692. << C_BMI160_EIGHT_U8X)
  15693. |(v_fifo_data_u8[v_fifo_index_u32 +
  15694. C_BMI160_ZERO_U8X]));
  15695. v_mag_x_s16 = (s16) (v_mag_data_s16 >>
  15696. C_BMI160_THREE_U8X);
  15697. /* Mag raw y v_data_u8 */
  15698. v_mag_data_s16 =
  15699. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15700. C_BMI160_THREE_U8X])
  15701. << C_BMI160_EIGHT_U8X)
  15702. |(v_fifo_data_u8[v_fifo_index_u32 +
  15703. C_BMI160_TWO_U8X]));
  15704. v_mag_y_s16 = (s16) (v_mag_data_s16 >>
  15705. C_BMI160_THREE_U8X);
  15706. /* Mag raw z v_data_u8 */
  15707. v_mag_data_s16 =
  15708. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15709. C_BMI160_FIVE_U8X])
  15710. << C_BMI160_EIGHT_U8X)
  15711. |(v_fifo_data_u8[v_fifo_index_u32 +
  15712. C_BMI160_FOUR_U8X]));
  15713. v_mag_z_s16 = (s16)(v_mag_data_s16 >>
  15714. C_BMI160_ONE_U8X);
  15715. /* Mag raw r v_data_u8 */
  15716. v_mag_data_r_u16 =
  15717. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15718. C_BMI160_SEVEN_U8X])
  15719. << C_BMI160_EIGHT_U8X)
  15720. |(v_fifo_data_u8[v_fifo_index_u32 +
  15721. C_BMI160_SIX_U8X]));
  15722. v_mag_r_s16 = (u16) (v_mag_data_r_u16 >>
  15723. C_BMI160_TWO_U8X);
  15724. /* Mag x compensation */
  15725. mag_fifo[v_mag_index_u8].x =
  15726. bmi160_bmm150_mag_compensate_X(v_mag_x_s16,
  15727. v_mag_r_s16);
  15728. /* Mag y compensation */
  15729. mag_fifo[v_mag_index_u8].y =
  15730. bmi160_bmm150_mag_compensate_Y(v_mag_y_s16,
  15731. v_mag_r_s16);
  15732. /* Mag z compensation */
  15733. mag_fifo[v_mag_index_u8].z =
  15734. bmi160_bmm150_mag_compensate_Z(v_mag_z_s16,
  15735. v_mag_r_s16);
  15736. /* Gyro raw x v_data_u8 */
  15737. gyro_fifo[v_gyro_index_u8].x =
  15738. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15739. C_BMI160_NINE_U8X])
  15740. << C_BMI160_EIGHT_U8X)
  15741. |(v_fifo_data_u8[v_fifo_index_u32 +
  15742. C_BMI160_EIGHT_U8X]));
  15743. /* Gyro raw y v_data_u8 */
  15744. gyro_fifo[v_gyro_index_u8].y =
  15745. (s16)(((v_fifo_data_u8[
  15746. v_fifo_index_u32 + C_BMI160_ELEVEN_U8X])
  15747. << C_BMI160_EIGHT_U8X)
  15748. |(v_fifo_data_u8[v_fifo_index_u32 +
  15749. C_BMI160_TEN_U8X]));
  15750. /* Gyro raw z v_data_u8 */
  15751. gyro_fifo[v_gyro_index_u8].z =
  15752. (s16)(((v_fifo_data_u8[
  15753. v_fifo_index_u32 + C_BMI160_THIRTEEN_U8X])
  15754. << C_BMI160_EIGHT_U8X)
  15755. |(v_fifo_data_u8[
  15756. v_fifo_index_u32 + C_BMI160_TWELVE_U8X]));
  15757. /* Accel raw x v_data_u8 */
  15758. accel_fifo[v_accel_index_u8].x =
  15759. (s16)(((v_fifo_data_u8[
  15760. v_fifo_index_u32 + C_BMI160_FIFTEEN_U8X])
  15761. << C_BMI160_EIGHT_U8X)
  15762. |(v_fifo_data_u8[v_fifo_index_u32 +
  15763. C_BMI160_FOURTEEN_U8X]));
  15764. /* Accel raw y v_data_u8 */
  15765. accel_fifo[v_accel_index_u8].y =
  15766. (s16)(((v_fifo_data_u8[
  15767. v_fifo_index_u32 + C_BMI160_SEVENTEEN_U8X])
  15768. << C_BMI160_EIGHT_U8X)
  15769. |(v_fifo_data_u8[v_fifo_index_u32 +
  15770. C_BMI160_SIXTEEN_U8X]));
  15771. /* Accel raw z v_data_u8 */
  15772. accel_fifo[v_accel_index_u8].z =
  15773. (s16)(((v_fifo_data_u8[
  15774. v_fifo_index_u32 + C_BMI160_NINETEEN_U8X])
  15775. << C_BMI160_EIGHT_U8X)
  15776. |(v_fifo_data_u8[v_fifo_index_u32 +
  15777. C_BMI160_EIGHTEEN_U8X]));
  15778. /* Index adde to 20 for mag, gyro and accel*/
  15779. v_fifo_index_u32 = v_fifo_index_u32 +
  15780. C_BMI160_TWENTY_U8X;
  15781. v_accel_index_u8++;
  15782. v_mag_index_u8++;
  15783. v_gyro_index_u8++;
  15784. break;
  15785. }
  15786. /* Header frame of mag and accel */
  15787. case FIFO_HEAD_M_A:
  15788. { /*fifo v_data_u8 frame index + 1*/
  15789. v_fifo_index_u32 = v_fifo_index_u32 + C_BMI160_ONE_U8X;
  15790. if ((v_fifo_index_u32 + C_BMI160_FOURTEEN_U8X)
  15791. > (v_fifo_length_u32)) {
  15792. v_last_return_stat_s8 = FIFO_M_A_OVER_LEN;
  15793. break;
  15794. }
  15795. /* mag raw x v_data_u8 */
  15796. v_mag_data_s16 =
  15797. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15798. C_BMI160_ONE_U8X])
  15799. << C_BMI160_EIGHT_U8X)
  15800. |(v_fifo_data_u8[v_fifo_index_u32 +
  15801. C_BMI160_ZERO_U8X]));
  15802. v_mag_x_s16 = (s16) (v_mag_data_s16 >>
  15803. C_BMI160_THREE_U8X);
  15804. /* mag raw y v_data_u8 */
  15805. v_mag_data_s16 =
  15806. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15807. C_BMI160_THREE_U8X])
  15808. << C_BMI160_EIGHT_U8X)
  15809. |(v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_TWO_U8X]));
  15810. v_mag_y_s16 = (s16) (v_mag_data_s16 >>
  15811. C_BMI160_THREE_U8X);
  15812. /* mag raw z v_data_u8 */
  15813. v_mag_data_s16 =
  15814. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15815. C_BMI160_FIVE_U8X])
  15816. << C_BMI160_EIGHT_U8X)
  15817. |(v_fifo_data_u8[v_fifo_index_u32 +
  15818. C_BMI160_FOUR_U8X]));
  15819. v_mag_z_s16 = (s16)(v_mag_data_s16 >>
  15820. C_BMI160_ONE_U8X);
  15821. /* mag raw r v_data_u8 */
  15822. v_mag_data_r_u16 =
  15823. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15824. C_BMI160_SEVEN_U8X])
  15825. << C_BMI160_EIGHT_U8X)
  15826. |(v_fifo_data_u8[v_fifo_index_u32 +
  15827. C_BMI160_SIX_U8X]));
  15828. v_mag_r_s16 = (u16) (v_mag_data_r_u16 >>
  15829. C_BMI160_TWO_U8X);
  15830. /* Mag x compensation */
  15831. mag_fifo[v_mag_index_u8].x =
  15832. bmi160_bmm150_mag_compensate_X(v_mag_x_s16,
  15833. v_mag_r_s16);
  15834. /* Mag y compensation */
  15835. mag_fifo[v_mag_index_u8].y =
  15836. bmi160_bmm150_mag_compensate_Y(v_mag_y_s16,
  15837. v_mag_r_s16);
  15838. /* Mag z compensation */
  15839. mag_fifo[v_mag_index_u8].z =
  15840. bmi160_bmm150_mag_compensate_Z(v_mag_z_s16,
  15841. v_mag_r_s16);
  15842. /* Accel raw x v_data_u8 */
  15843. accel_fifo[v_accel_index_u8].x =
  15844. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15845. C_BMI160_NINE_U8X])
  15846. << C_BMI160_EIGHT_U8X)
  15847. |(v_fifo_data_u8[v_fifo_index_u32 +
  15848. C_BMI160_EIGHT_U8X]));
  15849. /* Accel raw y v_data_u8 */
  15850. accel_fifo[v_accel_index_u8].y =
  15851. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15852. C_BMI160_ELEVEN_U8X])
  15853. << C_BMI160_EIGHT_U8X)
  15854. |(v_fifo_data_u8[v_fifo_index_u32 +
  15855. C_BMI160_TEN_U8X]));
  15856. /* Accel raw z v_data_u8 */
  15857. accel_fifo[v_accel_index_u8].z =
  15858. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15859. C_BMI160_THIRTEEN_U8X])
  15860. << C_BMI160_EIGHT_U8X)
  15861. |(v_fifo_data_u8[v_fifo_index_u32 +
  15862. C_BMI160_TWELVE_U8X]));
  15863. /*fifo AM v_data_u8 frame index + 14(8+6)*/
  15864. v_fifo_index_u32 = v_fifo_index_u32 +
  15865. C_BMI160_FOURTEEN_U8X;
  15866. v_accel_index_u8++;
  15867. v_mag_index_u8++;
  15868. break;
  15869. }
  15870. /* Header frame of mag and gyro */
  15871. case FIFO_HEAD_M_G:
  15872. {
  15873. /*fifo v_data_u8 frame index + 1*/
  15874. v_fifo_index_u32 = v_fifo_index_u32 + C_BMI160_ONE_U8X;
  15875. if ((v_fifo_index_u32 + C_BMI160_FOURTEEN_U8X)
  15876. > v_fifo_length_u32) {
  15877. v_last_return_stat_s8 = FIFO_M_G_OVER_LEN;
  15878. break;
  15879. }
  15880. /* Mag raw x v_data_u8 */
  15881. v_mag_data_s16 =
  15882. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15883. C_BMI160_ONE_U8X])
  15884. << C_BMI160_EIGHT_U8X)
  15885. |(v_fifo_data_u8[v_fifo_index_u32 +
  15886. C_BMI160_ZERO_U8X]));
  15887. v_mag_x_s16 = (s16) (v_mag_data_s16 >>
  15888. C_BMI160_THREE_U8X);
  15889. /* Mag raw y v_data_u8 */
  15890. v_mag_data_s16 =
  15891. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15892. C_BMI160_THREE_U8X])
  15893. << C_BMI160_EIGHT_U8X)
  15894. |(v_fifo_data_u8[v_fifo_index_u32 +
  15895. C_BMI160_TWO_U8X]));
  15896. v_mag_y_s16 = (s16) (v_mag_data_s16 >>
  15897. C_BMI160_THREE_U8X);
  15898. /* Mag raw z v_data_u8 */
  15899. v_mag_data_s16 =
  15900. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15901. C_BMI160_FIVE_U8X])
  15902. << C_BMI160_EIGHT_U8X)
  15903. |(v_fifo_data_u8[v_fifo_index_u32 +
  15904. C_BMI160_FOUR_U8X]));
  15905. v_mag_z_s16 = (s16)(v_mag_data_s16 >> C_BMI160_ONE_U8X);
  15906. /* Mag raw r v_data_u8 */
  15907. v_mag_data_r_u16 =
  15908. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15909. C_BMI160_SEVEN_U8X])
  15910. << C_BMI160_EIGHT_U8X)
  15911. |(v_fifo_data_u8[v_fifo_index_u32 +
  15912. C_BMI160_SIX_U8X]));
  15913. v_mag_r_s16 = (u16) (v_mag_data_r_u16 >>
  15914. C_BMI160_TWO_U8X);
  15915. /* Mag x compensation */
  15916. mag_fifo[v_mag_index_u8].x =
  15917. bmi160_bmm150_mag_compensate_X(v_mag_x_s16,
  15918. v_mag_r_s16);
  15919. /* Mag y compensation */
  15920. mag_fifo[v_mag_index_u8].y =
  15921. bmi160_bmm150_mag_compensate_Y(v_mag_y_s16,
  15922. v_mag_r_s16);
  15923. /* Mag z compensation */
  15924. mag_fifo[v_mag_index_u8].z =
  15925. bmi160_bmm150_mag_compensate_Z(v_mag_z_s16,
  15926. v_mag_r_s16);
  15927. /* Gyro raw x v_data_u8 */
  15928. gyro_fifo[v_gyro_index_u8].x =
  15929. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15930. C_BMI160_NINE_U8X])
  15931. << C_BMI160_EIGHT_U8X)
  15932. |(v_fifo_data_u8[v_fifo_index_u32 +
  15933. C_BMI160_EIGHT_U8X]));
  15934. /* Gyro raw y v_data_u8 */
  15935. gyro_fifo[v_gyro_index_u8].y =
  15936. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15937. C_BMI160_ELEVEN_U8X])
  15938. << C_BMI160_EIGHT_U8X)
  15939. |(v_fifo_data_u8[v_fifo_index_u32 +
  15940. C_BMI160_TEN_U8X]));
  15941. /* Gyro raw z v_data_u8 */
  15942. gyro_fifo[v_gyro_index_u8].z =
  15943. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  15944. C_BMI160_THIRTEEN_U8X])
  15945. << C_BMI160_EIGHT_U8X)
  15946. |(v_fifo_data_u8[v_fifo_index_u32 +
  15947. C_BMI160_TWELVE_U8X]));
  15948. /*fifo GM v_data_u8 frame index + 14(8+6)*/
  15949. v_fifo_index_u32 = v_fifo_index_u32 +
  15950. C_BMI160_FOURTEEN_U8X;
  15951. v_mag_index_u8++;
  15952. v_gyro_index_u8++;
  15953. break;
  15954. }
  15955. /* Header frame of sensor time */
  15956. case FIFO_HEAD_SENSOR_TIME:
  15957. {
  15958. v_fifo_index_u32 = v_fifo_index_u32 +
  15959. C_BMI160_ONE_U8X;
  15960. if ((v_fifo_index_u32 + C_BMI160_THREE_U8X) >
  15961. (v_fifo_length_u32)) {
  15962. v_last_return_stat_s8 = FIFO_SENSORTIME_RETURN;
  15963. break;
  15964. }
  15965. /* Sensor time */
  15966. V_fifo_time_U32 = (u32)
  15967. ((v_fifo_data_u8[v_fifo_index_u32 +
  15968. C_BMI160_TWO_U8X]
  15969. << C_BMI160_SIXTEEN_U8X) |
  15970. (v_fifo_data_u8[v_fifo_index_u32 +
  15971. C_BMI160_ONE_U8X]
  15972. << C_BMI160_EIGHT_U8X) |
  15973. (v_fifo_data_u8[v_fifo_index_u32 +
  15974. C_BMI160_ZERO_U8X]));
  15975. v_fifo_index_u32 = v_fifo_index_u32 +
  15976. C_BMI160_THREE_U8X;
  15977. break;
  15978. }
  15979. /* Header frame of skip frame */
  15980. case FIFO_HEAD_SKIP_FRAME:
  15981. {
  15982. /*fifo v_data_u8 frame index + 1*/
  15983. v_fifo_index_u32 = v_fifo_index_u32 +
  15984. C_BMI160_ONE_U8X;
  15985. if (v_fifo_index_u32 + C_BMI160_ONE_U8X
  15986. > v_fifo_length_u32) {
  15987. v_last_return_stat_s8 =
  15988. FIFO_SKIP_OVER_LEN;
  15989. break;
  15990. }
  15991. v_fifo_index_u32 = v_fifo_index_u32 +
  15992. C_BMI160_ONE_U8X;
  15993. break;
  15994. }
  15995. /* Header frame of over read fifo v_data_u8 */
  15996. case FIFO_HEAD_OVER_READ_LSB:
  15997. {
  15998. /*fifo v_data_u8 frame index + 1*/
  15999. v_fifo_index_u32 = v_fifo_index_u32 +
  16000. C_BMI160_ONE_U8X;
  16001. if ((v_fifo_index_u32 + C_BMI160_ONE_U8X)
  16002. > (v_fifo_length_u32)) {
  16003. v_last_return_stat_s8 = FIFO_OVER_READ_RETURN;
  16004. break;
  16005. }
  16006. if (v_fifo_data_u8[v_fifo_index_u32] ==
  16007. FIFO_HEAD_OVER_READ_MSB) {
  16008. /*fifo over read frame index + 1*/
  16009. v_fifo_index_u32 = v_fifo_index_u32 +
  16010. C_BMI160_ONE_U8X;
  16011. break;
  16012. } else {
  16013. v_last_return_stat_s8 = FIFO_OVER_READ_RETURN;
  16014. break;
  16015. }
  16016. }
  16017. default:
  16018. v_last_return_stat_s8 = C_BMI160_ONE_U8X;
  16019. break;
  16020. }
  16021. if (v_last_return_stat_s8)
  16022. break;
  16023. }
  16024. return com_rslt;
  16025. }
  16026. //add by lwy
  16027. BMI160_RETURN_FUNCTION_TYPE bmi160_read_accel_gyro_fifo_data(u8 *r_v_accel_index_u8, struct bmi160_accel_t **r_accel_fifo, u8 *r_v_gyro_index_u8,struct bmi160_gyro_t **r_gyro_fifo)
  16028. {
  16029. u32 v_fifo_length_u32 = FIFO_FRAME;
  16030. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  16031. u8 v_accel_index_u8 = C_BMI160_ZERO_U8X;
  16032. u8 v_gyro_index_u8 = C_BMI160_ZERO_U8X;
  16033. u8 v_mag_index_u8 = C_BMI160_ZERO_U8X;
  16034. s8 v_last_return_stat_s8 = C_BMI160_ZERO_U8X;
  16035. u32 v_fifo_index_u32 = C_BMI160_ZERO_U8X;
  16036. u16 v_mag_data_r_u16 = C_BMI160_ZERO_U8X;
  16037. u8 v_frame_head_u8 = C_BMI160_ZERO_U8X;
  16038. s16 v_mag_data_s16 = C_BMI160_ZERO_U8X;
  16039. s16 v_mag_x_s16, v_mag_y_s16, v_mag_z_s16 = C_BMI160_ZERO_U8X;
  16040. u16 v_mag_r_s16 = C_BMI160_ZERO_U8X;
  16041. /* read fifo v_data_u8*/
  16042. com_rslt = bmi160_fifo_data_get_set_integration(&v_fifo_data_u8[C_BMI160_ZERO_U8X],&v_fifo_length_u32);
  16043. for (v_fifo_index_u32 = C_BMI160_ZERO_U8X;
  16044. v_fifo_index_u32 < v_fifo_length_u32;) {
  16045. v_frame_head_u8 = v_fifo_data_u8[v_fifo_index_u32];
  16046. switch (v_frame_head_u8) {
  16047. /* Header frame of accel */
  16048. case FIFO_HEAD_A:
  16049. { /*fifo v_data_u8 frame index + 1*/
  16050. v_fifo_index_u32 = v_fifo_index_u32 +
  16051. C_BMI160_ONE_U8X;
  16052. if ((v_fifo_index_u32 + C_BMI160_SIX_U8X)
  16053. > v_fifo_length_u32) {
  16054. v_last_return_stat_s8 = FIFO_A_OVER_LEN;
  16055. break;
  16056. }
  16057. /* Accel raw x v_data_u8 */
  16058. accel_fifo[v_accel_index_u8].x =
  16059. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16060. C_BMI160_ONE_U8X]) << C_BMI160_EIGHT_U8X)
  16061. | (v_fifo_data_u8[v_fifo_index_u32 +
  16062. C_BMI160_ZERO_U8X]));
  16063. /* Accel raw y v_data_u8 */
  16064. accel_fifo[v_accel_index_u8].y =
  16065. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16066. C_BMI160_THREE_U8X]) << C_BMI160_EIGHT_U8X)
  16067. | (v_fifo_data_u8[v_fifo_index_u32 +
  16068. C_BMI160_TWO_U8X]));
  16069. /* Accel raw z v_data_u8 */
  16070. accel_fifo[v_accel_index_u8].z =
  16071. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16072. C_BMI160_FIVE_U8X]) << C_BMI160_EIGHT_U8X)
  16073. | (v_fifo_data_u8[v_fifo_index_u32 +
  16074. C_BMI160_FOUR_U8X]));
  16075. /* index adde to 6 accel alone*/
  16076. v_fifo_index_u32 = v_fifo_index_u32 +
  16077. C_BMI160_SIX_U8X;
  16078. v_accel_index_u8++;
  16079. //add by lwy
  16080. static int16_t acc_int16t[3];
  16081. acc_int16t[0] = accel_fifo[v_accel_index_u8].x;
  16082. acc_int16t[1] = accel_fifo[v_accel_index_u8].y;
  16083. acc_int16t[2] = -accel_fifo[v_accel_index_u8].z;
  16084. extern void detect_step_by_acc(int16_t *acc);
  16085. detect_step_by_acc(acc_int16t);
  16086. break;
  16087. }
  16088. /* Header frame of gyro */
  16089. case FIFO_HEAD_G:
  16090. { /*fifo v_data_u8 frame index + 1*/
  16091. v_fifo_index_u32 = v_fifo_index_u32 + C_BMI160_ONE_U8X;
  16092. if ((v_fifo_index_u32 + C_BMI160_SIX_U8X) >
  16093. v_fifo_length_u32) {
  16094. v_last_return_stat_s8 = FIFO_G_OVER_LEN;
  16095. break;
  16096. }
  16097. /* Gyro raw x v_data_u8 */
  16098. gyro_fifo[v_gyro_index_u8].x =
  16099. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16100. C_BMI160_ONE_U8X])
  16101. << C_BMI160_EIGHT_U8X)
  16102. | (v_fifo_data_u8[v_fifo_index_u32 +
  16103. C_BMI160_ZERO_U8X]));
  16104. /* Gyro raw y v_data_u8 */
  16105. gyro_fifo[v_gyro_index_u8].y =
  16106. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16107. C_BMI160_THREE_U8X])
  16108. << C_BMI160_EIGHT_U8X)
  16109. | (v_fifo_data_u8[v_fifo_index_u32 +
  16110. C_BMI160_TWO_U8X]));
  16111. /* Gyro raw z v_data_u8 */
  16112. gyro_fifo[v_gyro_index_u8].z =
  16113. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16114. C_BMI160_FIVE_U8X])
  16115. << C_BMI160_EIGHT_U8X)
  16116. | (v_fifo_data_u8[v_fifo_index_u32 +
  16117. C_BMI160_FOUR_U8X]));
  16118. /*fifo G v_data_u8 frame index + 6*/
  16119. v_fifo_index_u32 = v_fifo_index_u32 +
  16120. C_BMI160_SIX_U8X;
  16121. v_gyro_index_u8++;
  16122. break;
  16123. }
  16124. /* Header frame of mag */
  16125. case FIFO_HEAD_M:
  16126. { /*fifo v_data_u8 frame index + 1*/
  16127. v_fifo_index_u32 = v_fifo_index_u32 + C_BMI160_ONE_U8X;
  16128. if ((v_fifo_index_u32 + C_BMI160_EIGHT_U8X) >
  16129. (v_fifo_length_u32)) {
  16130. v_last_return_stat_s8 = FIFO_M_OVER_LEN;
  16131. break;
  16132. }
  16133. /* Raw mag x*/
  16134. v_mag_data_s16 =
  16135. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16136. C_BMI160_ONE_U8X]) << C_BMI160_EIGHT_U8X)
  16137. | (v_fifo_data_u8[v_fifo_index_u32 +
  16138. C_BMI160_ZERO_U8X]));
  16139. v_mag_x_s16 = (s16) (v_mag_data_s16 >>
  16140. C_BMI160_THREE_U8X);
  16141. /* Raw mag y*/
  16142. v_mag_data_s16 =
  16143. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16144. C_BMI160_THREE_U8X])
  16145. << C_BMI160_EIGHT_U8X)
  16146. | (v_fifo_data_u8[v_fifo_index_u32 +
  16147. C_BMI160_TWO_U8X]));
  16148. v_mag_y_s16 = (s16) (v_mag_data_s16 >>
  16149. C_BMI160_THREE_U8X);
  16150. /* Raw mag z*/
  16151. v_mag_data_s16 =
  16152. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16153. C_BMI160_FIVE_U8X])
  16154. << C_BMI160_EIGHT_U8X)
  16155. | (v_fifo_data_u8[v_fifo_index_u32 +
  16156. C_BMI160_FOUR_U8X]));
  16157. v_mag_z_s16 = (s16)(v_mag_data_s16 >>
  16158. C_BMI160_ONE_U8X);
  16159. /* Raw mag r*/
  16160. v_mag_data_r_u16 =
  16161. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16162. C_BMI160_SEVEN_U8X])
  16163. << C_BMI160_EIGHT_U8X)
  16164. |(v_fifo_data_u8[v_fifo_index_u32 +
  16165. C_BMI160_SIX_U8X]));
  16166. v_mag_r_s16 = (u16) (v_mag_data_r_u16 >>
  16167. C_BMI160_TWO_U8X);
  16168. /* Compensated mag x v_data_u8 */
  16169. mag_fifo[v_mag_index_u8].x =
  16170. bmi160_bmm150_mag_compensate_X(v_mag_x_s16,
  16171. v_mag_r_s16);
  16172. /* Compensated mag y v_data_u8 */
  16173. mag_fifo[v_mag_index_u8].y =
  16174. bmi160_bmm150_mag_compensate_Y(v_mag_y_s16,
  16175. v_mag_r_s16);
  16176. /* Compensated mag z v_data_u8 */
  16177. mag_fifo[v_mag_index_u8].z =
  16178. bmi160_bmm150_mag_compensate_Z(v_mag_z_s16,
  16179. v_mag_r_s16);
  16180. v_mag_index_u8++;
  16181. /*fifo M v_data_u8 frame index + 8*/
  16182. v_fifo_index_u32 = v_fifo_index_u32 +
  16183. C_BMI160_EIGHT_U8X;
  16184. break;
  16185. }
  16186. /* Header frame of gyro and accel */
  16187. case FIFO_HEAD_G_A:
  16188. v_fifo_index_u32 = v_fifo_index_u32 +
  16189. C_BMI160_ONE_U8X;
  16190. if ((v_fifo_index_u32 + C_BMI160_SIX_U8X)
  16191. > v_fifo_length_u32) {
  16192. v_last_return_stat_s8 = FIFO_G_A_OVER_LEN;
  16193. break;
  16194. }
  16195. /* Raw gyro x */
  16196. gyro_fifo[v_gyro_index_u8].x =
  16197. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16198. C_BMI160_ONE_U8X]) << C_BMI160_EIGHT_U8X)
  16199. |(v_fifo_data_u8[v_fifo_index_u32 +
  16200. C_BMI160_ZERO_U8X]));
  16201. /* Raw gyro y */
  16202. gyro_fifo[v_gyro_index_u8].y =
  16203. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16204. C_BMI160_THREE_U8X]) << C_BMI160_EIGHT_U8X)
  16205. |(v_fifo_data_u8[v_fifo_index_u32 +
  16206. C_BMI160_TWO_U8X]));
  16207. /* Raw gyro z */
  16208. gyro_fifo[v_gyro_index_u8].z =
  16209. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16210. C_BMI160_FIVE_U8X]) << C_BMI160_EIGHT_U8X)
  16211. |(v_fifo_data_u8[v_fifo_index_u32 +
  16212. C_BMI160_FOUR_U8X]));
  16213. /* Raw accel x */
  16214. accel_fifo[v_accel_index_u8].x =
  16215. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16216. C_BMI160_SEVEN_U8X]) << C_BMI160_EIGHT_U8X)
  16217. |(v_fifo_data_u8[v_fifo_index_u32 +
  16218. C_BMI160_SIX_U8X]));
  16219. /* Raw accel y */
  16220. accel_fifo[v_accel_index_u8].y =
  16221. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16222. C_BMI160_NINE_U8X]) << C_BMI160_EIGHT_U8X)
  16223. |(v_fifo_data_u8[v_fifo_index_u32 +
  16224. C_BMI160_EIGHT_U8X]));
  16225. /* Raw accel z */
  16226. accel_fifo[v_accel_index_u8].z =
  16227. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16228. C_BMI160_ELEVEN_U8X]) << C_BMI160_EIGHT_U8X)
  16229. |(v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_TEN_U8X]));
  16230. /* Index added to 12 for gyro and accel*/
  16231. v_fifo_index_u32 = v_fifo_index_u32 +
  16232. C_BMI160_TWELVE_U8X;
  16233. v_gyro_index_u8++;
  16234. v_accel_index_u8++;
  16235. break;
  16236. /* Header frame of mag, gyro and accel */
  16237. case FIFO_HEAD_M_G_A:
  16238. { /*fifo v_data_u8 frame index + 1*/
  16239. v_fifo_index_u32 = v_fifo_index_u32 + C_BMI160_ONE_U8X;
  16240. if ((v_fifo_index_u32 + C_BMI160_TWENTY_U8X)
  16241. > (v_fifo_length_u32)) {
  16242. v_last_return_stat_s8 = FIFO_M_G_A_OVER_LEN;
  16243. break;
  16244. }
  16245. /* Mag raw x v_data_u8 */
  16246. v_mag_data_s16 =
  16247. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16248. C_BMI160_ONE_U8X])
  16249. << C_BMI160_EIGHT_U8X)
  16250. |(v_fifo_data_u8[v_fifo_index_u32 +
  16251. C_BMI160_ZERO_U8X]));
  16252. v_mag_x_s16 = (s16) (v_mag_data_s16 >>
  16253. C_BMI160_THREE_U8X);
  16254. /* Mag raw y v_data_u8 */
  16255. v_mag_data_s16 =
  16256. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16257. C_BMI160_THREE_U8X])
  16258. << C_BMI160_EIGHT_U8X)
  16259. |(v_fifo_data_u8[v_fifo_index_u32 +
  16260. C_BMI160_TWO_U8X]));
  16261. v_mag_y_s16 = (s16) (v_mag_data_s16 >>
  16262. C_BMI160_THREE_U8X);
  16263. /* Mag raw z v_data_u8 */
  16264. v_mag_data_s16 =
  16265. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16266. C_BMI160_FIVE_U8X])
  16267. << C_BMI160_EIGHT_U8X)
  16268. |(v_fifo_data_u8[v_fifo_index_u32 +
  16269. C_BMI160_FOUR_U8X]));
  16270. v_mag_z_s16 = (s16)(v_mag_data_s16 >>
  16271. C_BMI160_ONE_U8X);
  16272. /* Mag raw r v_data_u8 */
  16273. v_mag_data_r_u16 =
  16274. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16275. C_BMI160_SEVEN_U8X])
  16276. << C_BMI160_EIGHT_U8X)
  16277. |(v_fifo_data_u8[v_fifo_index_u32 +
  16278. C_BMI160_SIX_U8X]));
  16279. v_mag_r_s16 = (u16) (v_mag_data_r_u16 >>
  16280. C_BMI160_TWO_U8X);
  16281. /* Mag x compensation */
  16282. mag_fifo[v_mag_index_u8].x =
  16283. bmi160_bmm150_mag_compensate_X(v_mag_x_s16,
  16284. v_mag_r_s16);
  16285. /* Mag y compensation */
  16286. mag_fifo[v_mag_index_u8].y =
  16287. bmi160_bmm150_mag_compensate_Y(v_mag_y_s16,
  16288. v_mag_r_s16);
  16289. /* Mag z compensation */
  16290. mag_fifo[v_mag_index_u8].z =
  16291. bmi160_bmm150_mag_compensate_Z(v_mag_z_s16,
  16292. v_mag_r_s16);
  16293. /* Gyro raw x v_data_u8 */
  16294. gyro_fifo[v_gyro_index_u8].x =
  16295. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16296. C_BMI160_NINE_U8X])
  16297. << C_BMI160_EIGHT_U8X)
  16298. |(v_fifo_data_u8[v_fifo_index_u32 +
  16299. C_BMI160_EIGHT_U8X]));
  16300. /* Gyro raw y v_data_u8 */
  16301. gyro_fifo[v_gyro_index_u8].y =
  16302. (s16)(((v_fifo_data_u8[
  16303. v_fifo_index_u32 + C_BMI160_ELEVEN_U8X])
  16304. << C_BMI160_EIGHT_U8X)
  16305. |(v_fifo_data_u8[v_fifo_index_u32 +
  16306. C_BMI160_TEN_U8X]));
  16307. /* Gyro raw z v_data_u8 */
  16308. gyro_fifo[v_gyro_index_u8].z =
  16309. (s16)(((v_fifo_data_u8[
  16310. v_fifo_index_u32 + C_BMI160_THIRTEEN_U8X])
  16311. << C_BMI160_EIGHT_U8X)
  16312. |(v_fifo_data_u8[
  16313. v_fifo_index_u32 + C_BMI160_TWELVE_U8X]));
  16314. /* Accel raw x v_data_u8 */
  16315. accel_fifo[v_accel_index_u8].x =
  16316. (s16)(((v_fifo_data_u8[
  16317. v_fifo_index_u32 + C_BMI160_FIFTEEN_U8X])
  16318. << C_BMI160_EIGHT_U8X)
  16319. |(v_fifo_data_u8[v_fifo_index_u32 +
  16320. C_BMI160_FOURTEEN_U8X]));
  16321. /* Accel raw y v_data_u8 */
  16322. accel_fifo[v_accel_index_u8].y =
  16323. (s16)(((v_fifo_data_u8[
  16324. v_fifo_index_u32 + C_BMI160_SEVENTEEN_U8X])
  16325. << C_BMI160_EIGHT_U8X)
  16326. |(v_fifo_data_u8[v_fifo_index_u32 +
  16327. C_BMI160_SIXTEEN_U8X]));
  16328. /* Accel raw z v_data_u8 */
  16329. accel_fifo[v_accel_index_u8].z =
  16330. (s16)(((v_fifo_data_u8[
  16331. v_fifo_index_u32 + C_BMI160_NINETEEN_U8X])
  16332. << C_BMI160_EIGHT_U8X)
  16333. |(v_fifo_data_u8[v_fifo_index_u32 +
  16334. C_BMI160_EIGHTEEN_U8X]));
  16335. /* Index adde to 20 for mag, gyro and accel*/
  16336. v_fifo_index_u32 = v_fifo_index_u32 +
  16337. C_BMI160_TWENTY_U8X;
  16338. v_accel_index_u8++;
  16339. v_mag_index_u8++;
  16340. v_gyro_index_u8++;
  16341. break;
  16342. }
  16343. /* Header frame of mag and accel */
  16344. case FIFO_HEAD_M_A:
  16345. { /*fifo v_data_u8 frame index + 1*/
  16346. v_fifo_index_u32 = v_fifo_index_u32 + C_BMI160_ONE_U8X;
  16347. if ((v_fifo_index_u32 + C_BMI160_FOURTEEN_U8X)
  16348. > (v_fifo_length_u32)) {
  16349. v_last_return_stat_s8 = FIFO_M_A_OVER_LEN;
  16350. break;
  16351. }
  16352. /* mag raw x v_data_u8 */
  16353. v_mag_data_s16 =
  16354. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16355. C_BMI160_ONE_U8X])
  16356. << C_BMI160_EIGHT_U8X)
  16357. |(v_fifo_data_u8[v_fifo_index_u32 +
  16358. C_BMI160_ZERO_U8X]));
  16359. v_mag_x_s16 = (s16) (v_mag_data_s16 >>
  16360. C_BMI160_THREE_U8X);
  16361. /* mag raw y v_data_u8 */
  16362. v_mag_data_s16 =
  16363. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16364. C_BMI160_THREE_U8X])
  16365. << C_BMI160_EIGHT_U8X)
  16366. |(v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_TWO_U8X]));
  16367. v_mag_y_s16 = (s16) (v_mag_data_s16 >>
  16368. C_BMI160_THREE_U8X);
  16369. /* mag raw z v_data_u8 */
  16370. v_mag_data_s16 =
  16371. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16372. C_BMI160_FIVE_U8X])
  16373. << C_BMI160_EIGHT_U8X)
  16374. |(v_fifo_data_u8[v_fifo_index_u32 +
  16375. C_BMI160_FOUR_U8X]));
  16376. v_mag_z_s16 = (s16)(v_mag_data_s16 >>
  16377. C_BMI160_ONE_U8X);
  16378. /* mag raw r v_data_u8 */
  16379. v_mag_data_r_u16 =
  16380. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16381. C_BMI160_SEVEN_U8X])
  16382. << C_BMI160_EIGHT_U8X)
  16383. |(v_fifo_data_u8[v_fifo_index_u32 +
  16384. C_BMI160_SIX_U8X]));
  16385. v_mag_r_s16 = (u16) (v_mag_data_r_u16 >>
  16386. C_BMI160_TWO_U8X);
  16387. /* Mag x compensation */
  16388. mag_fifo[v_mag_index_u8].x =
  16389. bmi160_bmm150_mag_compensate_X(v_mag_x_s16,
  16390. v_mag_r_s16);
  16391. /* Mag y compensation */
  16392. mag_fifo[v_mag_index_u8].y =
  16393. bmi160_bmm150_mag_compensate_Y(v_mag_y_s16,
  16394. v_mag_r_s16);
  16395. /* Mag z compensation */
  16396. mag_fifo[v_mag_index_u8].z =
  16397. bmi160_bmm150_mag_compensate_Z(v_mag_z_s16,
  16398. v_mag_r_s16);
  16399. /* Accel raw x v_data_u8 */
  16400. accel_fifo[v_accel_index_u8].x =
  16401. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16402. C_BMI160_NINE_U8X])
  16403. << C_BMI160_EIGHT_U8X)
  16404. |(v_fifo_data_u8[v_fifo_index_u32 +
  16405. C_BMI160_EIGHT_U8X]));
  16406. /* Accel raw y v_data_u8 */
  16407. accel_fifo[v_accel_index_u8].y =
  16408. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16409. C_BMI160_ELEVEN_U8X])
  16410. << C_BMI160_EIGHT_U8X)
  16411. |(v_fifo_data_u8[v_fifo_index_u32 +
  16412. C_BMI160_TEN_U8X]));
  16413. /* Accel raw z v_data_u8 */
  16414. accel_fifo[v_accel_index_u8].z =
  16415. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16416. C_BMI160_THIRTEEN_U8X])
  16417. << C_BMI160_EIGHT_U8X)
  16418. |(v_fifo_data_u8[v_fifo_index_u32 +
  16419. C_BMI160_TWELVE_U8X]));
  16420. /*fifo AM v_data_u8 frame index + 14(8+6)*/
  16421. v_fifo_index_u32 = v_fifo_index_u32 +
  16422. C_BMI160_FOURTEEN_U8X;
  16423. v_accel_index_u8++;
  16424. v_mag_index_u8++;
  16425. break;
  16426. }
  16427. /* Header frame of mag and gyro */
  16428. case FIFO_HEAD_M_G:
  16429. {
  16430. /*fifo v_data_u8 frame index + 1*/
  16431. v_fifo_index_u32 = v_fifo_index_u32 + C_BMI160_ONE_U8X;
  16432. if ((v_fifo_index_u32 + C_BMI160_FOURTEEN_U8X)
  16433. > v_fifo_length_u32) {
  16434. v_last_return_stat_s8 = FIFO_M_G_OVER_LEN;
  16435. break;
  16436. }
  16437. /* Mag raw x v_data_u8 */
  16438. v_mag_data_s16 =
  16439. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16440. C_BMI160_ONE_U8X])
  16441. << C_BMI160_EIGHT_U8X)
  16442. |(v_fifo_data_u8[v_fifo_index_u32 +
  16443. C_BMI160_ZERO_U8X]));
  16444. v_mag_x_s16 = (s16) (v_mag_data_s16 >>
  16445. C_BMI160_THREE_U8X);
  16446. /* Mag raw y v_data_u8 */
  16447. v_mag_data_s16 =
  16448. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16449. C_BMI160_THREE_U8X])
  16450. << C_BMI160_EIGHT_U8X)
  16451. |(v_fifo_data_u8[v_fifo_index_u32 +
  16452. C_BMI160_TWO_U8X]));
  16453. v_mag_y_s16 = (s16) (v_mag_data_s16 >>
  16454. C_BMI160_THREE_U8X);
  16455. /* Mag raw z v_data_u8 */
  16456. v_mag_data_s16 =
  16457. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16458. C_BMI160_FIVE_U8X])
  16459. << C_BMI160_EIGHT_U8X)
  16460. |(v_fifo_data_u8[v_fifo_index_u32 +
  16461. C_BMI160_FOUR_U8X]));
  16462. v_mag_z_s16 = (s16)(v_mag_data_s16 >> C_BMI160_ONE_U8X);
  16463. /* Mag raw r v_data_u8 */
  16464. v_mag_data_r_u16 =
  16465. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16466. C_BMI160_SEVEN_U8X])
  16467. << C_BMI160_EIGHT_U8X)
  16468. |(v_fifo_data_u8[v_fifo_index_u32 +
  16469. C_BMI160_SIX_U8X]));
  16470. v_mag_r_s16 = (u16) (v_mag_data_r_u16 >>
  16471. C_BMI160_TWO_U8X);
  16472. /* Mag x compensation */
  16473. mag_fifo[v_mag_index_u8].x =
  16474. bmi160_bmm150_mag_compensate_X(v_mag_x_s16,
  16475. v_mag_r_s16);
  16476. /* Mag y compensation */
  16477. mag_fifo[v_mag_index_u8].y =
  16478. bmi160_bmm150_mag_compensate_Y(v_mag_y_s16,
  16479. v_mag_r_s16);
  16480. /* Mag z compensation */
  16481. mag_fifo[v_mag_index_u8].z =
  16482. bmi160_bmm150_mag_compensate_Z(v_mag_z_s16,
  16483. v_mag_r_s16);
  16484. /* Gyro raw x v_data_u8 */
  16485. gyro_fifo[v_gyro_index_u8].x =
  16486. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16487. C_BMI160_NINE_U8X])
  16488. << C_BMI160_EIGHT_U8X)
  16489. |(v_fifo_data_u8[v_fifo_index_u32 +
  16490. C_BMI160_EIGHT_U8X]));
  16491. /* Gyro raw y v_data_u8 */
  16492. gyro_fifo[v_gyro_index_u8].y =
  16493. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16494. C_BMI160_ELEVEN_U8X])
  16495. << C_BMI160_EIGHT_U8X)
  16496. |(v_fifo_data_u8[v_fifo_index_u32 +
  16497. C_BMI160_TEN_U8X]));
  16498. /* Gyro raw z v_data_u8 */
  16499. gyro_fifo[v_gyro_index_u8].z =
  16500. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16501. C_BMI160_THIRTEEN_U8X])
  16502. << C_BMI160_EIGHT_U8X)
  16503. |(v_fifo_data_u8[v_fifo_index_u32 +
  16504. C_BMI160_TWELVE_U8X]));
  16505. /*fifo GM v_data_u8 frame index + 14(8+6)*/
  16506. v_fifo_index_u32 = v_fifo_index_u32 +
  16507. C_BMI160_FOURTEEN_U8X;
  16508. v_mag_index_u8++;
  16509. v_gyro_index_u8++;
  16510. break;
  16511. }
  16512. /* Header frame of sensor time */
  16513. case FIFO_HEAD_SENSOR_TIME:
  16514. {
  16515. v_fifo_index_u32 = v_fifo_index_u32 +
  16516. C_BMI160_ONE_U8X;
  16517. if ((v_fifo_index_u32 + C_BMI160_THREE_U8X) >
  16518. (v_fifo_length_u32)) {
  16519. v_last_return_stat_s8 = FIFO_SENSORTIME_RETURN;
  16520. break;
  16521. }
  16522. /* Sensor time */
  16523. V_fifo_time_U32 = (u32)
  16524. ((v_fifo_data_u8[v_fifo_index_u32 +
  16525. C_BMI160_TWO_U8X]
  16526. << C_BMI160_SIXTEEN_U8X) |
  16527. (v_fifo_data_u8[v_fifo_index_u32 +
  16528. C_BMI160_ONE_U8X]
  16529. << C_BMI160_EIGHT_U8X) |
  16530. (v_fifo_data_u8[v_fifo_index_u32 +
  16531. C_BMI160_ZERO_U8X]));
  16532. v_fifo_index_u32 = v_fifo_index_u32 +
  16533. C_BMI160_THREE_U8X;
  16534. break;
  16535. }
  16536. /* Header frame of skip frame */
  16537. case FIFO_HEAD_SKIP_FRAME:
  16538. {
  16539. /*fifo v_data_u8 frame index + 1*/
  16540. v_fifo_index_u32 = v_fifo_index_u32 +
  16541. C_BMI160_ONE_U8X;
  16542. if (v_fifo_index_u32 + C_BMI160_ONE_U8X
  16543. > v_fifo_length_u32) {
  16544. v_last_return_stat_s8 =
  16545. FIFO_SKIP_OVER_LEN;
  16546. break;
  16547. }
  16548. v_fifo_index_u32 = v_fifo_index_u32 +
  16549. C_BMI160_ONE_U8X;
  16550. break;
  16551. }
  16552. /* Header frame of over read fifo v_data_u8 */
  16553. case FIFO_HEAD_OVER_READ_LSB:
  16554. {
  16555. /*fifo v_data_u8 frame index + 1*/
  16556. v_fifo_index_u32 = v_fifo_index_u32 +
  16557. C_BMI160_ONE_U8X;
  16558. if ((v_fifo_index_u32 + C_BMI160_ONE_U8X)
  16559. > (v_fifo_length_u32)) {
  16560. v_last_return_stat_s8 = FIFO_OVER_READ_RETURN;
  16561. break;
  16562. }
  16563. if (v_fifo_data_u8[v_fifo_index_u32] ==
  16564. FIFO_HEAD_OVER_READ_MSB) {
  16565. /*fifo over read frame index + 1*/
  16566. v_fifo_index_u32 = v_fifo_index_u32 +
  16567. C_BMI160_ONE_U8X;
  16568. break;
  16569. } else {
  16570. v_last_return_stat_s8 = FIFO_OVER_READ_RETURN;
  16571. break;
  16572. }
  16573. }
  16574. default:
  16575. v_last_return_stat_s8 = C_BMI160_ONE_U8X;
  16576. break;
  16577. }
  16578. if (v_last_return_stat_s8)
  16579. break;
  16580. }
  16581. if(r_v_accel_index_u8 != 0)
  16582. *r_v_accel_index_u8 = v_accel_index_u8;
  16583. if(r_accel_fifo != 0)
  16584. *r_accel_fifo = accel_fifo;
  16585. if(r_v_gyro_index_u8 != 0)
  16586. *r_v_gyro_index_u8 = v_gyro_index_u8;
  16587. if(r_gyro_fifo != 0)
  16588. *r_gyro_fifo = gyro_fifo;
  16589. // u32 i;
  16590. // for(i=0;i<v_accel_index_u8;i++)
  16591. // {
  16592. //// SEGGER_RTT_printf(0,"err:%d a[%d].x:%d a[%d].y:%d a[%d].z:%d\r\n",com_rslt,i,accel_fifo[i].x,i,accel_fifo[i].y,i,accel_fifo[i].z);
  16593. // SEGGER_RTT_printf(0,"err:%d a[%d].x:%d a[%d].y:%d a[%d].z:%d\r\n",com_rslt,i,r_accel_fifo[i].x,i,r_accel_fifo[i].y,i,r_accel_fifo[i].z);
  16594. // }
  16595. return com_rslt;
  16596. }
  16597. /*!
  16598. * @brief This function used for reading the
  16599. * fifo data of header less mode
  16600. *
  16601. * @param v_fifo_length_u32 : The value of FIFO length
  16602. *
  16603. *
  16604. * @note Configure the below functions for FIFO header less mode
  16605. * @note 1. bmi160_set_fifo_down_gyro
  16606. * @note 2. bmi160_set_gyro_fifo_filter_data
  16607. * @note 3. bmi160_set_fifo_down_accel
  16608. * @note 4. bmi160_set_accel_fifo_filter_dat
  16609. * @note 5. bmi160_set_fifo_mag_enable
  16610. * @note 6. bmi160_set_fifo_accel_enable
  16611. * @note 7. bmi160_set_fifo_gyro_enable
  16612. * @note For interrupt configuration
  16613. * @note 1. bmi160_set_intr_fifo_full
  16614. * @note 2. bmi160_set_intr_fifo_wm
  16615. * @note 3. bmi160_set_fifo_tag_intr2_enable
  16616. * @note 4. bmi160_set_fifo_tag_intr1_enable
  16617. *
  16618. *
  16619. * @return results of bus communication function
  16620. * @retval 0 -> Success
  16621. * @retval -1 -> Error
  16622. *
  16623. *
  16624. */
  16625. BMI160_RETURN_FUNCTION_TYPE bmi160_read_fifo_headerless_mode(
  16626. u32 v_fifo_length_u32) {
  16627. u8 mag_en = C_BMI160_ZERO_U8X;
  16628. u8 accel_en = C_BMI160_ZERO_U8X;
  16629. u8 gyro_en = C_BMI160_ZERO_U8X;
  16630. u32 v_fifo_index_u32 = C_BMI160_ZERO_U8X;
  16631. s16 v_mag_data_s16 = C_BMI160_ZERO_U8X;
  16632. u16 v_mag_data_r_u16 = C_BMI160_ZERO_U8X;
  16633. u16 v_mag_r_s16 = C_BMI160_ZERO_U8X;
  16634. s16 v_mag_x_s16, v_mag_y_s16, v_mag_z_s16 = C_BMI160_ZERO_U8X;
  16635. u8 v_accel_index_u8 = C_BMI160_ZERO_U8X;
  16636. u8 v_gyro_index_u8 = C_BMI160_ZERO_U8X;
  16637. u8 v_mag_index_u8 = C_BMI160_ZERO_U8X;
  16638. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  16639. /* disable the header data */
  16640. com_rslt = bmi160_set_fifo_header_enable(C_BMI160_ZERO_U8X);
  16641. /* read the mag enable status*/
  16642. com_rslt += bmi160_get_fifo_mag_enable(&mag_en);
  16643. /* read the accel enable status*/
  16644. com_rslt += bmi160_get_fifo_accel_enable(&accel_en);
  16645. /* read the gyro enable status*/
  16646. com_rslt += bmi160_get_fifo_gyro_enable(&gyro_en);
  16647. /* read the fifo data of 1024 bytes*/
  16648. com_rslt += bmi160_fifo_data(&v_fifo_data_u8[C_BMI160_ZERO_U8X]);
  16649. /* loop for executing the different conditions */
  16650. for (v_fifo_index_u32 = C_BMI160_ZERO_U8X;
  16651. v_fifo_index_u32 < v_fifo_length_u32;) {
  16652. /* condition for mag, gyro and accel enable*/
  16653. if ((mag_en == C_BMI160_ONE_U8X) &&
  16654. (gyro_en == C_BMI160_ONE_U8X)
  16655. && (accel_en == C_BMI160_ONE_U8X)) {
  16656. /* Raw mag x*/
  16657. v_mag_data_s16 =
  16658. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16659. C_BMI160_ONE_U8X])
  16660. << C_BMI160_EIGHT_U8X)
  16661. |(v_fifo_data_u8[v_fifo_index_u32 +
  16662. C_BMI160_ZERO_U8X]));
  16663. v_mag_x_s16 = (s16) (v_mag_data_s16 >>
  16664. C_BMI160_THREE_U8X);
  16665. /* Raw mag y*/
  16666. v_mag_data_s16 =
  16667. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16668. C_BMI160_THREE_U8X])
  16669. << C_BMI160_EIGHT_U8X)
  16670. |(v_fifo_data_u8[v_fifo_index_u32 +
  16671. C_BMI160_TWO_U8X]));
  16672. v_mag_y_s16 = (s16) (v_mag_data_s16 >>
  16673. C_BMI160_THREE_U8X);
  16674. /* Raw mag z*/
  16675. v_mag_data_s16 =
  16676. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16677. C_BMI160_FIVE_U8X])
  16678. << C_BMI160_EIGHT_U8X)
  16679. |(v_fifo_data_u8[v_fifo_index_u32 +
  16680. C_BMI160_FOUR_U8X]));
  16681. v_mag_z_s16 = (s16)(v_mag_data_s16 >>
  16682. C_BMI160_ONE_U8X);
  16683. /* Raw mag r*/
  16684. v_mag_data_r_u16 =
  16685. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16686. C_BMI160_SEVEN_U8X])
  16687. << C_BMI160_EIGHT_U8X)
  16688. |(v_fifo_data_u8[v_fifo_index_u32 +
  16689. C_BMI160_SIX_U8X]));
  16690. v_mag_r_s16 = (u16) (v_mag_data_r_u16 >>
  16691. C_BMI160_TWO_U8X);
  16692. /* Compensated mag x v_data_u8 */
  16693. mag_fifo[v_mag_index_u8].x =
  16694. bmi160_bmm150_mag_compensate_X(v_mag_x_s16, v_mag_r_s16);
  16695. /* Compensated mag y v_data_u8 */
  16696. mag_fifo[v_mag_index_u8].y =
  16697. bmi160_bmm150_mag_compensate_Y(v_mag_y_s16, v_mag_r_s16);
  16698. /* Compensated mag z v_data_u8 */
  16699. mag_fifo[v_mag_index_u8].z =
  16700. bmi160_bmm150_mag_compensate_Z(v_mag_z_s16, v_mag_r_s16);
  16701. /* Gyro raw x v_data_u8 */
  16702. gyro_fifo[v_gyro_index_u8].x =
  16703. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16704. C_BMI160_NINE_U8X])
  16705. << C_BMI160_EIGHT_U8X)
  16706. |(v_fifo_data_u8[v_fifo_index_u32 +
  16707. C_BMI160_EIGHT_U8X]));
  16708. /* Gyro raw y v_data_u8 */
  16709. gyro_fifo[v_gyro_index_u8].y =
  16710. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16711. C_BMI160_ELEVEN_U8X])
  16712. << C_BMI160_EIGHT_U8X)
  16713. |(v_fifo_data_u8[v_fifo_index_u32 +
  16714. C_BMI160_TEN_U8X]));
  16715. /* Gyro raw z v_data_u8 */
  16716. gyro_fifo[v_gyro_index_u8].z =
  16717. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16718. C_BMI160_THIRTEEN_U8X])
  16719. << C_BMI160_EIGHT_U8X)
  16720. |(v_fifo_data_u8[v_fifo_index_u32 +
  16721. C_BMI160_TWELVE_U8X]));
  16722. /* Accel raw x v_data_u8 */
  16723. accel_fifo[v_accel_index_u8].x =
  16724. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16725. C_BMI160_FIFTEEN_U8X])
  16726. << C_BMI160_EIGHT_U8X)
  16727. |(v_fifo_data_u8[v_fifo_index_u32 +
  16728. C_BMI160_FOURTEEN_U8X]));
  16729. /* Accel raw y v_data_u8 */
  16730. accel_fifo[v_accel_index_u8].y =
  16731. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16732. C_BMI160_SEVENTEEN_U8X])
  16733. << C_BMI160_EIGHT_U8X)
  16734. |(v_fifo_data_u8[v_fifo_index_u32 +
  16735. C_BMI160_SIXTEEN_U8X]));
  16736. /* Accel raw z v_data_u8 */
  16737. accel_fifo[v_accel_index_u8].z =
  16738. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16739. C_BMI160_NINETEEN_U8X])
  16740. << C_BMI160_EIGHT_U8X)
  16741. |(v_fifo_data_u8[v_fifo_index_u32 +
  16742. C_BMI160_EIGHTEEN_U8X]));
  16743. v_accel_index_u8++;
  16744. v_mag_index_u8++;
  16745. v_gyro_index_u8++;
  16746. v_fifo_index_u32 = v_fifo_index_u32 +
  16747. C_BMI160_TWENTY_U8X;
  16748. }
  16749. /* condition for mag and gyro enable*/
  16750. else if ((mag_en == C_BMI160_ONE_U8X) &&
  16751. (gyro_en == C_BMI160_ONE_U8X)
  16752. && (accel_en == C_BMI160_ZERO_U8X)) {
  16753. /* Raw mag x*/
  16754. v_mag_data_s16 =
  16755. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16756. C_BMI160_ONE_U8X])
  16757. << C_BMI160_EIGHT_U8X)
  16758. |(v_fifo_data_u8[v_fifo_index_u32 +
  16759. C_BMI160_ZERO_U8X]));
  16760. v_mag_x_s16 = (s16) (v_mag_data_s16 >>
  16761. C_BMI160_THREE_U8X);
  16762. /* Raw mag y*/
  16763. v_mag_data_s16 =
  16764. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16765. C_BMI160_THREE_U8X])
  16766. << C_BMI160_EIGHT_U8X)
  16767. |(v_fifo_data_u8[v_fifo_index_u32 +
  16768. C_BMI160_TWO_U8X]));
  16769. v_mag_y_s16 = (s16) (v_mag_data_s16 >>
  16770. C_BMI160_THREE_U8X);
  16771. /* Raw mag z*/
  16772. v_mag_data_s16 =
  16773. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16774. C_BMI160_FIVE_U8X])
  16775. << C_BMI160_EIGHT_U8X)
  16776. |(v_fifo_data_u8[v_fifo_index_u32 +
  16777. C_BMI160_FOUR_U8X]));
  16778. v_mag_z_s16 = (s16)(v_mag_data_s16 >>
  16779. C_BMI160_ONE_U8X);
  16780. /* Raw mag r*/
  16781. v_mag_data_r_u16 =
  16782. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16783. C_BMI160_SEVEN_U8X])
  16784. << C_BMI160_EIGHT_U8X)
  16785. |(v_fifo_data_u8[v_fifo_index_u32 +
  16786. C_BMI160_SIX_U8X]));
  16787. v_mag_r_s16 = (u16) (v_mag_data_r_u16 >>
  16788. C_BMI160_TWO_U8X);
  16789. /* Compensated mag x v_data_u8 */
  16790. mag_fifo[v_mag_index_u8].x =
  16791. bmi160_bmm150_mag_compensate_X(v_mag_x_s16, v_mag_r_s16);
  16792. /* Compensated mag y v_data_u8 */
  16793. mag_fifo[v_mag_index_u8].y =
  16794. bmi160_bmm150_mag_compensate_Y(v_mag_y_s16, v_mag_r_s16);
  16795. /* Compensated mag z v_data_u8 */
  16796. mag_fifo[v_mag_index_u8].z =
  16797. bmi160_bmm150_mag_compensate_Z(v_mag_z_s16, v_mag_r_s16);
  16798. /* Gyro raw x v_data_u8 */
  16799. gyro_fifo[v_gyro_index_u8].x =
  16800. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16801. C_BMI160_NINE_U8X])
  16802. << C_BMI160_EIGHT_U8X)
  16803. |(v_fifo_data_u8[v_fifo_index_u32 +
  16804. C_BMI160_EIGHT_U8X]));
  16805. /* Gyro raw y v_data_u8 */
  16806. gyro_fifo[v_gyro_index_u8].y =
  16807. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16808. C_BMI160_ELEVEN_U8X])
  16809. << C_BMI160_EIGHT_U8X)
  16810. |(v_fifo_data_u8[v_fifo_index_u32 +
  16811. C_BMI160_TEN_U8X]));
  16812. /* Gyro raw z v_data_u8 */
  16813. gyro_fifo[v_gyro_index_u8].z =
  16814. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16815. C_BMI160_THIRTEEN_U8X])
  16816. << C_BMI160_EIGHT_U8X)
  16817. |(v_fifo_data_u8[v_fifo_index_u32 +
  16818. C_BMI160_TWELVE_U8X]));
  16819. v_gyro_index_u8++;
  16820. v_mag_index_u8++;
  16821. v_fifo_index_u32 = v_fifo_index_u32 +
  16822. C_BMI160_FOURTEEN_U8X;
  16823. }
  16824. /* condition for mag and accel enable*/
  16825. else if ((mag_en == C_BMI160_ONE_U8X) &&
  16826. (accel_en == C_BMI160_ONE_U8X)
  16827. && (gyro_en == C_BMI160_ZERO_U8X)) {
  16828. /* Raw mag x*/
  16829. v_mag_data_s16 =
  16830. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16831. C_BMI160_ONE_U8X])
  16832. << C_BMI160_EIGHT_U8X)
  16833. |(v_fifo_data_u8[v_fifo_index_u32 +
  16834. C_BMI160_ZERO_U8X]));
  16835. v_mag_x_s16 = (s16) (v_mag_data_s16 >>
  16836. C_BMI160_THREE_U8X);
  16837. /* Raw mag y*/
  16838. v_mag_data_s16 =
  16839. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16840. C_BMI160_THREE_U8X])
  16841. << C_BMI160_EIGHT_U8X)
  16842. |(v_fifo_data_u8[v_fifo_index_u32 +
  16843. C_BMI160_TWO_U8X]));
  16844. v_mag_y_s16 = (s16) (v_mag_data_s16 >>
  16845. C_BMI160_THREE_U8X);
  16846. /* Raw mag z*/
  16847. v_mag_data_s16 =
  16848. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16849. C_BMI160_FIVE_U8X])
  16850. << C_BMI160_EIGHT_U8X)
  16851. |(v_fifo_data_u8[v_fifo_index_u32 +
  16852. C_BMI160_FOUR_U8X]));
  16853. v_mag_z_s16 = (s16)(v_mag_data_s16 >>
  16854. C_BMI160_ONE_U8X);
  16855. /* Raw mag r*/
  16856. v_mag_data_r_u16 =
  16857. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16858. C_BMI160_SEVEN_U8X])
  16859. << C_BMI160_EIGHT_U8X)
  16860. |(v_fifo_data_u8[v_fifo_index_u32 +
  16861. C_BMI160_SIX_U8X]));
  16862. v_mag_r_s16 = (u16) (v_mag_data_r_u16 >>
  16863. C_BMI160_TWO_U8X);
  16864. /* Compensated mag x v_data_u8 */
  16865. mag_fifo[v_mag_index_u8].x =
  16866. bmi160_bmm150_mag_compensate_X(v_mag_x_s16, v_mag_r_s16);
  16867. /* Compensated mag y v_data_u8 */
  16868. mag_fifo[v_mag_index_u8].y =
  16869. bmi160_bmm150_mag_compensate_Y(v_mag_y_s16, v_mag_r_s16);
  16870. /* Compensated mag z v_data_u8 */
  16871. mag_fifo[v_mag_index_u8].z =
  16872. bmi160_bmm150_mag_compensate_Z(v_mag_z_s16, v_mag_r_s16);
  16873. /* Accel raw x v_data_u8 */
  16874. accel_fifo[v_accel_index_u8].x =
  16875. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16876. C_BMI160_NINE_U8X])
  16877. << C_BMI160_EIGHT_U8X)
  16878. |(v_fifo_data_u8[v_fifo_index_u32 +
  16879. C_BMI160_EIGHT_U8X]));
  16880. /* Accel raw y v_data_u8 */
  16881. accel_fifo[v_accel_index_u8].y =
  16882. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16883. C_BMI160_ELEVEN_U8X])
  16884. << C_BMI160_EIGHT_U8X)
  16885. |(v_fifo_data_u8[v_fifo_index_u32 +
  16886. C_BMI160_TEN_U8X]));
  16887. /* Accel raw z v_data_u8 */
  16888. accel_fifo[v_accel_index_u8].z =
  16889. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16890. C_BMI160_THIRTEEN_U8X])
  16891. << C_BMI160_EIGHT_U8X)
  16892. |(v_fifo_data_u8[v_fifo_index_u32 +
  16893. C_BMI160_TWELVE_U8X]));
  16894. v_accel_index_u8++;
  16895. v_mag_index_u8++;
  16896. v_fifo_index_u32 = v_fifo_index_u32 +
  16897. C_BMI160_FOURTEEN_U8X;
  16898. }
  16899. /* condition for gyro and accel enable*/
  16900. else if ((gyro_en == C_BMI160_ONE_U8X) &&
  16901. (accel_en == C_BMI160_ONE_U8X)
  16902. && (mag_en == C_BMI160_ZERO_U8X)) {
  16903. /* Gyro raw x v_data_u8 */
  16904. gyro_fifo[v_gyro_index_u8].x =
  16905. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16906. C_BMI160_ONE_U8X])
  16907. << C_BMI160_EIGHT_U8X)
  16908. |(v_fifo_data_u8[v_fifo_index_u32 +
  16909. C_BMI160_ZERO_U8X]));
  16910. /* Gyro raw y v_data_u8 */
  16911. gyro_fifo[v_gyro_index_u8].y =
  16912. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16913. C_BMI160_THREE_U8X])
  16914. << C_BMI160_EIGHT_U8X)
  16915. |(v_fifo_data_u8[v_fifo_index_u32 +
  16916. C_BMI160_TWO_U8X]));
  16917. /* Gyro raw z v_data_u8 */
  16918. gyro_fifo[v_gyro_index_u8].z =
  16919. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16920. C_BMI160_FIVE_U8X])
  16921. << C_BMI160_EIGHT_U8X)
  16922. |(v_fifo_data_u8[v_fifo_index_u32 +
  16923. C_BMI160_FOUR_U8X]));
  16924. /* Accel raw x v_data_u8 */
  16925. accel_fifo[v_accel_index_u8].x =
  16926. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16927. C_BMI160_SEVEN_U8X])
  16928. << C_BMI160_EIGHT_U8X)
  16929. |(v_fifo_data_u8[v_fifo_index_u32 +
  16930. C_BMI160_SIX_U8X]));
  16931. /* Accel raw y v_data_u8 */
  16932. accel_fifo[v_accel_index_u8].y =
  16933. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16934. C_BMI160_NINE_U8X])
  16935. << C_BMI160_EIGHT_U8X)
  16936. |(v_fifo_data_u8[v_fifo_index_u32 +
  16937. C_BMI160_EIGHT_U8X]));
  16938. /* Accel raw z v_data_u8 */
  16939. accel_fifo[v_accel_index_u8].z =
  16940. (s16)(((v_fifo_data_u8[v_fifo_index_u32 +
  16941. C_BMI160_ELEVEN_U8X])
  16942. << C_BMI160_EIGHT_U8X)
  16943. |(v_fifo_data_u8[v_fifo_index_u32 +
  16944. C_BMI160_TEN_U8X]));
  16945. v_accel_index_u8++;
  16946. v_gyro_index_u8++;
  16947. v_fifo_index_u32 = v_fifo_index_u32 +
  16948. C_BMI160_TWELVE_U8X;
  16949. }
  16950. /* condition for gyro enable*/
  16951. else if ((gyro_en == C_BMI160_ONE_U8X) &&
  16952. (accel_en == C_BMI160_ZERO_U8X)
  16953. && (mag_en == C_BMI160_ZERO_U8X)) {
  16954. /* Gyro raw x v_data_u8 */
  16955. gyro_fifo[v_gyro_index_u8].x =
  16956. (s16)(((v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_ONE_U8X])
  16957. << C_BMI160_EIGHT_U8X)
  16958. |(v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_ZERO_U8X]));
  16959. /* Gyro raw y v_data_u8 */
  16960. gyro_fifo[v_gyro_index_u8].y =
  16961. (s16)(((v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_THREE_U8X])
  16962. << C_BMI160_EIGHT_U8X)
  16963. |(v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_TWO_U8X]));
  16964. /* Gyro raw z v_data_u8 */
  16965. gyro_fifo[v_gyro_index_u8].z =
  16966. (s16)(((v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_FIVE_U8X])
  16967. << C_BMI160_EIGHT_U8X)
  16968. |(v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_FOUR_U8X]));
  16969. v_fifo_index_u32 = v_fifo_index_u32 + C_BMI160_SIX_U8X;
  16970. v_gyro_index_u8++;
  16971. }
  16972. /* condition for accel enable*/
  16973. else if ((gyro_en == C_BMI160_ZERO_U8X) &&
  16974. (accel_en == C_BMI160_ONE_U8X)
  16975. && (mag_en == C_BMI160_ZERO_U8X)) {
  16976. /* Accel raw x v_data_u8 */
  16977. accel_fifo[v_accel_index_u8].x =
  16978. (s16)(((v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_ONE_U8X])
  16979. << C_BMI160_EIGHT_U8X)
  16980. |(v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_ZERO_U8X]));
  16981. /* Accel raw y v_data_u8 */
  16982. accel_fifo[v_accel_index_u8].y =
  16983. (s16)(((v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_THREE_U8X])
  16984. << C_BMI160_EIGHT_U8X)
  16985. |(v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_TWO_U8X]));
  16986. /* Accel raw z v_data_u8 */
  16987. accel_fifo[v_accel_index_u8].z =
  16988. (s16)(((v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_FIVE_U8X])
  16989. << C_BMI160_EIGHT_U8X)
  16990. |(v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_FOUR_U8X]));
  16991. v_fifo_index_u32 = v_fifo_index_u32 + C_BMI160_SIX_U8X;
  16992. v_accel_index_u8++;
  16993. }
  16994. /* condition for mag enable*/
  16995. else if ((gyro_en == C_BMI160_ZERO_U8X) &&
  16996. (accel_en == C_BMI160_ZERO_U8X)
  16997. && (mag_en == C_BMI160_ONE_U8X)) {
  16998. /* Raw mag x*/
  16999. v_mag_data_s16 =
  17000. (s16)(((v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_ONE_U8X])
  17001. << C_BMI160_EIGHT_U8X)
  17002. |(v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_ZERO_U8X]));
  17003. v_mag_x_s16 = (s16) (v_mag_data_s16 >> C_BMI160_THREE_U8X);
  17004. /* Raw mag y*/
  17005. v_mag_data_s16 =
  17006. (s16)(((v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_THREE_U8X])
  17007. << C_BMI160_EIGHT_U8X)
  17008. |(v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_TWO_U8X]));
  17009. v_mag_y_s16 = (s16) (v_mag_data_s16 >> C_BMI160_THREE_U8X);
  17010. /* Raw mag z*/
  17011. v_mag_data_s16 =
  17012. (s16)(((v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_FIVE_U8X])
  17013. << C_BMI160_EIGHT_U8X)
  17014. |(v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_FOUR_U8X]));
  17015. v_mag_z_s16 = (s16)(v_mag_data_s16 >> C_BMI160_ONE_U8X);
  17016. /* Raw mag r*/
  17017. v_mag_data_r_u16 =
  17018. (s16)(((v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_SEVEN_U8X])
  17019. << C_BMI160_EIGHT_U8X)
  17020. |(v_fifo_data_u8[v_fifo_index_u32 + C_BMI160_SIX_U8X]));
  17021. v_mag_r_s16 = (u16) (v_mag_data_r_u16 >> C_BMI160_TWO_U8X);
  17022. /* Compensated mag x v_data_u8 */
  17023. mag_fifo[v_mag_index_u8].x =
  17024. bmi160_bmm150_mag_compensate_X(v_mag_x_s16, v_mag_r_s16);
  17025. /* Compensated mag y v_data_u8 */
  17026. mag_fifo[v_mag_index_u8].y =
  17027. bmi160_bmm150_mag_compensate_Y(v_mag_y_s16, v_mag_r_s16);
  17028. /* Compensated mag z v_data_u8 */
  17029. mag_fifo[v_mag_index_u8].z =
  17030. bmi160_bmm150_mag_compensate_Z(v_mag_z_s16, v_mag_r_s16);
  17031. v_fifo_index_u32 = v_fifo_index_u32 + C_BMI160_EIGHT_U8X;
  17032. v_mag_index_u8++;
  17033. }
  17034. /* condition for fifo over read enable*/
  17035. if (v_fifo_data_u8[v_fifo_index_u32] == FIFO_CONFIG_CHECK1 &&
  17036. v_fifo_data_u8[v_fifo_index_u32+C_BMI160_ONE_U8X] ==
  17037. FIFO_CONFIG_CHECK2 &&
  17038. v_fifo_data_u8[v_fifo_index_u32+C_BMI160_TWO_U8X] ==
  17039. FIFO_CONFIG_CHECK1 &&
  17040. v_fifo_data_u8[v_fifo_index_u32+C_BMI160_THREE_U8X] ==
  17041. FIFO_CONFIG_CHECK2) {
  17042. return FIFO_OVER_READ_RETURN;
  17043. }
  17044. }
  17045. return com_rslt;
  17046. }
  17047. /*!
  17048. * @brief This function used for read the compensated value of mag
  17049. * Before start reading the mag compensated data's
  17050. * make sure the following two points are addressed
  17051. * @note
  17052. * 1. Make sure the mag interface is enabled or not,
  17053. * by using the bmi160_get_if_mode() function.
  17054. * If mag interface is not enabled set the value of 0x02
  17055. * to the function bmi160_get_if_mode(0x02)
  17056. * @note
  17057. * 2. And also confirm the secondary-interface power mode
  17058. * is not in the SUSPEND mode.
  17059. * by using the function bmi160_get_mag_pmu_status().
  17060. * If the secondary-interface power mode is in SUSPEND mode
  17061. * set the value of 0x19(NORMAL mode)by using the
  17062. * bmi160_set_command_register(0x19) function.
  17063. *
  17064. * @return results of bus communication function
  17065. * @retval 0 -> Success
  17066. * @retval -1 -> Error
  17067. *
  17068. *
  17069. */
  17070. BMI160_RETURN_FUNCTION_TYPE bmi160_bmm150_mag_compensate_xyz(
  17071. struct bmi160_mag_xyz_s32_t *mag_comp_xyz)
  17072. {
  17073. /* variable used for return the status of communication result*/
  17074. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  17075. struct bmi160_mag_xyzr_t mag_xyzr;
  17076. com_rslt = bmi160_read_mag_xyzr(&mag_xyzr);
  17077. /* Compensation for X axis */
  17078. mag_comp_xyz->x = bmi160_bmm150_mag_compensate_X(
  17079. mag_xyzr.x, mag_xyzr.r);
  17080. /* Compensation for Y axis */
  17081. mag_comp_xyz->y = bmi160_bmm150_mag_compensate_Y(
  17082. mag_xyzr.y, mag_xyzr.r);
  17083. /* Compensation for Z axis */
  17084. mag_comp_xyz->z = bmi160_bmm150_mag_compensate_Z(
  17085. mag_xyzr.z, mag_xyzr.r);
  17086. return com_rslt;
  17087. }
  17088. /*!
  17089. * @brief This API used to get the compensated BMM150-X data
  17090. * the out put of X as s32
  17091. * Before start reading the mag compensated X data
  17092. * make sure the following two points are addressed
  17093. * @note
  17094. * 1. Make sure the mag interface is enabled or not,
  17095. * by using the bmi160_get_if_mode() function.
  17096. * If mag interface is not enabled set the value of 0x02
  17097. * to the function bmi160_get_if_mode(0x02)
  17098. * @note
  17099. * 2. And also confirm the secondary-interface power mode
  17100. * is not in the SUSPEND mode.
  17101. * by using the function bmi160_get_mag_pmu_status().
  17102. * If the secondary-interface power mode is in SUSPEND mode
  17103. * set the value of 0x19(NORMAL mode)by using the
  17104. * bmi160_set_command_register(0x19) function.
  17105. *
  17106. *
  17107. *
  17108. * @param v_mag_data_x_s16 : The value of mag raw X data
  17109. * @param v_data_r_u16 : The value of mag R data
  17110. *
  17111. * @return results of compensated X data value output as s32
  17112. *
  17113. */
  17114. s32 bmi160_bmm150_mag_compensate_X(s16 v_mag_data_x_s16, u16 v_data_r_u16)
  17115. {
  17116. s32 inter_retval = C_BMI160_ZERO_U8X;
  17117. /* no overflow */
  17118. if (v_mag_data_x_s16 != BMI160_MAG_FLIP_OVERFLOW_ADCVAL) {
  17119. if ((v_data_r_u16 != C_BMI160_ZERO_U8X)
  17120. && (mag_trim.dig_xyz1 != C_BMI160_ZERO_U8X)) {
  17121. inter_retval = ((s32)(((u16)
  17122. ((((s32)mag_trim.dig_xyz1)
  17123. << BMI160_SHIFT_14_POSITION)/
  17124. (v_data_r_u16 != C_BMI160_ZERO_U8X ?
  17125. v_data_r_u16 : mag_trim.dig_xyz1))) -
  17126. ((u16)BMM150_CALIB_HEX_FOUR_THOUSAND)));
  17127. } else {
  17128. inter_retval = BMI160_MAG_OVERFLOW_OUTPUT;
  17129. return inter_retval;
  17130. }
  17131. inter_retval = ((s32)((((s32)v_mag_data_x_s16) *
  17132. ((((((((s32)mag_trim.dig_xy2) *
  17133. ((((s32)inter_retval) *
  17134. ((s32)inter_retval))
  17135. >> BMI160_SHIFT_7_POSITION)) +
  17136. (((s32)inter_retval) *
  17137. ((s32)(((s16)mag_trim.dig_xy1)
  17138. << BMI160_SHIFT_7_POSITION))))
  17139. >> BMI160_SHIFT_9_POSITION) +
  17140. ((s32)BMM150_CALIB_HEX_LACKS)) *
  17141. ((s32)(((s16)mag_trim.dig_x2) +
  17142. ((s16)BMM150_CALIB_HEX_A_ZERO))))
  17143. >> BMI160_SHIFT_12_POSITION))
  17144. >> BMI160_SHIFT_13_POSITION)) +
  17145. (((s16)mag_trim.dig_x1)
  17146. << BMI160_SHIFT_3_POSITION);
  17147. /* check the overflow output */
  17148. if (inter_retval == (s32)BMI160_MAG_OVERFLOW_OUTPUT)
  17149. inter_retval = BMI160_MAG_OVERFLOW_OUTPUT_S32;
  17150. } else {
  17151. /* overflow */
  17152. inter_retval = BMI160_MAG_OVERFLOW_OUTPUT;
  17153. }
  17154. return inter_retval;
  17155. }
  17156. /*!
  17157. * @brief This API used to get the compensated BMM150-Y data
  17158. * the out put of Y as s32
  17159. * Before start reading the mag compensated Y data
  17160. * make sure the following two points are addressed
  17161. * @note
  17162. * 1. Make sure the mag interface is enabled or not,
  17163. * by using the bmi160_get_if_mode() function.
  17164. * If mag interface is not enabled set the value of 0x02
  17165. * to the function bmi160_get_if_mode(0x02)
  17166. * @note
  17167. * 2. And also confirm the secondary-interface power mode
  17168. * is not in the SUSPEND mode.
  17169. * by using the function bmi160_get_mag_pmu_status().
  17170. * If the secondary-interface power mode is in SUSPEND mode
  17171. * set the value of 0x19(NORMAL mode)by using the
  17172. * bmi160_set_command_register(0x19) function.
  17173. *
  17174. *
  17175. *
  17176. * @param v_mag_data_y_s16 : The value of mag raw Y data
  17177. * @param v_data_r_u16 : The value of mag R data
  17178. *
  17179. * @return results of compensated Y data value output as s32
  17180. */
  17181. s32 bmi160_bmm150_mag_compensate_Y(s16 v_mag_data_y_s16, u16 v_data_r_u16)
  17182. {
  17183. s32 inter_retval = C_BMI160_ZERO_U8X;
  17184. /* no overflow */
  17185. if (v_mag_data_y_s16 != BMI160_MAG_FLIP_OVERFLOW_ADCVAL) {
  17186. if ((v_data_r_u16 != C_BMI160_ZERO_U8X)
  17187. && (mag_trim.dig_xyz1 != C_BMI160_ZERO_U8X)) {
  17188. inter_retval = ((s32)(((u16)(((
  17189. (s32)mag_trim.dig_xyz1) << BMI160_SHIFT_14_POSITION)/
  17190. (v_data_r_u16 != C_BMI160_ZERO_U8X ?
  17191. v_data_r_u16 : mag_trim.dig_xyz1))) -
  17192. ((u16)BMM150_CALIB_HEX_FOUR_THOUSAND)));
  17193. } else {
  17194. inter_retval = BMI160_MAG_OVERFLOW_OUTPUT;
  17195. return inter_retval;
  17196. }
  17197. inter_retval = ((s32)((((s32)v_mag_data_y_s16) * ((((((((s32)
  17198. mag_trim.dig_xy2) * ((((s32) inter_retval) *
  17199. ((s32)inter_retval)) >> BMI160_SHIFT_7_POSITION))
  17200. + (((s32)inter_retval) *
  17201. ((s32)(((s16)mag_trim.dig_xy1)
  17202. << BMI160_SHIFT_7_POSITION))))
  17203. >> BMI160_SHIFT_9_POSITION) +
  17204. ((s32)BMM150_CALIB_HEX_LACKS))
  17205. * ((s32)(((s16)mag_trim.dig_y2)
  17206. + ((s16)BMM150_CALIB_HEX_A_ZERO))))
  17207. >> BMI160_SHIFT_12_POSITION))
  17208. >> BMI160_SHIFT_13_POSITION)) +
  17209. (((s16)mag_trim.dig_y1) << BMI160_SHIFT_3_POSITION);
  17210. /* check the overflow output */
  17211. if (inter_retval == (s32)BMI160_MAG_OVERFLOW_OUTPUT)
  17212. inter_retval = BMI160_MAG_OVERFLOW_OUTPUT_S32;
  17213. } else {
  17214. /* overflow */
  17215. inter_retval = BMI160_MAG_OVERFLOW_OUTPUT;
  17216. }
  17217. return inter_retval;
  17218. }
  17219. /*!
  17220. * @brief This API used to get the compensated BMM150-Z data
  17221. * the out put of Z as s32
  17222. * Before start reading the mag compensated Z data
  17223. * make sure the following two points are addressed
  17224. * @note
  17225. * 1. Make sure the mag interface is enabled or not,
  17226. * by using the bmi160_get_if_mode() function.
  17227. * If mag interface is not enabled set the value of 0x02
  17228. * to the function bmi160_get_if_mode(0x02)
  17229. * @note
  17230. * 2. And also confirm the secondary-interface power mode
  17231. * is not in the SUSPEND mode.
  17232. * by using the function bmi160_get_mag_pmu_status().
  17233. * If the secondary-interface power mode is in SUSPEND mode
  17234. * set the value of 0x19(NORMAL mode)by using the
  17235. * bmi160_set_command_register(0x19) function.
  17236. *
  17237. *
  17238. *
  17239. * @param v_mag_data_z_s16 : The value of mag raw Z data
  17240. * @param v_data_r_u16 : The value of mag R data
  17241. *
  17242. * @return results of compensated Z data value output as s32
  17243. */
  17244. s32 bmi160_bmm150_mag_compensate_Z(s16 v_mag_data_z_s16, u16 v_data_r_u16)
  17245. {
  17246. s32 retval = C_BMI160_ZERO_U8X;
  17247. if (v_mag_data_z_s16 != BMI160_MAG_HALL_OVERFLOW_ADCVAL) {
  17248. if ((v_data_r_u16 != C_BMI160_ZERO_U8X)
  17249. && (mag_trim.dig_z2 != C_BMI160_ZERO_U8X)
  17250. && (mag_trim.dig_z1 != C_BMI160_ZERO_U8X)) {
  17251. retval = (((((s32)(v_mag_data_z_s16 - mag_trim.dig_z4))
  17252. << BMI160_SHIFT_15_POSITION) -
  17253. ((((s32)mag_trim.dig_z3) *
  17254. ((s32)(((s16)v_data_r_u16) -
  17255. ((s16)mag_trim.dig_xyz1))))
  17256. >> BMI160_SHIFT_2_POSITION))/
  17257. (mag_trim.dig_z2 +
  17258. ((s16)(((((s32)mag_trim.dig_z1) *
  17259. ((((s16)v_data_r_u16) << BMI160_SHIFT_1_POSITION))) +
  17260. (C_BMI160_ONE_U8X << BMI160_SHIFT_15_POSITION))
  17261. >> BMI160_SHIFT_16_POSITION))));
  17262. }
  17263. } else {
  17264. retval = BMI160_MAG_OVERFLOW_OUTPUT;
  17265. }
  17266. return retval;
  17267. }
  17268. /*!
  17269. * @brief This function used for initialize the bmm150 sensor
  17270. *
  17271. *
  17272. * @return results of bus communication function
  17273. * @retval 0 -> Success
  17274. * @retval -1 -> Error
  17275. *
  17276. *
  17277. */
  17278. BMI160_RETURN_FUNCTION_TYPE bmi160_bmm150_mag_interface_init(void)
  17279. {
  17280. /* This variable used for provide the communication
  17281. results*/
  17282. /* variable used for return the status of communication result*/
  17283. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  17284. u8 v_pull_value_u8 = C_BMI160_ZERO_U8X;
  17285. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  17286. /* accel operation mode to normal*/
  17287. com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL);
  17288. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17289. com_rslt = bmi160_set_command_register(MAG_MODE_NORMAL);
  17290. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17291. bmi160_get_mag_power_mode_stat(&v_data_u8);
  17292. /* register 0x7E write the 0x37, 0x9A and 0x30*/
  17293. com_rslt += bmi160_set_command_register(BMI160_COMMAND_REG_ONE);
  17294. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17295. com_rslt += bmi160_set_command_register(BMI160_COMMAND_REG_TWO);
  17296. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17297. com_rslt += bmi160_set_command_register(BMI160_COMMAND_REG_THREE);
  17298. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17299. /*switch the page1*/
  17300. com_rslt += bmi160_set_target_page(BMI160_HEX_0_1_DATA);
  17301. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17302. bmi160_get_target_page(&v_data_u8);
  17303. com_rslt += bmi160_set_paging_enable(BMI160_HEX_0_1_DATA);
  17304. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17305. bmi160_get_paging_enable(&v_data_u8);
  17306. /* enable the pullup configuration from
  17307. the register 0x85 bit 4 and 5 */
  17308. bmi160_get_pullup_configuration(&v_pull_value_u8);
  17309. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17310. v_pull_value_u8 = v_pull_value_u8 | BMI160_HEX_0_3_DATA;
  17311. com_rslt += bmi160_set_pullup_configuration(v_pull_value_u8);
  17312. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17313. /*switch the page0*/
  17314. com_rslt += bmi160_set_target_page(BMI160_HEX_0_0_DATA);
  17315. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17316. bmi160_get_target_page(&v_data_u8);
  17317. /* Write the BMM150 i2c address*/
  17318. com_rslt += bmi160_set_i2c_device_addr(BMI160_BMM150_I2C_ADDRESS);
  17319. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17320. /* enable the mag interface to manual mode*/
  17321. com_rslt += bmi160_set_mag_manual_enable(BMI160_HEX_0_1_DATA);
  17322. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17323. bmi160_get_mag_manual_enable(&v_data_u8);
  17324. /*Enable the MAG interface */
  17325. com_rslt += bmi160_set_if_mode(BMI160_HEX_0_2_DATA);
  17326. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17327. bmi160_get_if_mode(&v_data_u8);
  17328. /* Mag normal mode*/
  17329. com_rslt += bmi160_bmm150_mag_wakeup();
  17330. /* write the power mode register*/
  17331. com_rslt += bmi160_set_mag_write_data(BMI160_HEX_0_6_DATA);
  17332. /*write 0x4C register to write set power mode to normal*/
  17333. com_rslt += bmi160_set_mag_write_addr(
  17334. BMI160_BMM150_POWE_MODE_REG);
  17335. /* read the mag trim values*/
  17336. com_rslt += bmi160_read_bmm150_mag_trim();
  17337. /* To avoid the auto mode enable when manual mode operation running*/
  17338. V_bmm150_maual_auto_condition_u8 = BMM150_HEX_0_1_DATA;
  17339. /* write the XY and Z repetitions*/
  17340. com_rslt += bmi160_set_bmm150_mag_presetmode(
  17341. BMI160_MAG_PRESETMODE_REGULAR);
  17342. /* To avoid the auto mode enable when manual mode operation running*/
  17343. V_bmm150_maual_auto_condition_u8 = BMM150_HEX_0_0_DATA;
  17344. /* Set the power mode of mag as force mode*/
  17345. /* The data have to write for the register
  17346. It write the value in the register 0x4F */
  17347. com_rslt += bmi160_set_mag_write_data(BMM150_FORCE_MODE);
  17348. /* write into power mode register*/
  17349. com_rslt += bmi160_set_mag_write_addr(
  17350. BMI160_BMM150_POWE_MODE_REG);
  17351. /* write the mag v_data_bw_u8 as 25Hz*/
  17352. com_rslt += bmi160_set_mag_output_data_rate(
  17353. BMI160_MAG_OUTPUT_DATA_RATE_25HZ);
  17354. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17355. /* When mag interface is auto mode - The mag read address
  17356. starts the register 0x42*/
  17357. com_rslt += bmi160_set_mag_read_addr(
  17358. BMI160_BMM150_DATA_REG);
  17359. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17360. /* enable mag interface to auto mode*/
  17361. com_rslt += bmi160_set_mag_manual_enable(BMI160_HEX_0_0_DATA);
  17362. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17363. bmi160_get_mag_manual_enable(&v_data_u8);
  17364. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17365. return com_rslt;
  17366. }
  17367. /*!
  17368. * @brief This function used for set the mag power control
  17369. * bit enable
  17370. *
  17371. *
  17372. * @return results of bus communication function
  17373. * @retval 0 -> Success
  17374. * @retval -1 -> Error
  17375. *
  17376. *
  17377. */
  17378. BMI160_RETURN_FUNCTION_TYPE bmi160_bmm150_mag_wakeup(void)
  17379. {
  17380. /* variable used for return the status of communication result*/
  17381. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  17382. u8 try_times = BMM150_MAX_RETRY_WAKEUP;
  17383. u8 v_power_control_bit_u8 = C_BMI160_ZERO_U8X;
  17384. u8 i = C_BMI160_ZERO_U8X;
  17385. for (i = C_BMI160_ZERO_U8X; i < try_times; i++) {
  17386. com_rslt = bmi160_set_mag_write_data(BMM150_POWER_ON);
  17387. p_bmi160->delay_msec(C_BMI160_TWO_U8X);
  17388. /*write 0x4B register to enable power control bit*/
  17389. com_rslt += bmi160_set_mag_write_addr(
  17390. BMI160_BMM150_POWE_CONTROL_REG);
  17391. p_bmi160->delay_msec(C_BMI160_THREE_U8X);
  17392. com_rslt += bmi160_set_mag_read_addr(
  17393. BMI160_BMM150_POWE_CONTROL_REG);
  17394. /* 0x04 is secondary read mag x lsb register */
  17395. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17396. com_rslt += bmi160_read_reg(BMI160_USER_DATA_0_ADDR,
  17397. &v_power_control_bit_u8, C_BMI160_ONE_U8X);
  17398. v_power_control_bit_u8 = BMM150_HEX_0_1_DATA
  17399. & v_power_control_bit_u8;
  17400. if (v_power_control_bit_u8 == BMM150_POWER_ON)
  17401. break;
  17402. }
  17403. com_rslt = (i >= try_times) ?
  17404. BMM150_POWER_ON_FAIL : BMM150_POWER_ON_SUCCESS;
  17405. return com_rslt;
  17406. }
  17407. /*!
  17408. * @brief This function used for set the magnetometer
  17409. * power mode.
  17410. * @note
  17411. * Before set the mag power mode
  17412. * make sure the following two point is addressed
  17413. * Make sure the mag interface is enabled or not,
  17414. * by using the bmi160_get_if_mode() function.
  17415. * If mag interface is not enabled set the value of 0x02
  17416. * to the function bmi160_get_if_mode(0x02)
  17417. *
  17418. * @param v_mag_sec_if_pow_mode_u8 : The value of mag power mode
  17419. * value | mode
  17420. * ----------|------------
  17421. * 0 | BMI160_MAG_FORCE_MODE
  17422. * 1 | BMI160_MAG_SUSPEND_MODE
  17423. *
  17424. *
  17425. * @return results of bus communication function
  17426. * @retval 0 -> Success
  17427. * @retval -1 -> Error
  17428. *
  17429. *
  17430. */
  17431. BMI160_RETURN_FUNCTION_TYPE bmi160_set_bmm150_mag_and_secondary_if_power_mode(
  17432. u8 v_mag_sec_if_pow_mode_u8)
  17433. {
  17434. /* variable used for return the status of communication result*/
  17435. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  17436. /* set the accel power mode to NORMAL*/
  17437. com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL);
  17438. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17439. switch (v_mag_sec_if_pow_mode_u8) {
  17440. case BMI160_MAG_FORCE_MODE:
  17441. /* set mag interface manual mode*/
  17442. if (p_bmi160->mag_manual_enable != BMI160_HEX_0_1_DATA) {
  17443. com_rslt = bmi160_set_mag_manual_enable(
  17444. BMI160_HEX_0_1_DATA);
  17445. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17446. }
  17447. /* set the secondary mag power mode as NORMAL*/
  17448. com_rslt += bmi160_set_command_register(MAG_MODE_NORMAL);
  17449. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  17450. /* set the mag power mode as FORCE mode*/
  17451. com_rslt += bmi160_bmm150_mag_set_power_mode(FORCE_MODE);
  17452. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17453. if (p_bmi160->mag_manual_enable == BMI160_HEX_0_1_DATA) {
  17454. /* set mag interface auto mode*/
  17455. com_rslt += bmi160_set_mag_manual_enable(
  17456. BMI160_HEX_0_0_DATA);
  17457. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17458. }
  17459. break;
  17460. case BMI160_MAG_SUSPEND_MODE:
  17461. /* set mag interface manual mode*/
  17462. if (p_bmi160->mag_manual_enable != BMI160_HEX_0_1_DATA) {
  17463. com_rslt = bmi160_set_mag_manual_enable(
  17464. BMI160_HEX_0_1_DATA);
  17465. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17466. }
  17467. /* set the mag power mode as SUSPEND mode*/
  17468. com_rslt += bmi160_bmm150_mag_set_power_mode(SUSPEND_MODE);
  17469. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17470. /* set the secondary mag power mode as SUSPEND*/
  17471. com_rslt += bmi160_set_command_register(MAG_MODE_SUSPEND);
  17472. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  17473. break;
  17474. default:
  17475. com_rslt = E_BMI160_OUT_OF_RANGE;
  17476. break;
  17477. }
  17478. return com_rslt;
  17479. }
  17480. /*!
  17481. * @brief This function used for set the magnetometer
  17482. * power mode.
  17483. * @note
  17484. * Before set the mag power mode
  17485. * make sure the following two points are addressed
  17486. * @note
  17487. * 1. Make sure the mag interface is enabled or not,
  17488. * by using the bmi160_get_if_mode() function.
  17489. * If mag interface is not enabled set the value of 0x02
  17490. * to the function bmi160_get_if_mode(0x02)
  17491. * @note
  17492. * 2. And also confirm the secondary-interface power mode
  17493. * is not in the SUSPEND mode.
  17494. * by using the function bmi160_get_mag_pmu_status().
  17495. * If the secondary-interface power mode is in SUSPEND mode
  17496. * set the value of 0x19(NORMAL mode)by using the
  17497. * bmi160_set_command_register(0x19) function.
  17498. *
  17499. * @param v_mag_pow_mode_u8 : The value of mag power mode
  17500. * value | mode
  17501. * ----------|------------
  17502. * 0 | FORCE_MODE
  17503. * 1 | SUSPEND_MODE
  17504. *
  17505. *
  17506. * @return results of bus communication function
  17507. * @retval 0 -> Success
  17508. * @retval -1 -> Error
  17509. *
  17510. *
  17511. */
  17512. BMI160_RETURN_FUNCTION_TYPE bmi160_bmm150_mag_set_power_mode(
  17513. u8 v_mag_pow_mode_u8)
  17514. {
  17515. /* variable used for return the status of communication result*/
  17516. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  17517. switch (v_mag_pow_mode_u8) {
  17518. case FORCE_MODE:
  17519. /* set mag interface manual mode*/
  17520. if (p_bmi160->mag_manual_enable != BMI160_HEX_0_1_DATA) {
  17521. com_rslt = bmi160_set_mag_manual_enable(
  17522. BMI160_HEX_0_1_DATA);
  17523. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17524. }
  17525. /* Set the power control bit enabled */
  17526. com_rslt = bmi160_bmm150_mag_wakeup();
  17527. /* write the mag power mode as FORCE mode*/
  17528. com_rslt += bmi160_set_mag_write_data(
  17529. BMM150_FORCE_MODE);
  17530. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17531. com_rslt += bmi160_set_mag_write_addr(
  17532. BMI160_BMM150_POWE_MODE_REG);
  17533. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  17534. /* To avoid the auto mode enable when manual
  17535. mode operation running*/
  17536. V_bmm150_maual_auto_condition_u8 = BMM150_HEX_0_1_DATA;
  17537. /* set the preset mode */
  17538. com_rslt += bmi160_set_bmm150_mag_presetmode(
  17539. BMI160_MAG_PRESETMODE_REGULAR);
  17540. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17541. /* To avoid the auto mode enable when manual
  17542. mode operation running*/
  17543. V_bmm150_maual_auto_condition_u8 = BMM150_HEX_0_0_DATA;
  17544. /* set the mag read address to data registers*/
  17545. com_rslt += bmi160_set_mag_read_addr(
  17546. BMI160_BMM150_DATA_REG);
  17547. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17548. /* set mag interface auto mode*/
  17549. if (p_bmi160->mag_manual_enable == BMI160_HEX_0_1_DATA) {
  17550. com_rslt += bmi160_set_mag_manual_enable(
  17551. BMI160_HEX_0_0_DATA);
  17552. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17553. }
  17554. break;
  17555. case SUSPEND_MODE:
  17556. /* set mag interface manual mode*/
  17557. if (p_bmi160->mag_manual_enable != BMI160_HEX_0_1_DATA) {
  17558. com_rslt = bmi160_set_mag_manual_enable(
  17559. BMI160_HEX_0_1_DATA);
  17560. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17561. }
  17562. /* Set the power mode of mag as suspend mode*/
  17563. com_rslt += bmi160_set_mag_write_data(
  17564. BMM150_POWER_OFF);
  17565. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17566. com_rslt += bmi160_set_mag_write_addr(
  17567. BMI160_BMM150_POWE_CONTROL_REG);
  17568. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  17569. break;
  17570. default:
  17571. com_rslt = E_BMI160_OUT_OF_RANGE;
  17572. break;
  17573. }
  17574. return com_rslt;
  17575. }
  17576. /*!
  17577. * @brief This API used to set the pre-set modes of bmm150
  17578. * The pre-set mode setting is depend on data rate and xy and z repetitions
  17579. *
  17580. * @note
  17581. * Before set the mag preset mode
  17582. * make sure the following two points are addressed
  17583. * @note
  17584. * 1. Make sure the mag interface is enabled or not,
  17585. * by using the bmi160_get_if_mode() function.
  17586. * If mag interface is not enabled set the value of 0x02
  17587. * to the function bmi160_get_if_mode(0x02)
  17588. * @note
  17589. * 2. And also confirm the secondary-interface power mode
  17590. * is not in the SUSPEND mode.
  17591. * by using the function bmi160_get_mag_pmu_status().
  17592. * If the secondary-interface power mode is in SUSPEND mode
  17593. * set the value of 0x19(NORMAL mode)by using the
  17594. * bmi160_set_command_register(0x19) function.
  17595. *
  17596. *
  17597. * @param v_mode_u8: The value of pre-set mode selection value
  17598. * value | pre_set mode
  17599. * ----------|------------
  17600. * 1 | BMI160_MAG_PRESETMODE_LOWPOWER
  17601. * 2 | BMI160_MAG_PRESETMODE_REGULAR
  17602. * 3 | BMI160_MAG_PRESETMODE_HIGHACCURACY
  17603. * 4 | BMI160_MAG_PRESETMODE_ENHANCED
  17604. *
  17605. * @return results of bus communication function
  17606. * @retval 0 -> Success
  17607. * @retval -1 -> Error
  17608. *
  17609. */
  17610. BMI160_RETURN_FUNCTION_TYPE bmi160_set_bmm150_mag_presetmode(u8 v_mode_u8)
  17611. {
  17612. /* variable used for return the status of communication result*/
  17613. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  17614. /* set mag interface manual mode*/
  17615. if (p_bmi160->mag_manual_enable != BMI160_HEX_0_1_DATA)
  17616. com_rslt = bmi160_set_mag_manual_enable(
  17617. BMI160_HEX_0_1_DATA);
  17618. switch (v_mode_u8) {
  17619. case BMI160_MAG_PRESETMODE_LOWPOWER:
  17620. /* write the XY and Z repetitions*/
  17621. /* The v_data_u8 have to write for the register
  17622. It write the value in the register 0x4F*/
  17623. com_rslt = bmi160_set_mag_write_data(
  17624. BMI160_MAG_LOWPOWER_REPXY);
  17625. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17626. com_rslt += bmi160_set_mag_write_addr(
  17627. BMI160_BMM150_XY_REP);
  17628. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17629. /* write the Z repetitions*/
  17630. /* The v_data_u8 have to write for the register
  17631. It write the value in the register 0x4F*/
  17632. com_rslt += bmi160_set_mag_write_data(
  17633. BMI160_MAG_LOWPOWER_REPZ);
  17634. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17635. com_rslt += bmi160_set_mag_write_addr(
  17636. BMI160_BMM150_Z_REP);
  17637. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17638. /* set the mag v_data_u8 rate as 10 to the register 0x4C*/
  17639. com_rslt += bmi160_set_mag_write_data(
  17640. BMI160_MAG_LOWPOWER_DR);
  17641. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17642. com_rslt += bmi160_set_mag_write_addr(
  17643. BMI160_BMM150_POWE_MODE_REG);
  17644. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17645. break;
  17646. case BMI160_MAG_PRESETMODE_REGULAR:
  17647. /* write the XY and Z repetitions*/
  17648. /* The v_data_u8 have to write for the register
  17649. It write the value in the register 0x4F*/
  17650. com_rslt = bmi160_set_mag_write_data(
  17651. BMI160_MAG_REGULAR_REPXY);
  17652. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17653. com_rslt += bmi160_set_mag_write_addr(
  17654. BMI160_BMM150_XY_REP);
  17655. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17656. /* write the Z repetitions*/
  17657. /* The v_data_u8 have to write for the register
  17658. It write the value in the register 0x4F*/
  17659. com_rslt += bmi160_set_mag_write_data(
  17660. BMI160_MAG_REGULAR_REPZ);
  17661. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17662. com_rslt += bmi160_set_mag_write_addr(
  17663. BMI160_BMM150_Z_REP);
  17664. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17665. /* set the mag v_data_u8 rate as 10 to the register 0x4C*/
  17666. com_rslt += bmi160_set_mag_write_data(
  17667. BMI160_MAG_REGULAR_DR);
  17668. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17669. com_rslt += bmi160_set_mag_write_addr(
  17670. BMI160_BMM150_POWE_MODE_REG);
  17671. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17672. break;
  17673. case BMI160_MAG_PRESETMODE_HIGHACCURACY:
  17674. /* write the XY and Z repetitions*/
  17675. /* The v_data_u8 have to write for the register
  17676. It write the value in the register 0x4F*/
  17677. com_rslt = bmi160_set_mag_write_data(
  17678. BMI160_MAG_HIGHACCURACY_REPXY);
  17679. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17680. com_rslt += bmi160_set_mag_write_addr(
  17681. BMI160_BMM150_XY_REP);
  17682. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17683. /* write the Z repetitions*/
  17684. /* The v_data_u8 have to write for the register
  17685. It write the value in the register 0x4F*/
  17686. com_rslt += bmi160_set_mag_write_data(
  17687. BMI160_MAG_HIGHACCURACY_REPZ);
  17688. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17689. com_rslt += bmi160_set_mag_write_addr(
  17690. BMI160_BMM150_Z_REP);
  17691. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17692. /* set the mag v_data_u8 rate as 20 to the register 0x4C*/
  17693. com_rslt += bmi160_set_mag_write_data(
  17694. BMI160_MAG_HIGHACCURACY_DR);
  17695. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17696. com_rslt += bmi160_set_mag_write_addr(
  17697. BMI160_BMM150_POWE_MODE_REG);
  17698. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17699. break;
  17700. case BMI160_MAG_PRESETMODE_ENHANCED:
  17701. /* write the XY and Z repetitions*/
  17702. /* The v_data_u8 have to write for the register
  17703. It write the value in the register 0x4F*/
  17704. com_rslt = bmi160_set_mag_write_data(
  17705. BMI160_MAG_ENHANCED_REPXY);
  17706. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17707. com_rslt += bmi160_set_mag_write_addr(
  17708. BMI160_BMM150_XY_REP);
  17709. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17710. /* write the Z repetitions*/
  17711. /* The v_data_u8 have to write for the register
  17712. It write the value in the register 0x4F*/
  17713. com_rslt += bmi160_set_mag_write_data(
  17714. BMI160_MAG_ENHANCED_REPZ);
  17715. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17716. com_rslt += bmi160_set_mag_write_addr(
  17717. BMI160_BMM150_Z_REP);
  17718. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17719. /* set the mag v_data_u8 rate as 10 to the register 0x4C*/
  17720. com_rslt += bmi160_set_mag_write_data(
  17721. BMI160_MAG_ENHANCED_DR);
  17722. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17723. com_rslt += bmi160_set_mag_write_addr(
  17724. BMI160_BMM150_POWE_MODE_REG);
  17725. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17726. break;
  17727. default:
  17728. com_rslt = E_BMI160_OUT_OF_RANGE;
  17729. break;
  17730. }
  17731. if (V_bmm150_maual_auto_condition_u8 == BMI160_HEX_0_0_DATA) {
  17732. com_rslt += bmi160_set_mag_write_data(
  17733. BMM150_FORCE_MODE);
  17734. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17735. com_rslt += bmi160_set_mag_write_addr(
  17736. BMI160_BMM150_POWE_MODE_REG);
  17737. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  17738. com_rslt += bmi160_set_mag_read_addr(BMI160_BMM150_DATA_REG);
  17739. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17740. /* set mag interface auto mode*/
  17741. if (p_bmi160->mag_manual_enable == BMI160_HEX_0_1_DATA)
  17742. com_rslt = bmi160_set_mag_manual_enable(
  17743. BMI160_HEX_0_0_DATA);
  17744. }
  17745. return com_rslt;
  17746. }
  17747. /*!
  17748. * @brief This function used for read the trim values of magnetometer
  17749. *
  17750. * @note
  17751. * Before reading the mag trimming values
  17752. * make sure the following two points are addressed
  17753. * @note
  17754. * 1. Make sure the mag interface is enabled or not,
  17755. * by using the bmi160_get_if_mode() function.
  17756. * If mag interface is not enabled set the value of 0x02
  17757. * to the function bmi160_get_if_mode(0x02)
  17758. * @note
  17759. * 2. And also confirm the secondary-interface power mode
  17760. * is not in the SUSPEND mode.
  17761. * by using the function bmi160_get_mag_pmu_status().
  17762. * If the secondary-interface power mode is in SUSPEND mode
  17763. * set the value of 0x19(NORMAL mode)by using the
  17764. * bmi160_set_command_register(0x19) function.
  17765. *
  17766. * @return results of bus communication function
  17767. * @retval 0 -> Success
  17768. * @retval -1 -> Error
  17769. *
  17770. *
  17771. */
  17772. BMI160_RETURN_FUNCTION_TYPE bmi160_read_bmm150_mag_trim(void)
  17773. {
  17774. /* This variable used for provide the communication
  17775. results*/
  17776. /* variable used for return the status of communication result*/
  17777. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  17778. /* Array holding the bmm150 trim data
  17779. */
  17780. u8 v_data_u8[ARRAY_SIZE_SIXTEEN] = {
  17781. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X,
  17782. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X,
  17783. C_BMI160_ZERO_U8X,
  17784. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X,
  17785. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X,
  17786. C_BMI160_ZERO_U8X,
  17787. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X,
  17788. C_BMI160_ZERO_U8X,
  17789. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X,
  17790. C_BMI160_ZERO_U8X};
  17791. /* read dig_x1 value */
  17792. com_rslt = bmi160_set_mag_read_addr(
  17793. BMI160_MAG_DIG_X1);
  17794. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17795. /* 0x04 is secondary read mag x lsb register */
  17796. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  17797. &v_data_u8[BMM150_DIG_X1], C_BMI160_ONE_U8X);
  17798. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17799. mag_trim.dig_x1 = v_data_u8[BMM150_DIG_X1];
  17800. /* read dig_y1 value */
  17801. com_rslt += bmi160_set_mag_read_addr(
  17802. BMI160_MAG_DIG_Y1);
  17803. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17804. /* 0x04 is secondary read mag x lsb register */
  17805. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  17806. &v_data_u8[BMM150_DIG_Y1],
  17807. C_BMI160_ONE_U8X);
  17808. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17809. mag_trim.dig_y1 = v_data_u8[BMM150_DIG_Y1];
  17810. /* read dig_x2 value */
  17811. com_rslt += bmi160_set_mag_read_addr(
  17812. BMI160_MAG_DIG_X2);
  17813. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17814. /* 0x04 is secondary read mag x lsb register */
  17815. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  17816. &v_data_u8[BMM150_DIG_X2], C_BMI160_ONE_U8X);
  17817. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17818. mag_trim.dig_x2 = v_data_u8[BMM150_DIG_X2];
  17819. /* read dig_y2 value */
  17820. com_rslt += bmi160_set_mag_read_addr(
  17821. BMI160_MAG_DIG_Y2);
  17822. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17823. /* 0x04 is secondary read mag x lsb register */
  17824. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  17825. &v_data_u8[BMM150_DIG_Y3], C_BMI160_ONE_U8X);
  17826. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17827. mag_trim.dig_y2 = v_data_u8[BMM150_DIG_Y3];
  17828. /* read dig_xy1 value */
  17829. com_rslt += bmi160_set_mag_read_addr(
  17830. BMI160_MAG_DIG_XY1);
  17831. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17832. /* 0x04 is secondary read mag x lsb register */
  17833. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  17834. &v_data_u8[BMM150_DIG_XY1], C_BMI160_ONE_U8X);
  17835. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17836. mag_trim.dig_xy1 = v_data_u8[BMM150_DIG_XY1];
  17837. /* read dig_xy2 value */
  17838. com_rslt += bmi160_set_mag_read_addr(
  17839. BMI160_MAG_DIG_XY2);
  17840. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17841. /* 0x04 is v_mag_x_s16 ls register */
  17842. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  17843. &v_data_u8[BMM150_DIG_XY2], C_BMI160_ONE_U8X);
  17844. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17845. mag_trim.dig_xy2 = v_data_u8[BMM150_DIG_XY2];
  17846. /* read dig_z1 lsb value */
  17847. com_rslt += bmi160_set_mag_read_addr(
  17848. BMI160_MAG_DIG_Z1_LSB);
  17849. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17850. /* 0x04 is secondary read mag x lsb register */
  17851. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  17852. &v_data_u8[BMM150_DIG_Z1_LSB], C_BMI160_ONE_U8X);
  17853. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17854. /* read dig_z1 msb value */
  17855. com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_Z1_MSB);
  17856. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17857. /* 0x04 is v_mag_x_s16 msb register */
  17858. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  17859. &v_data_u8[BMM150_DIG_Z1_MSB], C_BMI160_ONE_U8X);
  17860. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17861. mag_trim.dig_z1 =
  17862. (u16)((((u32)((u8)v_data_u8[BMM150_DIG_Z1_MSB]))
  17863. << BMI160_SHIFT_8_POSITION) |
  17864. (v_data_u8[BMM150_DIG_Z1_LSB]));
  17865. /* read dig_z2 lsb value */
  17866. com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_Z2_LSB);
  17867. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17868. /* 0x04 is secondary read mag x lsb register */
  17869. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  17870. &v_data_u8[BMM150_DIG_Z2_LSB], C_BMI160_ONE_U8X);
  17871. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17872. /* read dig_z2 msb value */
  17873. com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_Z2_MSB);
  17874. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17875. /* 0x04 is v_mag_x_s16 msb register */
  17876. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  17877. &v_data_u8[BMM150_DIG_Z2_MSB], C_BMI160_ONE_U8X);
  17878. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17879. mag_trim.dig_z2 =
  17880. (s16)((((s32)((s8)v_data_u8[BMM150_DIG_Z2_MSB]))
  17881. << BMI160_SHIFT_8_POSITION) |
  17882. (v_data_u8[BMM150_DIG_Z2_LSB]));
  17883. /* read dig_z3 lsb value */
  17884. com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_Z3_LSB);
  17885. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17886. /* 0x04 is secondary read mag x lsb register */
  17887. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  17888. &v_data_u8[BMM150_DIG_DIG_Z3_LSB], C_BMI160_ONE_U8X);
  17889. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17890. /* read dig_z3 msb value */
  17891. com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_Z3_MSB);
  17892. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17893. /* 0x04 is v_mag_x_s16 msb register */
  17894. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  17895. &v_data_u8[BMM150_DIG_DIG_Z3_MSB], C_BMI160_ONE_U8X);
  17896. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17897. mag_trim.dig_z3 =
  17898. (s16)((((s32)((s8)v_data_u8[BMM150_DIG_DIG_Z3_MSB]))
  17899. << BMI160_SHIFT_8_POSITION) |
  17900. (v_data_u8[BMM150_DIG_DIG_Z3_LSB]));
  17901. /* read dig_z4 lsb value */
  17902. com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_Z4_LSB);
  17903. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17904. /* 0x04 is secondary read mag x lsb register */
  17905. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  17906. &v_data_u8[BMM150_DIG_DIG_Z4_LSB], C_BMI160_ONE_U8X);
  17907. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17908. /* read dig_z4 msb value */
  17909. com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_Z4_MSB);
  17910. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17911. /* 0x04 is v_mag_x_s16 msb register */
  17912. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  17913. &v_data_u8[BMM150_DIG_DIG_Z4_MSB], C_BMI160_ONE_U8X);
  17914. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17915. mag_trim.dig_z4 =
  17916. (s16)((((s32)((s8)v_data_u8[BMM150_DIG_DIG_Z4_MSB]))
  17917. << BMI160_SHIFT_8_POSITION) |
  17918. (v_data_u8[BMM150_DIG_DIG_Z4_LSB]));
  17919. /* read dig_xyz1 lsb value */
  17920. com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_XYZ1_LSB);
  17921. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17922. /* 0x04 is secondary read mag x lsb register */
  17923. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  17924. &v_data_u8[BMM150_DIG_DIG_XYZ1_LSB], C_BMI160_ONE_U8X);
  17925. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17926. /* read dig_xyz1 msb value */
  17927. com_rslt += bmi160_set_mag_read_addr(BMI160_MAG_DIG_XYZ1_MSB);
  17928. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17929. /* 0x04 is v_mag_x_s16 msb register */
  17930. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  17931. &v_data_u8[BMM150_DIG_DIG_XYZ1_MSB], C_BMI160_ONE_U8X);
  17932. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17933. mag_trim.dig_xyz1 =
  17934. (u16)((((u32)((u8)v_data_u8[BMM150_DIG_DIG_XYZ1_MSB]))
  17935. << BMI160_SHIFT_8_POSITION) |
  17936. (v_data_u8[BMM150_DIG_DIG_XYZ1_LSB]));
  17937. return com_rslt;
  17938. }
  17939. /*!
  17940. * Description: This function used for initialize the AKM09911 sensor
  17941. *
  17942. *
  17943. * @return results of bus communication function
  17944. * @retval 0 -> Success
  17945. * @retval -1 -> Error
  17946. *
  17947. *
  17948. */
  17949. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_akm_mag_interface_init(void)
  17950. {
  17951. /* variable used for return the status of communication result*/
  17952. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  17953. u8 v_pull_value_u8 = C_BMI160_ZERO_U8X;
  17954. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  17955. /* accel operation mode to normal*/
  17956. com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL);
  17957. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17958. com_rslt += bmi160_set_command_register(MAG_MODE_NORMAL);
  17959. p_bmi160->delay_msec(C_BMI160_SIXTY_U8X);
  17960. bmi160_get_mag_power_mode_stat(&v_data_u8);
  17961. /* register 0x7E write the 0x37, 0x9A and 0x30*/
  17962. com_rslt += bmi160_set_command_register(BMI160_COMMAND_REG_ONE);
  17963. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  17964. com_rslt += bmi160_set_command_register(BMI160_COMMAND_REG_TWO);
  17965. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  17966. com_rslt += bmi160_set_command_register(BMI160_COMMAND_REG_THREE);
  17967. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  17968. /*switch the page1*/
  17969. com_rslt += bmi160_set_target_page(BMI160_HEX_0_1_DATA);
  17970. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17971. bmi160_get_target_page(&v_data_u8);
  17972. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17973. com_rslt += bmi160_set_paging_enable(BMI160_HEX_0_1_DATA);
  17974. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17975. bmi160_get_paging_enable(&v_data_u8);
  17976. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17977. /* enable the pullup configuration from
  17978. the register 0x85 bit 4 and 5 */
  17979. bmi160_get_pullup_configuration(&v_pull_value_u8);
  17980. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17981. v_pull_value_u8 = v_pull_value_u8 | BMI160_HEX_0_3_DATA;
  17982. com_rslt += bmi160_set_pullup_configuration(v_pull_value_u8);
  17983. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17984. /*switch the page0*/
  17985. com_rslt += bmi160_set_target_page(BMI160_HEX_0_0_DATA);
  17986. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17987. bmi160_get_target_page(&v_data_u8);
  17988. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17989. /* Write the AKM i2c address*/
  17990. com_rslt += bmi160_set_i2c_device_addr(BMI160_AKM09911_I2C_ADDRESS);
  17991. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17992. /* enable the mag interface to manual mode*/
  17993. com_rslt += bmi160_set_mag_manual_enable(BMI160_HEX_0_1_DATA);
  17994. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17995. bmi160_get_mag_manual_enable(&v_data_u8);
  17996. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  17997. /*Enable the MAG interface */
  17998. com_rslt += bmi160_set_if_mode(BMI160_HEX_0_2_DATA);
  17999. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18000. bmi160_get_if_mode(&v_data_u8);
  18001. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18002. /* Set the AKM Fuse ROM mode */
  18003. /* Set value for fuse ROM mode*/
  18004. com_rslt += bmi160_set_mag_write_data(AKM_FUSE_ROM_MODE);
  18005. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18006. /* AKM mode address is 0x31*/
  18007. com_rslt += bmi160_set_mag_write_addr(AKM_POWER_MODE_REG);
  18008. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  18009. /* Read the Fuse ROM v_data_u8 from registers
  18010. 0x60,0x61 and 0x62*/
  18011. /* ASAX v_data_u8 */
  18012. com_rslt += bmi160_read_bst_akm_sensitivity_data();
  18013. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  18014. /* Set value power down mode mode*/
  18015. com_rslt += bmi160_set_mag_write_data(AKM_POWER_DOWN_MODE_DATA);
  18016. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18017. /* AKM mode address is 0x31*/
  18018. com_rslt += bmi160_set_mag_write_addr(AKM_POWER_MODE_REG);
  18019. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  18020. /* Set AKM Force mode*/
  18021. com_rslt += bmi160_set_mag_write_data(
  18022. AKM_SINGLE_MEASUREMENT_MODE);
  18023. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18024. /* AKM mode address is 0x31*/
  18025. com_rslt += bmi160_set_mag_write_addr(AKM_POWER_MODE_REG);
  18026. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  18027. /* Set the AKM read xyz v_data_u8 address*/
  18028. com_rslt += bmi160_set_mag_read_addr(AKM_DATA_REGISTER);
  18029. /* write the mag v_data_bw_u8 as 25Hz*/
  18030. com_rslt += bmi160_set_mag_output_data_rate(
  18031. BMI160_MAG_OUTPUT_DATA_RATE_25HZ);
  18032. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18033. /* Enable mag interface to auto mode*/
  18034. com_rslt += bmi160_set_mag_manual_enable(BMI160_HEX_0_0_DATA);
  18035. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18036. bmi160_get_mag_manual_enable(&v_data_u8);
  18037. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18038. return com_rslt;
  18039. }
  18040. /*!
  18041. * @brief This function used for read the sensitivity data of
  18042. * AKM09911
  18043. *
  18044. * @note Before reading the mag sensitivity values
  18045. * make sure the following two points are addressed
  18046. * @note 1. Make sure the mag interface is enabled or not,
  18047. * by using the bmi160_get_if_mode() function.
  18048. * If mag interface is not enabled set the value of 0x02
  18049. * to the function bmi160_get_if_mode(0x02)
  18050. * @note 2. And also confirm the secondary-interface power mode
  18051. * is not in the SUSPEND mode.
  18052. * by using the function bmi160_get_mag_pmu_status().
  18053. * If the secondary-interface power mode is in SUSPEND mode
  18054. * set the value of 0x19(NORMAL mode)by using the
  18055. * bmi160_set_command_register(0x19) function.
  18056. *
  18057. * @return results of bus communication function
  18058. * @retval 0 -> Success
  18059. * @retval -1 -> Error
  18060. *
  18061. *
  18062. */
  18063. BMI160_RETURN_FUNCTION_TYPE bmi160_read_bst_akm_sensitivity_data(void)
  18064. {
  18065. /* This variable used for provide the communication
  18066. results*/
  18067. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  18068. /* Array holding the sensitivity ax,ay and az data*/
  18069. u8 v_data_u8[ARRAY_SIZE_THREE] = {C_BMI160_ZERO_U8X,
  18070. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X};
  18071. /* read asax value */
  18072. com_rslt = bmi160_set_mag_read_addr(BMI160_BST_AKM_ASAX);
  18073. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18074. /* 0x04 is secondary read mag x lsb register */
  18075. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  18076. &v_data_u8[AKM_ASAX],
  18077. C_BMI160_ONE_U8X);
  18078. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18079. akm_asa_data.asax = v_data_u8[AKM_ASAX];
  18080. /* read asay value */
  18081. com_rslt += bmi160_set_mag_read_addr(BMI160_BST_AKM_ASAY);
  18082. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18083. /* 0x04 is secondary read mag x lsb register */
  18084. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  18085. &v_data_u8[AKM_ASAY],
  18086. C_BMI160_ONE_U8X);
  18087. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18088. akm_asa_data.asay = v_data_u8[AKM_ASAY];
  18089. /* read asaz value */
  18090. com_rslt += bmi160_set_mag_read_addr(BMI160_BST_AKM_ASAZ);
  18091. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18092. /* 0x04 is secondary read mag x lsb register */
  18093. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  18094. &v_data_u8[AKM_ASAZ],
  18095. C_BMI160_ONE_U8X);
  18096. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18097. akm_asa_data.asaz = v_data_u8[AKM_ASAZ];
  18098. return com_rslt;
  18099. }
  18100. /*!
  18101. * @brief This API used to get the compensated X data
  18102. * of AKM09911 the out put of X as s16
  18103. * @note Before start reading the mag compensated X data
  18104. * make sure the following two points are addressed
  18105. * @note 1. Make sure the mag interface is enabled or not,
  18106. * by using the bmi160_get_if_mode() function.
  18107. * If mag interface is not enabled set the value of 0x02
  18108. * to the function bmi160_get_if_mode(0x02)
  18109. * @note 2. And also confirm the secondary-interface power mode
  18110. * is not in the SUSPEND mode.
  18111. * by using the function bmi160_get_mag_pmu_status().
  18112. * If the secondary-interface power mode is in SUSPEND mode
  18113. * set the value of 0x19(NORMAL mode)by using the
  18114. * bmi160_set_command_register(0x19) function.
  18115. *
  18116. *
  18117. * @param v_bst_akm_x_s16 : The value of X data
  18118. *
  18119. * @return results of compensated X data value output as s16
  18120. *
  18121. */
  18122. s16 bmi160_bst_akm_compensate_X(s16 v_bst_akm_x_s16)
  18123. {
  18124. /*Return value of AKM x compensated v_data_u8*/
  18125. s16 retval = C_BMI160_ZERO_U8X;
  18126. /* Convert raw v_data_u8 into compensated v_data_u8*/
  18127. retval = (v_bst_akm_x_s16 *
  18128. ((akm_asa_data.asax/AKM09911_SENSITIVITY_DIV) +
  18129. C_BMI160_ONE_U8X));
  18130. return retval;
  18131. }
  18132. /*!
  18133. * @brief This API used to get the compensated Y data
  18134. * of AKM09911 the out put of Y as s16
  18135. * @note Before start reading the mag compensated Y data
  18136. * make sure the following two points are addressed
  18137. * @note 1. Make sure the mag interface is enabled or not,
  18138. * by using the bmi160_get_if_mode() function.
  18139. * If mag interface is not enabled set the value of 0x02
  18140. * to the function bmi160_get_if_mode(0x02)
  18141. * @note 2. And also confirm the secondary-interface power mode
  18142. * is not in the SUSPEND mode.
  18143. * by using the function bmi160_get_mag_pmu_status().
  18144. * If the secondary-interface power mode is in SUSPEND mode
  18145. * set the value of 0x19(NORMAL mode)by using the
  18146. * bmi160_set_command_register(0x19) function.
  18147. *
  18148. *
  18149. * @param v_bst_akm_y_s16 : The value of Y data
  18150. *
  18151. * @return results of compensated Y data value output as s16
  18152. *
  18153. */
  18154. s16 bmi160_bst_akm_compensate_Y(s16 v_bst_akm_y_s16)
  18155. {
  18156. /*Return value of AKM y compensated v_data_u8*/
  18157. s16 retval = C_BMI160_ZERO_U8X;
  18158. /* Convert raw v_data_u8 into compensated v_data_u8*/
  18159. retval = (v_bst_akm_y_s16 *
  18160. ((akm_asa_data.asay/AKM09911_SENSITIVITY_DIV) +
  18161. C_BMI160_ONE_U8X));
  18162. return retval;
  18163. }
  18164. /*!
  18165. * @brief This API used to get the compensated Z data
  18166. * of AKM09911 the out put of Z as s16
  18167. * @note Before start reading the mag compensated Z data
  18168. * make sure the following two points are addressed
  18169. * @note 1. Make sure the mag interface is enabled or not,
  18170. * by using the bmi160_get_if_mode() function.
  18171. * If mag interface is not enabled set the value of 0x02
  18172. * to the function bmi160_get_if_mode(0x02)
  18173. * @note 2. And also confirm the secondary-interface power mode
  18174. * is not in the SUSPEND mode.
  18175. * by using the function bmi160_get_mag_pmu_status().
  18176. * If the secondary-interface power mode is in SUSPEND mode
  18177. * set the value of 0x19(NORMAL mode)by using the
  18178. * bmi160_set_command_register(0x19) function.
  18179. *
  18180. *
  18181. * @param v_bst_akm_z_s16 : The value of Z data
  18182. *
  18183. * @return results of compensated Z data value output as s16
  18184. *
  18185. */
  18186. s16 bmi160_bst_akm_compensate_Z(s16 v_bst_akm_z_s16)
  18187. {
  18188. /*Return value of AKM z compensated v_data_u8*/
  18189. s16 retval = C_BMI160_ZERO_U8X;
  18190. /* Convert raw v_data_u8 into compensated v_data_u8*/
  18191. retval = (v_bst_akm_z_s16 *
  18192. ((akm_asa_data.asaz/AKM09911_SENSITIVITY_DIV) +
  18193. C_BMI160_ONE_U8X));
  18194. return retval;
  18195. }
  18196. /*!
  18197. * @brief This function used for read the compensated value of
  18198. * AKM09911
  18199. * @note Before start reading the mag compensated v_data_u8's
  18200. * make sure the following two points are addressed
  18201. * @note 1. Make sure the mag interface is enabled or not,
  18202. * by using the bmi160_get_if_mode() function.
  18203. * If mag interface is not enabled set the value of 0x02
  18204. * to the function bmi160_get_if_mode(0x02)
  18205. * @note 2. And also confirm the secondary-interface power mode
  18206. * is not in the SUSPEND mode.
  18207. * by using the function bmi160_get_mag_pmu_status().
  18208. * If the secondary-interface power mode is in SUSPEND mode
  18209. * set the value of 0x19(NORMAL mode)by using the
  18210. * bmi160_set_command_register(0x19) function.
  18211. *
  18212. * @return results of bus communication function
  18213. * @retval 0 -> Success
  18214. * @retval -1 -> Error
  18215. *
  18216. *
  18217. */
  18218. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_akm_compensate_xyz(
  18219. struct bmi160_bst_akm_xyz_t *bst_akm_xyz)
  18220. {
  18221. /* variable used for return the status of communication result*/
  18222. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  18223. struct bmi160_mag_t mag_xyz;
  18224. com_rslt = bmi160_read_mag_xyz(&mag_xyz, C_BMI160_ONE_U8X);
  18225. /* Compensation for X axis */
  18226. bst_akm_xyz->x = bmi160_bst_akm_compensate_X(mag_xyz.x);
  18227. /* Compensation for Y axis */
  18228. bst_akm_xyz->y = bmi160_bst_akm_compensate_Y(mag_xyz.y);
  18229. /* Compensation for Z axis */
  18230. bst_akm_xyz->z = bmi160_bst_akm_compensate_Z(mag_xyz.z);
  18231. return com_rslt;
  18232. }
  18233. /*!
  18234. * @brief This function used for set the AKM09911
  18235. * power mode.
  18236. * @note Before set the AKM power mode
  18237. * make sure the following two points are addressed
  18238. * @note 1. Make sure the mag interface is enabled or not,
  18239. * by using the bmi160_get_if_mode() function.
  18240. * If mag interface is not enabled set the value of 0x02
  18241. * to the function bmi160_get_if_mode(0x02)
  18242. * @note 2. And also confirm the secondary-interface power mode
  18243. * is not in the SUSPEND mode.
  18244. * by using the function bmi160_get_mag_pmu_status().
  18245. * If the secondary-interface power mode is in SUSPEND mode
  18246. * set the value of 0x19(NORMAL mode)by using the
  18247. * bmi160_set_command_register(0x19) function.
  18248. *
  18249. * @param v_akm_pow_mode_u8 : The value of akm power mode
  18250. * value | Description
  18251. * ---------|--------------------
  18252. * 0 | AKM_POWER_DOWN_MODE
  18253. * 1 | AKM_SINGLE_MEAS_MODE
  18254. * 2 | FUSE_ROM_MODE
  18255. *
  18256. *
  18257. * @return results of bus communication function
  18258. * @retval 0 -> Success
  18259. * @retval -1 -> Error
  18260. *
  18261. *
  18262. */
  18263. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_akm_set_powermode(
  18264. u8 v_akm_pow_mode_u8)
  18265. {
  18266. /* variable used for return the status of communication result*/
  18267. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  18268. switch (v_akm_pow_mode_u8) {
  18269. case AKM_POWER_DOWN_MODE:
  18270. /* set mag interface manual mode*/
  18271. if (p_bmi160->mag_manual_enable != BMI160_HEX_0_1_DATA) {
  18272. com_rslt = bmi160_set_mag_manual_enable(
  18273. BMI160_HEX_0_1_DATA);
  18274. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18275. }
  18276. /* Set the power mode of AKM as power down mode*/
  18277. com_rslt += bmi160_set_mag_write_data(AKM_POWER_DOWN_MODE_DATA);
  18278. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18279. com_rslt += bmi160_set_mag_write_addr(AKM_POWER_MODE_REG);
  18280. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  18281. /* set mag interface auto mode*/
  18282. if (p_bmi160->mag_manual_enable == BMI160_HEX_0_1_DATA) {
  18283. com_rslt += bmi160_set_mag_manual_enable(
  18284. BMI160_HEX_0_0_DATA);
  18285. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18286. }
  18287. break;
  18288. case AKM_SINGLE_MEAS_MODE:
  18289. /* set mag interface manual mode*/
  18290. if (p_bmi160->mag_manual_enable != BMI160_HEX_0_1_DATA) {
  18291. com_rslt = bmi160_set_mag_manual_enable(
  18292. BMI160_HEX_0_1_DATA);
  18293. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18294. }
  18295. /* Set the power mode of AKM as
  18296. single measurement mode*/
  18297. com_rslt += bmi160_set_mag_write_data
  18298. (AKM_SINGLE_MEASUREMENT_MODE);
  18299. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18300. com_rslt += bmi160_set_mag_write_addr(AKM_POWER_MODE_REG);
  18301. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  18302. com_rslt += bmi160_set_mag_read_addr(AKM_DATA_REGISTER);
  18303. /* set mag interface auto mode*/
  18304. if (p_bmi160->mag_manual_enable == BMI160_HEX_0_1_DATA) {
  18305. com_rslt += bmi160_set_mag_manual_enable(
  18306. BMI160_HEX_0_0_DATA);
  18307. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18308. }
  18309. break;
  18310. case FUSE_ROM_MODE:
  18311. /* set mag interface manual mode*/
  18312. if (p_bmi160->mag_manual_enable != BMI160_HEX_0_1_DATA) {
  18313. com_rslt = bmi160_set_mag_manual_enable(
  18314. BMI160_HEX_0_1_DATA);
  18315. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18316. }
  18317. /* Set the power mode of AKM as
  18318. Fuse ROM mode*/
  18319. com_rslt += bmi160_set_mag_write_data(AKM_FUSE_ROM_MODE);
  18320. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18321. com_rslt += bmi160_set_mag_write_addr(AKM_POWER_MODE_REG);
  18322. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  18323. /* Sensitivity v_data_u8 */
  18324. com_rslt += bmi160_read_bst_akm_sensitivity_data();
  18325. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  18326. /* power down mode*/
  18327. com_rslt += bmi160_set_mag_write_data(AKM_POWER_DOWN_MODE);
  18328. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18329. com_rslt += bmi160_set_mag_write_addr(AKM_POWER_MODE_REG);
  18330. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  18331. /* set mag interface auto mode*/
  18332. if (p_bmi160->mag_manual_enable == BMI160_HEX_0_1_DATA) {
  18333. com_rslt += bmi160_set_mag_manual_enable(
  18334. BMI160_HEX_0_0_DATA);
  18335. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18336. }
  18337. break;
  18338. default:
  18339. com_rslt = E_BMI160_OUT_OF_RANGE;
  18340. break;
  18341. }
  18342. return com_rslt;
  18343. }
  18344. /*!
  18345. * @brief This function used for set the magnetometer
  18346. * power mode.
  18347. * @note Before set the mag power mode
  18348. * make sure the following two point is addressed
  18349. * Make sure the mag interface is enabled or not,
  18350. * by using the bmi160_get_if_mode() function.
  18351. * If mag interface is not enabled set the value of 0x02
  18352. * to the function bmi160_get_if_mode(0x02)
  18353. *
  18354. * @param v_mag_sec_if_pow_mode_u8 : The value of secondary if power mode
  18355. * value | Description
  18356. * ---------|--------------------
  18357. * 0 | BMI160_MAG_FORCE_MODE
  18358. * 1 | BMI160_MAG_SUSPEND_MODE
  18359. *
  18360. *
  18361. * @return results of bus communication function
  18362. * @retval 0 -> Success
  18363. * @retval -1 -> Error
  18364. *
  18365. *
  18366. */
  18367. BMI160_RETURN_FUNCTION_TYPE bmi160_set_bst_akm_and_secondary_if_powermode(
  18368. u8 v_mag_sec_if_pow_mode_u8)
  18369. {
  18370. /* variable used for return the status of communication result*/
  18371. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  18372. /* accel operation mode to normal*/
  18373. com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL);
  18374. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18375. switch (v_mag_sec_if_pow_mode_u8) {
  18376. case BMI160_MAG_FORCE_MODE:
  18377. /* set mag interface manual mode*/
  18378. if (p_bmi160->mag_manual_enable != BMI160_HEX_0_1_DATA) {
  18379. com_rslt = bmi160_set_mag_manual_enable(
  18380. BMI160_HEX_0_1_DATA);
  18381. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18382. }
  18383. /* set the secondary mag power mode as NORMAL*/
  18384. com_rslt += bmi160_set_command_register(MAG_MODE_NORMAL);
  18385. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  18386. /* set the akm power mode as single measurement mode*/
  18387. com_rslt += bmi160_bst_akm_set_powermode(AKM_SINGLE_MEAS_MODE);
  18388. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  18389. com_rslt += bmi160_set_mag_read_addr(AKM_DATA_REGISTER);
  18390. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18391. /* set mag interface auto mode*/
  18392. if (p_bmi160->mag_manual_enable == BMI160_HEX_0_1_DATA)
  18393. com_rslt += bmi160_set_mag_manual_enable(
  18394. BMI160_HEX_0_0_DATA);
  18395. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18396. break;
  18397. case BMI160_MAG_SUSPEND_MODE:
  18398. /* set mag interface manual mode*/
  18399. if (p_bmi160->mag_manual_enable != BMI160_HEX_0_1_DATA)
  18400. com_rslt = bmi160_set_mag_manual_enable(
  18401. BMI160_HEX_0_1_DATA);
  18402. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18403. /* set the akm power mode as power down mode*/
  18404. com_rslt += bmi160_bst_akm_set_powermode(AKM_POWER_DOWN_MODE);
  18405. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  18406. /* set the secondary mag power mode as SUSPEND*/
  18407. com_rslt += bmi160_set_command_register(MAG_MODE_SUSPEND);
  18408. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  18409. /* set mag interface auto mode*/
  18410. if (p_bmi160->mag_manual_enable == BMI160_HEX_0_1_DATA)
  18411. com_rslt += bmi160_set_mag_manual_enable(
  18412. BMI160_HEX_0_0_DATA);
  18413. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18414. break;
  18415. default:
  18416. com_rslt = E_BMI160_OUT_OF_RANGE;
  18417. break;
  18418. }
  18419. return com_rslt;
  18420. }
  18421. /*!
  18422. * @brief This function used for read the YAMAH-YAS532 init
  18423. *
  18424. *
  18425. * @return results of bus communication function
  18426. * @retval 0 -> Success
  18427. * @retval -1 -> Error
  18428. *
  18429. *
  18430. */
  18431. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yamaha_yas532_mag_interface_init(
  18432. void)
  18433. {
  18434. /* This variable used for provide the communication
  18435. results*/
  18436. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  18437. u8 v_pull_value_u8 = C_BMI160_ZERO_U8X;
  18438. u8 v_data_u8 = C_BMI160_ZERO_U8X;
  18439. u8 i = C_BMI160_ZERO_U8X;
  18440. /* accel operation mode to normal*/
  18441. com_rslt = bmi160_set_command_register(ACCEL_MODE_NORMAL);
  18442. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18443. com_rslt += bmi160_set_command_register(MAG_MODE_NORMAL);
  18444. p_bmi160->delay_msec(C_BMI160_SIXTY_U8X);
  18445. bmi160_get_mag_power_mode_stat(&v_data_u8);
  18446. /* register 0x7E write the 0x37, 0x9A and 0x30*/
  18447. com_rslt += bmi160_set_command_register(BMI160_COMMAND_REG_ONE);
  18448. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  18449. com_rslt += bmi160_set_command_register(BMI160_COMMAND_REG_TWO);
  18450. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  18451. com_rslt += bmi160_set_command_register(BMI160_COMMAND_REG_THREE);
  18452. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  18453. /*switch the page1*/
  18454. com_rslt += bmi160_set_target_page(BMI160_HEX_0_1_DATA);
  18455. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18456. bmi160_get_target_page(&v_data_u8);
  18457. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18458. com_rslt += bmi160_set_paging_enable(BMI160_HEX_0_1_DATA);
  18459. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18460. bmi160_get_paging_enable(&v_data_u8);
  18461. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18462. /* enable the pullup configuration from
  18463. the register 0x85 bit 4 and 5 */
  18464. bmi160_get_pullup_configuration(&v_pull_value_u8);
  18465. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18466. v_pull_value_u8 = v_pull_value_u8 | BMI160_HEX_0_3_DATA;
  18467. com_rslt += bmi160_set_pullup_configuration(v_pull_value_u8);
  18468. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18469. /*switch the page0*/
  18470. com_rslt += bmi160_set_target_page(BMI160_HEX_0_0_DATA);
  18471. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18472. bmi160_get_target_page(&v_data_u8);
  18473. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18474. /* Write the YAS532 i2c address*/
  18475. com_rslt += bmi160_set_i2c_device_addr(BMI160_YAS532_I2C_ADDRESS);
  18476. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18477. /* enable the mag interface to manual mode*/
  18478. com_rslt += bmi160_set_mag_manual_enable(BMI160_HEX_0_1_DATA);
  18479. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18480. bmi160_get_mag_manual_enable(&v_data_u8);
  18481. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18482. /*Enable the MAG interface */
  18483. com_rslt += bmi160_set_if_mode(BMI160_HEX_0_2_DATA);
  18484. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18485. bmi160_get_if_mode(&v_data_u8);
  18486. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18487. v_data_u8 = BMI160_HEX_0_0_DATA;
  18488. /* Read the YAS532 device id*/
  18489. com_rslt += bmi160_set_mag_read_addr(BMI160_HEX_8_0_DATA);
  18490. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18491. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  18492. &v_data_u8, C_BMI160_ONE_U8X);
  18493. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18494. /* Read the YAS532 calibration data*/
  18495. com_rslt += bmi160_bst_yamaha_yas532_calib_values();
  18496. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  18497. /* Assign the data acquisition mode*/
  18498. yas532_data.measure_state = YAS532_MAG_STATE_INIT_COIL;
  18499. /* Set the default offset as invalid offset*/
  18500. set_vector(yas532_data.v_hard_offset_s8, INVALID_OFFSET);
  18501. /* set the transform to zero */
  18502. yas532_data.transform = BMI160_NULL;
  18503. /* Assign overflow as zero*/
  18504. yas532_data.overflow = C_BMI160_ZERO_U8X;
  18505. #if 1 < YAS532_MAG_TEMPERATURE_LOG
  18506. yas532_data.temp_data.num =
  18507. yas532_data.temp_data.idx = C_BMI160_ZERO_U8X;
  18508. #endif
  18509. /* Assign the coef value*/
  18510. for (i = C_BMI160_ZERO_U8X; i < C_BMI160_THREE_U8X; i++) {
  18511. yas532_data.coef[i] = yas532_version_ac_coef[i];
  18512. yas532_data.last_raw[i] = C_BMI160_ZERO_U8X;
  18513. }
  18514. yas532_data.last_raw[INDEX_THREE] = C_BMI160_ZERO_U8X;
  18515. /* Set the initial values of yas532*/
  18516. com_rslt += bmi160_bst_yas532_set_initial_values();
  18517. /* write the mag v_data_bw_u8 as 25Hz*/
  18518. com_rslt += bmi160_set_mag_output_data_rate(
  18519. BMI160_MAG_OUTPUT_DATA_RATE_25HZ);
  18520. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18521. /* Enable mag interface to auto mode*/
  18522. com_rslt += bmi160_set_mag_manual_enable(
  18523. BMI160_HEX_0_0_DATA);
  18524. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18525. bmi160_get_mag_manual_enable(&v_data_u8);
  18526. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18527. return com_rslt;
  18528. }
  18529. /*!
  18530. * @brief This function used to set the YAS532 initial values
  18531. *
  18532. *
  18533. * @return results of bus communication function
  18534. * @retval 0 -> Success
  18535. * @retval -1 -> Error
  18536. *
  18537. *
  18538. */
  18539. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yas532_set_initial_values(void)
  18540. {
  18541. /* This variable used for provide the communication
  18542. results*/
  18543. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  18544. /* write testr1 as 0x00*/
  18545. com_rslt = bmi160_set_mag_write_data(
  18546. BMI160_YAS532_WRITE_DATA_ZERO);
  18547. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  18548. com_rslt += bmi160_set_mag_write_addr(BMI160_YAS532_TESTR1);
  18549. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  18550. /* write testr2 as 0x00*/
  18551. com_rslt += bmi160_set_mag_write_data(
  18552. BMI160_YAS532_WRITE_DATA_ZERO);
  18553. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  18554. com_rslt += bmi160_set_mag_write_addr(BMI160_YAS532_TESTR2);
  18555. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  18556. /* write Rcoil as 0x00*/
  18557. com_rslt += bmi160_set_mag_write_data(
  18558. BMI160_YAS532_WRITE_DATA_ZERO);
  18559. p_bmi160->delay_msec(C_BMI160_FIVE_U8X);
  18560. com_rslt += bmi160_set_mag_write_addr(BMI160_YAS532_RCOIL);
  18561. p_bmi160->delay_msec(C_BMI160_TWO_HUNDRED_U8X);
  18562. /* check the valid offset*/
  18563. if (is_valid_offset(yas532_data.v_hard_offset_s8)) {
  18564. com_rslt += bmi160_bst_yas532_set_offset(
  18565. yas532_data.v_hard_offset_s8);
  18566. yas532_data.measure_state = YAS532_MAG_STATE_NORMAL;
  18567. } else {
  18568. /* set the default offset as invalid offset*/
  18569. set_vector(yas532_data.v_hard_offset_s8, INVALID_OFFSET);
  18570. /*Set the default measure state for offset correction*/
  18571. yas532_data.measure_state = YAS532_MAG_STATE_MEASURE_OFFSET;
  18572. }
  18573. return com_rslt;
  18574. }
  18575. /*!
  18576. * @brief This function used for YAS532 offset correction
  18577. *
  18578. *
  18579. * @return results of bus communication function
  18580. * @retval 0 -> Success
  18581. * @retval -1 -> Error
  18582. *
  18583. *
  18584. */
  18585. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yas532_magnetic_measure_set_offset(
  18586. void)
  18587. {
  18588. /* This variable used for provide the communication
  18589. results*/
  18590. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  18591. /* used for offset value set to the offset register*/
  18592. s8 v_hard_offset_s8[ARRAY_SIZE_THREE] = {C_BMI160_ZERO_U8X,
  18593. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X};
  18594. /* offset correction factors*/
  18595. static const u8 v_correct_u8[ARRAY_SIZE_FIVE] = {
  18596. YAS532_CORRECT_OFFSET_16,
  18597. YAS532_CORRECT_OFFSET_8, YAS532_CORRECT_OFFSET_4,
  18598. YAS532_CORRECT_OFFSET_2, YAS532_CORRECT_OFFSET_1};
  18599. /* used for the temperature */
  18600. u16 v_temp_u16 = C_BMI160_ZERO_U8X;
  18601. /* used for the xy1y2 read*/
  18602. u16 v_xy1y2_u16[ARRAY_SIZE_THREE] = {C_BMI160_ZERO_U8X,
  18603. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X};
  18604. /* local flag for assign the values*/
  18605. s32 v_flag_s32[ARRAY_SIZE_THREE] = {C_BMI160_ZERO_U8X,
  18606. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X};
  18607. u8 i, j, v_busy_u8, v_overflow_u8 = C_BMI160_ZERO_U8X;
  18608. for (i = C_BMI160_ZERO_U8X; i < C_BMI160_FIVE_U8X; i++) {
  18609. /* set the offset values*/
  18610. com_rslt = bmi160_bst_yas532_set_offset(v_hard_offset_s8);
  18611. /* read the sensor data*/
  18612. com_rslt += bmi160_bst_yas532_normal_measurement_data(
  18613. BMI160_HEX_1_1_DATA, &v_busy_u8, &v_temp_u16,
  18614. v_xy1y2_u16, &v_overflow_u8);
  18615. /* check the sensor busy status*/
  18616. if (v_busy_u8)
  18617. return E_BMI160_BUSY;
  18618. /* calculate the magnetic correction with
  18619. offset and assign the values
  18620. to the offset register */
  18621. for (j = C_BMI160_ZERO_U8X; j < C_BMI160_THREE_U8X; j++) {
  18622. if (YAS532_DATA_CENTER == v_xy1y2_u16[j])
  18623. v_flag_s32[j] = C_BMI160_ZERO_U8X;
  18624. if (YAS532_DATA_CENTER < v_xy1y2_u16[j])
  18625. v_flag_s32[j] = C_BMI160_ONE_U8X;
  18626. if (v_xy1y2_u16[j] < YAS532_DATA_CENTER)
  18627. v_flag_s32[j] = C_BMI160_MINUS_ONE_S8X;
  18628. }
  18629. for (j = C_BMI160_ZERO_U8X; j < C_BMI160_THREE_U8X; j++) {
  18630. if (v_flag_s32[j])
  18631. v_hard_offset_s8[j] = (s8)(v_hard_offset_s8[j]
  18632. + v_flag_s32[j] * v_correct_u8[i]);
  18633. }
  18634. }
  18635. /* set the offset */
  18636. com_rslt += bmi160_bst_yas532_set_offset(v_hard_offset_s8);
  18637. return com_rslt;
  18638. }
  18639. /*!
  18640. * @brief This function used for read the
  18641. * YAMAHA YAS532 calibration data
  18642. *
  18643. *
  18644. * @return results of bus communication function
  18645. * @retval 0 -> Success
  18646. * @retval -1 -> Error
  18647. *
  18648. *
  18649. */
  18650. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yamaha_yas532_calib_values(void)
  18651. {
  18652. /* This variable used for provide the communication
  18653. results*/
  18654. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  18655. /* Array holding the YAS532 calibration values */
  18656. u8 v_data_u8[ARRAY_SIZE_FOURTEEN] = {
  18657. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X,
  18658. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X,
  18659. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X,
  18660. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X,
  18661. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X};
  18662. /* Read the DX value */
  18663. com_rslt = bmi160_set_mag_read_addr(BMI160_YAS532_CALIB_CX);
  18664. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18665. /* 0x04 is secondary read mag x lsb register */
  18666. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  18667. &v_data_u8[YAS532_CALIB_CX], C_BMI160_ONE_U8X);
  18668. yas532_data.calib_yas532.cx = (s32)((v_data_u8[YAS532_CALIB_CX]
  18669. * C_BMI160_TEN_U8X) -
  18670. YAS532_CALIB_THOUSAND_TWO_EIGHTY);
  18671. /* Read the DY1 value */
  18672. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB_CY1);
  18673. /* 0x04 is secondary read mag x lsb register */
  18674. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  18675. &v_data_u8[YAS532_CALIB_CY1], C_BMI160_ONE_U8X);
  18676. yas532_data.calib_yas532.cy1 =
  18677. (s32)((v_data_u8[YAS532_CALIB_CY1] * C_BMI160_TEN_U8X) -
  18678. YAS532_CALIB_THOUSAND_TWO_EIGHTY);
  18679. /* Read the DY2 value */
  18680. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB_CY2);
  18681. /* 0x04 is secondary read mag x lsb register */
  18682. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  18683. &v_data_u8[YAS532_CALIB_CY2], C_BMI160_ONE_U8X);
  18684. yas532_data.calib_yas532.cy2 =
  18685. (s32)((v_data_u8[YAS532_CALIB_CY2] * C_BMI160_TEN_U8X) -
  18686. YAS532_CALIB_THOUSAND_TWO_EIGHTY);
  18687. /* Read the D2 and D3 value */
  18688. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB1);
  18689. /* 0x04 is secondary read mag x lsb register */
  18690. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  18691. &v_data_u8[INDEX_THREE], C_BMI160_ONE_U8X);
  18692. yas532_data.calib_yas532.a2 =
  18693. (s32)(((v_data_u8[INDEX_THREE] >> C_BMI160_TWO_U8X)
  18694. & YAS532_CALIB_HEX_ZERO_THREE_F) - C_BMI160_THIRTY_TWO_U8X);
  18695. /* Read the D3 and D4 value */
  18696. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB2);
  18697. /* 0x04 is secondary read mag x lsb register */
  18698. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  18699. &v_data_u8[INDEX_FOUR], C_BMI160_ONE_U8X);
  18700. /* calculate a3*/
  18701. yas532_data.calib_yas532.a3 = (s32)((((v_data_u8[INDEX_THREE] <<
  18702. C_BMI160_TWO_U8X) & YAS532_CALIB_HEX_ZERO_C) |
  18703. ((v_data_u8[INDEX_FOUR]
  18704. >> C_BMI160_SIX_U8X) & YAS532_CALIB_HEX_ZERO_THREE)) -
  18705. C_BMI160_EIGHT_U8X);
  18706. /* calculate a4*/
  18707. yas532_data.calib_yas532.a4 = (s32)((v_data_u8[INDEX_FOUR]
  18708. & YAS532_CALIB_HEX_THREE_F) - C_BMI160_THIRTY_TWO_U8X);
  18709. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  18710. /* Read the D5 and D6 value */
  18711. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB3);
  18712. /* 0x04 is secondary read mag x lsb register */
  18713. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  18714. &v_data_u8[INDEX_FIVE], C_BMI160_ONE_U8X);
  18715. /* calculate a5*/
  18716. yas532_data.calib_yas532.a5 =
  18717. (s32)(((v_data_u8[INDEX_FIVE] >> C_BMI160_TWO_U8X)
  18718. & YAS532_CALIB_HEX_THREE_F) + C_BMI160_THIRTY_EIGHT_U8X);
  18719. /* Read the D6 and D7 value */
  18720. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB4);
  18721. /* 0x04 is secondary read mag x lsb register */
  18722. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  18723. &v_data_u8[INDEX_SIX], C_BMI160_ONE_U8X);
  18724. /* calculate a6*/
  18725. yas532_data.calib_yas532.a6 =
  18726. (s32)((((v_data_u8[INDEX_FIVE] << C_BMI160_FOUR_U8X)
  18727. & YAS532_CALIB_HEX_THREE_ZERO) |
  18728. ((v_data_u8[INDEX_SIX] >>
  18729. C_BMI160_FOUR_U8X) & YAS532_CALIB_HEX_ZERO_F)) -
  18730. C_BMI160_THIRTY_TWO_U8X);
  18731. /* Read the D7 and D8 value */
  18732. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB5);
  18733. /* 0x04 is secondary read mag x lsb register */
  18734. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  18735. &v_data_u8[INDEX_SEVEN], C_BMI160_ONE_U8X);
  18736. /* calculate a7*/
  18737. yas532_data.calib_yas532.a7 = (s32)((((v_data_u8[INDEX_SIX]
  18738. << C_BMI160_THREE_U8X) & YAS532_CALIB_HEX_SEVEN_EIGHT) |
  18739. ((v_data_u8[INDEX_SEVEN] >> C_BMI160_FIVE_U8X) &
  18740. YAS532_CALIB_HEX_ZERO_SEVEN)) -
  18741. C_BMI160_SIXTY_FOUR_U8X);
  18742. /* Read the D8 and D9 value */
  18743. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CLAIB6);
  18744. /* 0x04 is secondary read mag x lsb register */
  18745. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  18746. &v_data_u8[INDEX_EIGHT], C_BMI160_ONE_U8X);
  18747. /* calculate a8*/
  18748. yas532_data.calib_yas532.a8 = (s32)((((v_data_u8[INDEX_SEVEN] <<
  18749. C_BMI160_ONE_U8X) & YAS532_CALIB_HEX_THREE_E) |
  18750. ((v_data_u8[INDEX_EIGHT] >>
  18751. C_BMI160_SEVEN_U8X) & YAS532_CALIB_HEX_ZERO_ONE)) -
  18752. C_BMI160_THIRTY_TWO_U8X);
  18753. /* Read the D8 and D9 value */
  18754. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB7);
  18755. /* 0x04 is secondary read mag x lsb register */
  18756. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  18757. &v_data_u8[INDEX_NINE], C_BMI160_ONE_U8X);
  18758. /* calculate a9*/
  18759. yas532_data.calib_yas532.a9 = (s32)(((v_data_u8[INDEX_EIGHT] <<
  18760. C_BMI160_ONE_U8X) & YAS532_CALIB_HEX_F_E) |
  18761. ((v_data_u8[INDEX_NINE] >>
  18762. C_BMI160_SEVEN_U8X) & YAS532_CALIB_HEX_ZERO_ONE));
  18763. /* calculate k*/
  18764. yas532_data.calib_yas532.k = (s32)((v_data_u8[INDEX_NINE] >>
  18765. C_BMI160_TWO_U8X) & YAS532_CALIB_HEX_ONE_F);
  18766. /* Read the value from register 0x9A*/
  18767. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB8);
  18768. /* 0x04 is secondary read mag x lsb register */
  18769. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  18770. &v_data_u8[INDEX_TEN],
  18771. C_BMI160_ONE_U8X);
  18772. /* Read the value from register 0x9B*/
  18773. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIIB9);
  18774. /* 0x04 is secondary read mag x lsb register */
  18775. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  18776. &v_data_u8[INDEX_ELEVEN],
  18777. C_BMI160_ONE_U8X);
  18778. /* Read the value from register 0x9C*/
  18779. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB10);
  18780. /* 0x04 is secondary read mag x lsb register */
  18781. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  18782. &v_data_u8[INDEX_TWELVE],
  18783. C_BMI160_ONE_U8X);
  18784. /* Read the value from register 0x9D*/
  18785. com_rslt += bmi160_set_mag_read_addr(BMI160_YAS532_CALIB11);
  18786. /* 0x04 is secondary read mag x lsb register */
  18787. com_rslt += bmi160_read_reg(BMI160_HEX_0_4_DATA,
  18788. &v_data_u8[INDEX_THIRTEEN],
  18789. C_BMI160_ONE_U8X);
  18790. /* Calculate the fxy1y2 and rxy1y1*/
  18791. yas532_data.calib_yas532.fxy1y2[INDEX_ZERO] =
  18792. (u8)(((v_data_u8[INDEX_TEN]
  18793. & YAS532_CALIB_HEX_ZERO_ONE)
  18794. << C_BMI160_ONE_U8X)
  18795. | ((v_data_u8[INDEX_ELEVEN] >>
  18796. C_BMI160_SEVEN_U8X) & YAS532_CALIB_HEX_ZERO_ONE));
  18797. yas532_data.calib_yas532.rxy1y2[INDEX_ZERO] =
  18798. ((s8)(((v_data_u8[INDEX_TEN]
  18799. >> C_BMI160_ONE_U8X)
  18800. & YAS532_CALIB_HEX_THREE_F)
  18801. << C_BMI160_TWO_U8X)) >> C_BMI160_TWO_U8X;
  18802. yas532_data.calib_yas532.fxy1y2[INDEX_ONE] =
  18803. (u8)(((v_data_u8[INDEX_ELEVEN]
  18804. & YAS532_CALIB_HEX_ZERO_ONE)
  18805. << C_BMI160_ONE_U8X)
  18806. | ((v_data_u8[INDEX_TWELVE] >>
  18807. C_BMI160_SEVEN_U8X) & YAS532_CALIB_HEX_ZERO_ONE));
  18808. yas532_data.calib_yas532.rxy1y2[INDEX_ONE] =
  18809. ((s8)(((v_data_u8[INDEX_ELEVEN]
  18810. >> C_BMI160_ONE_U8X) & YAS532_CALIB_HEX_THREE_F)
  18811. << C_BMI160_TWO_U8X)) >> C_BMI160_TWO_U8X;
  18812. yas532_data.calib_yas532.fxy1y2[INDEX_TWO] =
  18813. (u8)(((v_data_u8[INDEX_TWELVE]
  18814. & YAS532_CALIB_HEX_ZERO_ONE)
  18815. << C_BMI160_ONE_U8X)
  18816. | ((v_data_u8[INDEX_THIRTEEN] >> C_BMI160_SEVEN_U8X)
  18817. & YAS532_CALIB_HEX_ZERO_ONE));
  18818. yas532_data.calib_yas532.rxy1y2[INDEX_TWO] =
  18819. ((s8)(((v_data_u8[INDEX_TWELVE]
  18820. >> C_BMI160_ONE_U8X) & YAS532_CALIB_HEX_THREE_F)
  18821. << C_BMI160_TWO_U8X)) >> C_BMI160_TWO_U8X;
  18822. return com_rslt;
  18823. }
  18824. /*!
  18825. * @brief This function used for calculate the
  18826. * YAS532 read the linear data
  18827. *
  18828. *
  18829. * @return results of bus communication function
  18830. * @retval 0 -> Success
  18831. * @retval -1 -> Error
  18832. *
  18833. *
  18834. */
  18835. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yas532_xy1y2_to_linear(
  18836. u16 *v_xy1y2_u16, s32 *xy1y2_linear)
  18837. {
  18838. /* This variable used for provide the communication
  18839. results*/
  18840. BMI160_RETURN_FUNCTION_TYPE com_rslt = SUCCESS;
  18841. static const u16 v_calib_data[] = {
  18842. CALIB_LINEAR_3721, CALIB_LINEAR_3971,
  18843. CALIB_LINEAR_4221, CALIB_LINEAR_4471};
  18844. u8 i = C_BMI160_ZERO_U8X;
  18845. for (i = C_BMI160_ZERO_U8X; i < C_BMI160_THREE_U8X; i++)
  18846. xy1y2_linear[i] = v_xy1y2_u16[i] -
  18847. v_calib_data[yas532_data.calib_yas532.fxy1y2[i]]
  18848. + (yas532_data.v_hard_offset_s8[i] -
  18849. yas532_data.calib_yas532.rxy1y2[i])
  18850. * yas532_data.coef[i];
  18851. return com_rslt;
  18852. }
  18853. /*!
  18854. * @brief This function used for read the YAS532 sensor data
  18855. * @param v_acquisition_command_u8: used to set the data acquisition
  18856. * acquisition_command | operation
  18857. * ---------------------|-------------------------
  18858. * 0x17 | turn on the acquisition coil
  18859. * - | set direction of the coil
  18860. * _ | (x and y as minus(-))
  18861. * _ | Deferred acquisition mode
  18862. * 0x07 | turn on the acquisition coil
  18863. * _ | set direction of the coil
  18864. * _ | (x and y as minus(-))
  18865. * _ | Normal acquisition mode
  18866. * 0x11 | turn OFF the acquisition coil
  18867. * _ | set direction of the coil
  18868. * _ | (x and y as plus(+))
  18869. * _ | Deferred acquisition mode
  18870. * 0x01 | turn OFF the acquisition coil
  18871. * _ | set direction of the coil
  18872. * _ | (x and y as plus(+))
  18873. * _ | Normal acquisition mode
  18874. *
  18875. * @param v_busy_u8 : used to get the busy flay for sensor data read
  18876. * @param v_temp_u16 : used to get the temperature data
  18877. * @param v_xy1y2_u16 : used to get the sensor xy1y2 data
  18878. * @param v_overflow_u8 : used to get the overflow data
  18879. *
  18880. *
  18881. *
  18882. * @return results of bus communication function
  18883. * @retval 0 -> Success
  18884. * @retval -1 -> Error
  18885. *
  18886. *
  18887. */
  18888. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yas532_normal_measurement_data(
  18889. u8 v_acquisition_command_u8, u8 *v_busy_u8,
  18890. u16 *v_temp_u16, u16 *v_xy1y2_u16, u8 *v_overflow_u8)
  18891. {
  18892. /* This variable used for provide the communication
  18893. results*/
  18894. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  18895. /* Array holding the YAS532 xyy1 data*/
  18896. u8 v_data_u8[ARRAY_SIZE_EIGHT] = {
  18897. C_BMI160_ZERO_U8X,
  18898. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X,
  18899. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X,
  18900. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X};
  18901. u8 i = C_BMI160_ZERO_U8X;
  18902. /* check the p_bmi160 structure as NULL*/
  18903. if (p_bmi160 == BMI160_NULL) {
  18904. return E_BMI160_NULL_PTR;
  18905. } else {
  18906. /* read the sensor data */
  18907. com_rslt = bmi160_bst_yas532_acquisition_command_register(
  18908. v_acquisition_command_u8);
  18909. com_rslt +=
  18910. p_bmi160->BMI160_BUS_READ_FUNC(p_bmi160->dev_addr,
  18911. BMI160_USER_DATA_MAG_X_LSB__REG,
  18912. v_data_u8, C_BMI160_EIGHT_U8X);
  18913. /* read the xyy1 data*/
  18914. *v_busy_u8 =
  18915. ((v_data_u8[INDEX_ZERO] >> C_BMI160_SEVEN_U8X)
  18916. & YAS532_HEX_ZERO_ONE);
  18917. *v_temp_u16 =
  18918. (u16)((((s32)v_data_u8[INDEX_ZERO] << C_BMI160_THREE_U8X)
  18919. & YAS532_HEX_THREE_F_EIGHT) |
  18920. ((v_data_u8[INDEX_ONE] >> C_BMI160_FIVE_U8X)
  18921. & YAS532_HEX_ZERO_SEVEN));
  18922. v_xy1y2_u16[INDEX_ZERO] =
  18923. (u16)((((s32)v_data_u8[INDEX_TWO] << C_BMI160_SIX_U8X)
  18924. & YAS532_HEX_ONE_F_C_ZERO)
  18925. | ((v_data_u8[INDEX_THREE] >> C_BMI160_TWO_U8X)
  18926. & YAS532_HEX_THREE_F));
  18927. v_xy1y2_u16[INDEX_ONE] =
  18928. (u16)((((s32)v_data_u8[INDEX_FOUR] << C_BMI160_SIX_U8X)
  18929. & YAS532_HEX_ONE_F_C_ZERO)
  18930. | ((v_data_u8[INDEX_FIVE]
  18931. >> C_BMI160_TWO_U8X) & YAS532_HEX_THREE_F));
  18932. v_xy1y2_u16[INDEX_TWO] =
  18933. (u16)((((s32)v_data_u8[INDEX_SIX] << C_BMI160_SIX_U8X)
  18934. & YAS532_HEX_ONE_F_C_ZERO)
  18935. | ((v_data_u8[INDEX_SEVEN]
  18936. >> C_BMI160_TWO_U8X) & YAS532_HEX_THREE_F));
  18937. *v_overflow_u8 = C_BMI160_ZERO_U8X;
  18938. for (i = C_BMI160_ZERO_U8X; i < C_BMI160_THREE_U8X; i++) {
  18939. if (v_xy1y2_u16[i] == YAS532_DATA_OVERFLOW)
  18940. *v_overflow_u8 |= (C_BMI160_ONE_U8X
  18941. << (i * C_BMI160_TWO_U8X));
  18942. if (v_xy1y2_u16[i] == YAS532_DATA_UNDERFLOW)
  18943. *v_overflow_u8 |= (C_BMI160_ONE_U8X <<
  18944. (i * C_BMI160_TWO_U8X + C_BMI160_ONE_U8X));
  18945. }
  18946. }
  18947. return com_rslt;
  18948. }
  18949. /*!
  18950. * @brief This function used for YAS532 sensor data
  18951. * @param v_acquisition_command_u8 : the value of CMDR
  18952. * acquisition_command | operation
  18953. * ---------------------|-------------------------
  18954. * 0x17 | turn on the acquisition coil
  18955. * - | set direction of the coil
  18956. * _ | (x and y as minus(-))
  18957. * _ | Deferred acquisition mode
  18958. * 0x07 | turn on the acquisition coil
  18959. * _ | set direction of the coil
  18960. * _ | (x and y as minus(-))
  18961. * _ | Normal acquisition mode
  18962. * 0x11 | turn OFF the acquisition coil
  18963. * _ | set direction of the coil
  18964. * _ | (x and y as plus(+))
  18965. * _ | Deferred acquisition mode
  18966. * 0x01 | turn OFF the acquisition coil
  18967. * _ | set direction of the coil
  18968. * _ | (x and y as plus(+))
  18969. * _ | Normal acquisition mode
  18970. *
  18971. * @param xyz_data : the vector xyz output
  18972. * @param v_overflow_s8 : the value of overflow
  18973. * @param v_temp_correction_u8 : the value of temperate correction enable
  18974. *
  18975. *
  18976. * @return results of bus communication function
  18977. * @retval 0 -> Success
  18978. * @retval -1 -> Error
  18979. *
  18980. *
  18981. */
  18982. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yas532_measurement_xyz_data(
  18983. struct yas532_vector *xyz_data, u8 *v_overflow_s8, u8 v_temp_correction_u8,
  18984. u8 v_acquisition_command_u8)
  18985. {
  18986. /* This variable used for provide the communication
  18987. results*/
  18988. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  18989. /* Array holding the linear calculation output*/
  18990. s32 v_xy1y2_linear_s32[ARRAY_SIZE_THREE] = {C_BMI160_ZERO_U8X,
  18991. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X};
  18992. /* Array holding the temperature data */
  18993. s32 v_xyz_tmp_s32[ARRAY_SIZE_THREE] = {C_BMI160_ZERO_U8X,
  18994. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X};
  18995. s32 tmp = C_BMI160_ZERO_U8X;
  18996. s32 sx, sy1, sy2, sy, sz = C_BMI160_ZERO_U8X;
  18997. u8 i, v_busy_u8 = C_BMI160_ZERO_U8X;
  18998. u16 v_temp_u16 = C_BMI160_ZERO_U8X;
  18999. /* Array holding the xyy1 sensor raw data*/
  19000. u16 v_xy1y2_u16[ARRAY_SIZE_THREE] = {C_BMI160_ZERO_U8X,
  19001. C_BMI160_ZERO_U8X, C_BMI160_ZERO_U8X};
  19002. #if 1 < YAS532_MAG_TEMPERATURE_LOG
  19003. s32 sum = C_BMI160_ZERO_U8X;
  19004. #endif
  19005. *v_overflow_s8 = C_BMI160_ZERO_U8X;
  19006. switch (yas532_data.measure_state) {
  19007. case YAS532_MAG_STATE_INIT_COIL:
  19008. if (p_bmi160->mag_manual_enable != BMI160_HEX_0_1_DATA)
  19009. com_rslt = bmi160_set_mag_manual_enable(
  19010. BMI160_HEX_0_1_DATA);
  19011. /* write Rcoil*/
  19012. com_rslt += bmi160_set_mag_write_data(
  19013. BMI160_HEX_0_0_DATA);
  19014. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  19015. com_rslt += bmi160_set_mag_write_addr(BMI160_YAS532_RCOIL);
  19016. p_bmi160->delay_msec(C_BMI160_TWENTY_U8X);
  19017. if (!yas532_data.overflow && is_valid_offset(
  19018. yas532_data.v_hard_offset_s8))
  19019. yas532_data.measure_state = YAS532_MAG_STATE_NORMAL;
  19020. break;
  19021. case YAS532_MAG_STATE_MEASURE_OFFSET:
  19022. com_rslt = bmi160_bst_yas532_magnetic_measure_set_offset();
  19023. yas532_data.measure_state = YAS532_MAG_STATE_NORMAL;
  19024. break;
  19025. default:
  19026. break;
  19027. }
  19028. /* Read sensor data*/
  19029. com_rslt += bmi160_bst_yas532_normal_measurement_data(
  19030. v_acquisition_command_u8, &v_busy_u8, &v_temp_u16,
  19031. v_xy1y2_u16, v_overflow_s8);
  19032. /* Calculate the linear data*/
  19033. com_rslt += bmi160_bst_yas532_xy1y2_to_linear(v_xy1y2_u16,
  19034. v_xy1y2_linear_s32);
  19035. /* Calculate temperature correction */
  19036. #if 1 < YAS532_MAG_TEMPERATURE_LOG
  19037. yas532_data.temp_data.log[yas532_data.temp_data.idx++] =
  19038. v_temp_u16;
  19039. if (YAS532_MAG_TEMPERATURE_LOG <= yas532_data.temp_data.idx)
  19040. yas532_data.temp_data.idx = C_BMI160_ZERO_U8X;
  19041. yas532_data.temp_data.num++;
  19042. if (YAS532_MAG_TEMPERATURE_LOG <= yas532_data.temp_data.num)
  19043. yas532_data.temp_data.num = YAS532_MAG_TEMPERATURE_LOG;
  19044. for (i = C_BMI160_ZERO_U8X; i < yas532_data.temp_data.num; i++)
  19045. sum += yas532_data.temp_data.log[i];
  19046. tmp = sum * C_BMI160_TEN_U8X / yas532_data.temp_data.num
  19047. - YAS532_TEMP20DEGREE_TYPICAL * C_BMI160_TEN_U8X;
  19048. #else
  19049. tmp = (v_temp_u16 - YAS532_TEMP20DEGREE_TYPICAL)
  19050. * C_BMI160_TEN_U8X;
  19051. #endif
  19052. sx = v_xy1y2_linear_s32[INDEX_ZERO];
  19053. sy1 = v_xy1y2_linear_s32[INDEX_ONE];
  19054. sy2 = v_xy1y2_linear_s32[INDEX_TWO];
  19055. /* Temperature correction */
  19056. if (v_temp_correction_u8) {
  19057. sx -= (yas532_data.calib_yas532.cx * tmp)
  19058. / C_BMI160_THOUSAND_U8X;
  19059. sy1 -= (yas532_data.calib_yas532.cy1 * tmp)
  19060. / C_BMI160_THOUSAND_U8X;
  19061. sy2 -= (yas532_data.calib_yas532.cy2 * tmp)
  19062. / C_BMI160_THOUSAND_U8X;
  19063. }
  19064. sy = sy1 - sy2;
  19065. sz = -sy1 - sy2;
  19066. #if 1
  19067. xyz_data->yas532_vector_xyz[INDEX_ZERO] = yas532_data.calib_yas532.k *
  19068. ((C_BMI160_HUNDRED_U8X * sx + yas532_data.calib_yas532.a2 * sy +
  19069. yas532_data.calib_yas532.a3 * sz) / C_BMI160_TEN_U8X);
  19070. xyz_data->yas532_vector_xyz[INDEX_ONE] = yas532_data.calib_yas532.k *
  19071. ((yas532_data.calib_yas532.a4 * sx + yas532_data.calib_yas532.a5 * sy +
  19072. yas532_data.calib_yas532.a6 * sz) / C_BMI160_TEN_U8X);
  19073. xyz_data->yas532_vector_xyz[INDEX_TWO] = yas532_data.calib_yas532.k *
  19074. ((yas532_data.calib_yas532.a7 * sx + yas532_data.calib_yas532.a8 * sy +
  19075. yas532_data.calib_yas532.a9 * sz) / C_BMI160_TEN_U8X);
  19076. if (yas532_data.transform != BMI160_NULL) {
  19077. for (i = C_BMI160_ZERO_U8X; i < C_BMI160_THREE_U8X; i++) {
  19078. v_xyz_tmp_s32[i] = yas532_data.transform[i
  19079. * C_BMI160_THREE_U8X] *
  19080. xyz_data->yas532_vector_xyz[INDEX_ZERO]
  19081. + yas532_data.transform[i * C_BMI160_THREE_U8X
  19082. + C_BMI160_ONE_U8X] *
  19083. xyz_data->yas532_vector_xyz[INDEX_ONE]
  19084. + yas532_data.transform[i * C_BMI160_THREE_U8X
  19085. + C_BMI160_TWO_U8X] *
  19086. xyz_data->yas532_vector_xyz[INDEX_TWO];
  19087. }
  19088. set_vector(xyz_data->yas532_vector_xyz, v_xyz_tmp_s32);
  19089. }
  19090. for (i = C_BMI160_ZERO_U8X; i < C_BMI160_THREE_U8X; i++) {
  19091. xyz_data->yas532_vector_xyz[i] -=
  19092. xyz_data->yas532_vector_xyz[i] % C_BMI160_TEN_U8X;
  19093. if (*v_overflow_s8 & (C_BMI160_ONE_U8X
  19094. << (i * C_BMI160_TWO_U8X)))
  19095. xyz_data->yas532_vector_xyz[i] +=
  19096. C_BMI160_ONE_U8X; /* set overflow */
  19097. if (*v_overflow_s8 & (C_BMI160_ONE_U8X <<
  19098. (i * C_BMI160_TWO_U8X + C_BMI160_ONE_U8X)))
  19099. xyz_data->yas532_vector_xyz[i] +=
  19100. C_BMI160_TWO_U8X; /* set underflow */
  19101. }
  19102. #else
  19103. xyz_data->yas532_vector_xyz[INDEX_ZERO] = sx;
  19104. xyz_data->yas532_vector_xyz[INDEX_ONE] = sy;
  19105. xyz_data->yas532_vector_xyz[INDEX_TWO] = sz;
  19106. #endif
  19107. if (v_busy_u8)
  19108. return com_rslt;
  19109. if (C_BMI160_ZERO_U8X < *v_overflow_s8) {
  19110. if (!yas532_data.overflow)
  19111. yas532_data.overflow = C_BMI160_ONE_U8X;
  19112. yas532_data.measure_state = YAS532_MAG_STATE_INIT_COIL;
  19113. } else
  19114. yas532_data.overflow = C_BMI160_ZERO_U8X;
  19115. for (i = C_BMI160_ZERO_U8X; i < C_BMI160_THREE_U8X; i++)
  19116. yas532_data.last_raw[i] = v_xy1y2_u16[i];
  19117. yas532_data.last_raw[i] = v_temp_u16;
  19118. return com_rslt;
  19119. }
  19120. /*!
  19121. * @brief This function used for YAS532 write data acquisition
  19122. * command register write
  19123. * @param v_command_reg_data_u8 : the value of data acquisition
  19124. * acquisition_command | operation
  19125. * ---------------------|-------------------------
  19126. * 0x17 | turn on the acquisition coil
  19127. * - | set direction of the coil
  19128. * _ | (x and y as minus(-))
  19129. * _ | Deferred acquisition mode
  19130. * 0x07 | turn on the acquisition coil
  19131. * _ | set direction of the coil
  19132. * _ | (x and y as minus(-))
  19133. * _ | Normal acquisition mode
  19134. * 0x11 | turn OFF the acquisition coil
  19135. * _ | set direction of the coil
  19136. * _ | (x and y as plus(+))
  19137. * _ | Deferred acquisition mode
  19138. * 0x01 | turn OFF the acquisition coil
  19139. * _ | set direction of the coil
  19140. * _ | (x and y as plus(+))
  19141. * _ | Normal acquisition mode
  19142. *
  19143. *
  19144. *
  19145. * @return results of bus communication function
  19146. * @retval 0 -> Success
  19147. * @retval -1 -> Error
  19148. *
  19149. *
  19150. */
  19151. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yas532_acquisition_command_register(
  19152. u8 v_command_reg_data_u8)
  19153. {
  19154. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  19155. if (p_bmi160->mag_manual_enable != BMI160_HEX_0_1_DATA)
  19156. com_rslt = bmi160_set_mag_manual_enable(
  19157. BMI160_HEX_0_1_DATA);
  19158. com_rslt = bmi160_set_mag_write_data(v_command_reg_data_u8);
  19159. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  19160. /* YAMAHA YAS532-0x82*/
  19161. com_rslt += bmi160_set_mag_write_addr(
  19162. BMI160_YAS532_COMMAND_REGISTER);
  19163. p_bmi160->delay_msec(C_BMI160_FIVETY_U8X);
  19164. com_rslt += bmi160_set_mag_read_addr(
  19165. BMI160_YAS532_DATA_REGISTER);
  19166. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  19167. if (p_bmi160->mag_manual_enable == BMI160_HEX_0_1_DATA)
  19168. com_rslt += bmi160_set_mag_manual_enable(BMI160_HEX_0_0_DATA);
  19169. return com_rslt;
  19170. }
  19171. /*!
  19172. * @brief This function used write offset of YAS532
  19173. *
  19174. * @param p_offset_s8 : The value of offset to write
  19175. *
  19176. *
  19177. * @return results of bus communication function
  19178. * @retval 0 -> Success
  19179. * @retval -1 -> Error
  19180. *
  19181. *
  19182. */
  19183. BMI160_RETURN_FUNCTION_TYPE bmi160_bst_yas532_set_offset(
  19184. const s8 *p_offset_s8)
  19185. {
  19186. /* This variable used for provide the communication
  19187. results*/
  19188. BMI160_RETURN_FUNCTION_TYPE com_rslt = E_BMI160_COMM_RES;
  19189. if (p_bmi160->mag_manual_enable != BMI160_HEX_0_1_DATA)
  19190. com_rslt = bmi160_set_mag_manual_enable(BMI160_HEX_0_1_DATA);
  19191. p_bmi160->delay_msec(C_BMI160_TWO_U8X);
  19192. /* Write offset X data*/
  19193. com_rslt = bmi160_set_mag_write_data(p_offset_s8[INDEX_ZERO]);
  19194. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  19195. /* YAS532 offset x write*/
  19196. com_rslt += bmi160_set_mag_write_addr(BMI160_YAS532_OFFSET_X);
  19197. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  19198. /* Write offset Y data*/
  19199. com_rslt = bmi160_set_mag_write_data(p_offset_s8[INDEX_ONE]);
  19200. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  19201. /* YAS532 offset y write*/
  19202. com_rslt += bmi160_set_mag_write_addr(BMI160_YAS532_OFFSET_Y);
  19203. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  19204. /* Write offset Z data*/
  19205. com_rslt = bmi160_set_mag_write_data(p_offset_s8[INDEX_TWO]);
  19206. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  19207. /* YAS532 offset z write*/
  19208. com_rslt += bmi160_set_mag_write_addr(BMI160_YAS532_OFFSET_Z);
  19209. p_bmi160->delay_msec(C_BMI160_ONE_U8X);
  19210. set_vector(yas532_data.v_hard_offset_s8, p_offset_s8);
  19211. if (p_bmi160->mag_manual_enable == BMI160_HEX_0_1_DATA)
  19212. com_rslt = bmi160_set_mag_manual_enable(BMI160_HEX_0_0_DATA);
  19213. return com_rslt;
  19214. }
  19215. /*!
  19216. * @brief This function used for reading
  19217. * bmi160_t structure
  19218. *
  19219. * @return the reference and values of bmi160_t
  19220. *
  19221. *
  19222. */
  19223. struct bmi160_t *bmi160_get_ptr(void)
  19224. {
  19225. return p_bmi160;
  19226. }