lsm6ds3tr-c_reg.c 214 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209
  1. /**
  2. ******************************************************************************
  3. * @file lsm6ds3tr_c_reg.c
  4. * @author Sensors Software Solution Team
  5. * @brief LSM6DS3TR_C driver file
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. #include "lsm6ds3tr-c_reg.h"
  20. /**
  21. * @defgroup LSM6DS3TR_C
  22. * @brief This file provides a set of functions needed to drive the
  23. * lsm6ds3tr_c enanced inertial module.
  24. * @{
  25. *
  26. */
  27. /**
  28. * @defgroup LSM6DS3TR_C_interfaces_functions
  29. * @brief This section provide a set of functions used to read and
  30. * write a generic register of the device.
  31. * MANDATORY: return 0 -> no Error.
  32. * @{
  33. *
  34. */
  35. /**
  36. * @brief Read generic device register
  37. *
  38. * @param ctx read / write interface definitions(ptr)
  39. * @param reg register to read
  40. * @param data pointer to buffer that store the data read(ptr)
  41. * @param len number of consecutive register to read
  42. * @retval interface status (MANDATORY: return 0 -> no Error)
  43. *
  44. */
  45. int32_t lsm6ds3tr_c_read_reg(stmdev_ctx_t *ctx, uint8_t reg,
  46. uint8_t *data,
  47. uint16_t len)
  48. {
  49. int32_t ret;
  50. ret = ctx->read_reg(ctx->handle, reg, data, len);
  51. return ret;
  52. }
  53. /**
  54. * @brief Write generic device register
  55. *
  56. * @param ctx read / write interface definitions(ptr)
  57. * @param reg register to write
  58. * @param data pointer to data to write in register reg(ptr)
  59. * @param len number of consecutive register to write
  60. * @retval interface status (MANDATORY: return 0 -> no Error)
  61. *
  62. */
  63. int32_t lsm6ds3tr_c_write_reg(stmdev_ctx_t *ctx, uint8_t reg,
  64. uint8_t *data,
  65. uint16_t len)
  66. {
  67. int32_t ret;
  68. ret = ctx->write_reg(ctx->handle, reg, data, len);
  69. return ret;
  70. }
  71. /**
  72. * @}
  73. *
  74. */
  75. /**
  76. * @defgroup LSM6DS3TR_C_Sensitivity
  77. * @brief These functions convert raw-data into engineering units.
  78. * @{
  79. *
  80. */
  81. float_t lsm6ds3tr_c_from_fs2g_to_mg(int16_t lsb)
  82. {
  83. return ((float_t)lsb * 0.061f);
  84. }
  85. float_t lsm6ds3tr_c_from_fs4g_to_mg(int16_t lsb)
  86. {
  87. return ((float_t)lsb * 0.122f);
  88. }
  89. float_t lsm6ds3tr_c_from_fs8g_to_mg(int16_t lsb)
  90. {
  91. return ((float_t)lsb * 0.244f);
  92. }
  93. float_t lsm6ds3tr_c_from_fs16g_to_mg(int16_t lsb)
  94. {
  95. return ((float_t)lsb * 0.488f);
  96. }
  97. float_t lsm6ds3tr_c_from_fs125dps_to_mdps(int16_t lsb)
  98. {
  99. return ((float_t)lsb * 4.375f);
  100. }
  101. float_t lsm6ds3tr_c_from_fs250dps_to_mdps(int16_t lsb)
  102. {
  103. return ((float_t)lsb * 8.750f);
  104. }
  105. float_t lsm6ds3tr_c_from_fs500dps_to_mdps(int16_t lsb)
  106. {
  107. return ((float_t)lsb * 17.50f);
  108. }
  109. float_t lsm6ds3tr_c_from_fs1000dps_to_mdps(int16_t lsb)
  110. {
  111. return ((float_t)lsb * 35.0f);
  112. }
  113. float_t lsm6ds3tr_c_from_fs2000dps_to_mdps(int16_t lsb)
  114. {
  115. return ((float_t)lsb * 70.0f);
  116. }
  117. float_t lsm6ds3tr_c_from_lsb_to_celsius(int16_t lsb)
  118. {
  119. return (((float_t)lsb / 256.0f) + 25.0f);
  120. }
  121. /**
  122. * @}
  123. *
  124. */
  125. /**
  126. * @defgroup LSM6DS3TR_C_data_generation
  127. * @brief This section groups all the functions concerning data
  128. * generation
  129. * @{
  130. *
  131. */
  132. /**
  133. * @brief Accelerometer full-scale selection.[set]
  134. *
  135. * @param ctx Read / write interface definitions
  136. * @param val Change the values of fs_xl in reg CTRL1_XL
  137. * @retval Interface status (MANDATORY: return 0 -> no Error).
  138. *
  139. */
  140. int32_t lsm6ds3tr_c_xl_full_scale_set(stmdev_ctx_t *ctx,
  141. lsm6ds3tr_c_fs_xl_t val)
  142. {
  143. lsm6ds3tr_c_ctrl1_xl_t ctrl1_xl;
  144. int32_t ret;
  145. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  146. (uint8_t *)&ctrl1_xl, 1);
  147. if (ret == 0)
  148. {
  149. ctrl1_xl.fs_xl = (uint8_t) val;
  150. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  151. (uint8_t *)&ctrl1_xl, 1);
  152. }
  153. return ret;
  154. }
  155. /**
  156. * @brief Accelerometer full-scale selection.[get]
  157. *
  158. * @param ctx Read / write interface definitions
  159. * @param val Get the values of fs_xl in reg CTRL1_XL
  160. * @retval Interface status (MANDATORY: return 0 -> no Error).
  161. *
  162. */
  163. int32_t lsm6ds3tr_c_xl_full_scale_get(stmdev_ctx_t *ctx,
  164. lsm6ds3tr_c_fs_xl_t *val)
  165. {
  166. lsm6ds3tr_c_ctrl1_xl_t ctrl1_xl;
  167. int32_t ret;
  168. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  169. (uint8_t *)&ctrl1_xl, 1);
  170. switch (ctrl1_xl.fs_xl)
  171. {
  172. case LSM6DS3TR_C_2g:
  173. *val = LSM6DS3TR_C_2g;
  174. break;
  175. case LSM6DS3TR_C_16g:
  176. *val = LSM6DS3TR_C_16g;
  177. break;
  178. case LSM6DS3TR_C_4g:
  179. *val = LSM6DS3TR_C_4g;
  180. break;
  181. case LSM6DS3TR_C_8g:
  182. *val = LSM6DS3TR_C_8g;
  183. break;
  184. default:
  185. *val = LSM6DS3TR_C_XL_FS_ND;
  186. break;
  187. }
  188. return ret;
  189. }
  190. /**
  191. * @brief Accelerometer data rate selection.[set]
  192. *
  193. * @param ctx Read / write interface definitions
  194. * @param val Change the values of odr_xl in reg CTRL1_XL
  195. * @retval Interface status (MANDATORY: return 0 -> no Error).
  196. *
  197. */
  198. int32_t lsm6ds3tr_c_xl_data_rate_set(stmdev_ctx_t *ctx,
  199. lsm6ds3tr_c_odr_xl_t val)
  200. {
  201. lsm6ds3tr_c_ctrl1_xl_t ctrl1_xl;
  202. int32_t ret;
  203. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  204. (uint8_t *)&ctrl1_xl, 1);
  205. if (ret == 0)
  206. {
  207. ctrl1_xl.odr_xl = (uint8_t) val;
  208. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  209. (uint8_t *)&ctrl1_xl, 1);
  210. }
  211. return ret;
  212. }
  213. /**
  214. * @brief Accelerometer data rate selection.[get]
  215. *
  216. * @param ctx Read / write interface definitions
  217. * @param val Get the values of odr_xl in reg CTRL1_XL
  218. * @retval Interface status (MANDATORY: return 0 -> no Error).
  219. *
  220. */
  221. int32_t lsm6ds3tr_c_xl_data_rate_get(stmdev_ctx_t *ctx,
  222. lsm6ds3tr_c_odr_xl_t *val)
  223. {
  224. lsm6ds3tr_c_ctrl1_xl_t ctrl1_xl;
  225. int32_t ret;
  226. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  227. (uint8_t *)&ctrl1_xl, 1);
  228. switch (ctrl1_xl.odr_xl)
  229. {
  230. case LSM6DS3TR_C_XL_ODR_OFF:
  231. *val = LSM6DS3TR_C_XL_ODR_OFF;
  232. break;
  233. case LSM6DS3TR_C_XL_ODR_12Hz5:
  234. *val = LSM6DS3TR_C_XL_ODR_12Hz5;
  235. break;
  236. case LSM6DS3TR_C_XL_ODR_26Hz:
  237. *val = LSM6DS3TR_C_XL_ODR_26Hz;
  238. break;
  239. case LSM6DS3TR_C_XL_ODR_52Hz:
  240. *val = LSM6DS3TR_C_XL_ODR_52Hz;
  241. break;
  242. case LSM6DS3TR_C_XL_ODR_104Hz:
  243. *val = LSM6DS3TR_C_XL_ODR_104Hz;
  244. break;
  245. case LSM6DS3TR_C_XL_ODR_208Hz:
  246. *val = LSM6DS3TR_C_XL_ODR_208Hz;
  247. break;
  248. case LSM6DS3TR_C_XL_ODR_416Hz:
  249. *val = LSM6DS3TR_C_XL_ODR_416Hz;
  250. break;
  251. case LSM6DS3TR_C_XL_ODR_833Hz:
  252. *val = LSM6DS3TR_C_XL_ODR_833Hz;
  253. break;
  254. case LSM6DS3TR_C_XL_ODR_1k66Hz:
  255. *val = LSM6DS3TR_C_XL_ODR_1k66Hz;
  256. break;
  257. case LSM6DS3TR_C_XL_ODR_3k33Hz:
  258. *val = LSM6DS3TR_C_XL_ODR_3k33Hz;
  259. break;
  260. case LSM6DS3TR_C_XL_ODR_6k66Hz:
  261. *val = LSM6DS3TR_C_XL_ODR_6k66Hz;
  262. break;
  263. case LSM6DS3TR_C_XL_ODR_1Hz6:
  264. *val = LSM6DS3TR_C_XL_ODR_1Hz6;
  265. break;
  266. default:
  267. *val = LSM6DS3TR_C_XL_ODR_ND;
  268. break;
  269. }
  270. return ret;
  271. }
  272. /**
  273. * @brief Gyroscope chain full-scale selection.[set]
  274. *
  275. * @param ctx Read / write interface definitions
  276. * @param val Change the values of fs_g in reg CTRL2_G
  277. * @retval Interface status (MANDATORY: return 0 -> no Error).
  278. *
  279. */
  280. int32_t lsm6ds3tr_c_gy_full_scale_set(stmdev_ctx_t *ctx,
  281. lsm6ds3tr_c_fs_g_t val)
  282. {
  283. lsm6ds3tr_c_ctrl2_g_t ctrl2_g;
  284. int32_t ret;
  285. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL2_G,
  286. (uint8_t *)&ctrl2_g, 1);
  287. if (ret == 0)
  288. {
  289. ctrl2_g.fs_g = (uint8_t) val;
  290. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL2_G,
  291. (uint8_t *)&ctrl2_g, 1);
  292. }
  293. return ret;
  294. }
  295. /**
  296. * @brief Gyroscope chain full-scale selection.[get]
  297. *
  298. * @param ctx Read / write interface definitions
  299. * @param val Get the values of fs_g in reg CTRL2_G
  300. * @retval Interface status (MANDATORY: return 0 -> no Error).
  301. *
  302. */
  303. int32_t lsm6ds3tr_c_gy_full_scale_get(stmdev_ctx_t *ctx,
  304. lsm6ds3tr_c_fs_g_t *val)
  305. {
  306. lsm6ds3tr_c_ctrl2_g_t ctrl2_g;
  307. int32_t ret;
  308. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL2_G,
  309. (uint8_t *)&ctrl2_g, 1);
  310. switch (ctrl2_g.fs_g)
  311. {
  312. case LSM6DS3TR_C_250dps:
  313. *val = LSM6DS3TR_C_250dps;
  314. break;
  315. case LSM6DS3TR_C_125dps:
  316. *val = LSM6DS3TR_C_125dps;
  317. break;
  318. case LSM6DS3TR_C_500dps:
  319. *val = LSM6DS3TR_C_500dps;
  320. break;
  321. case LSM6DS3TR_C_1000dps:
  322. *val = LSM6DS3TR_C_1000dps;
  323. break;
  324. case LSM6DS3TR_C_2000dps:
  325. *val = LSM6DS3TR_C_2000dps;
  326. break;
  327. default:
  328. *val = LSM6DS3TR_C_GY_FS_ND;
  329. break;
  330. }
  331. return ret;
  332. }
  333. /**
  334. * @brief Gyroscope data rate selection.[set]
  335. *
  336. * @param ctx Read / write interface definitions
  337. * @param val Change the values of odr_g in reg CTRL2_G
  338. * @retval Interface status (MANDATORY: return 0 -> no Error).
  339. *
  340. */
  341. int32_t lsm6ds3tr_c_gy_data_rate_set(stmdev_ctx_t *ctx,
  342. lsm6ds3tr_c_odr_g_t val)
  343. {
  344. lsm6ds3tr_c_ctrl2_g_t ctrl2_g;
  345. int32_t ret;
  346. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL2_G,
  347. (uint8_t *)&ctrl2_g, 1);
  348. if (ret == 0)
  349. {
  350. ctrl2_g.odr_g = (uint8_t) val;
  351. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL2_G,
  352. (uint8_t *)&ctrl2_g, 1);
  353. }
  354. return ret;
  355. }
  356. /**
  357. * @brief Gyroscope data rate selection.[get]
  358. *
  359. * @param ctx Read / write interface definitions
  360. * @param val Get the values of odr_g in reg CTRL2_G
  361. * @retval Interface status (MANDATORY: return 0 -> no Error).
  362. *
  363. */
  364. int32_t lsm6ds3tr_c_gy_data_rate_get(stmdev_ctx_t *ctx,
  365. lsm6ds3tr_c_odr_g_t *val)
  366. {
  367. lsm6ds3tr_c_ctrl2_g_t ctrl2_g;
  368. int32_t ret;
  369. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL2_G,
  370. (uint8_t *)&ctrl2_g, 1);
  371. switch (ctrl2_g.odr_g)
  372. {
  373. case LSM6DS3TR_C_GY_ODR_OFF:
  374. *val = LSM6DS3TR_C_GY_ODR_OFF;
  375. break;
  376. case LSM6DS3TR_C_GY_ODR_12Hz5:
  377. *val = LSM6DS3TR_C_GY_ODR_12Hz5;
  378. break;
  379. case LSM6DS3TR_C_GY_ODR_26Hz:
  380. *val = LSM6DS3TR_C_GY_ODR_26Hz;
  381. break;
  382. case LSM6DS3TR_C_GY_ODR_52Hz:
  383. *val = LSM6DS3TR_C_GY_ODR_52Hz;
  384. break;
  385. case LSM6DS3TR_C_GY_ODR_104Hz:
  386. *val = LSM6DS3TR_C_GY_ODR_104Hz;
  387. break;
  388. case LSM6DS3TR_C_GY_ODR_208Hz:
  389. *val = LSM6DS3TR_C_GY_ODR_208Hz;
  390. break;
  391. case LSM6DS3TR_C_GY_ODR_416Hz:
  392. *val = LSM6DS3TR_C_GY_ODR_416Hz;
  393. break;
  394. case LSM6DS3TR_C_GY_ODR_833Hz:
  395. *val = LSM6DS3TR_C_GY_ODR_833Hz;
  396. break;
  397. case LSM6DS3TR_C_GY_ODR_1k66Hz:
  398. *val = LSM6DS3TR_C_GY_ODR_1k66Hz;
  399. break;
  400. case LSM6DS3TR_C_GY_ODR_3k33Hz:
  401. *val = LSM6DS3TR_C_GY_ODR_3k33Hz;
  402. break;
  403. case LSM6DS3TR_C_GY_ODR_6k66Hz:
  404. *val = LSM6DS3TR_C_GY_ODR_6k66Hz;
  405. break;
  406. default:
  407. *val = LSM6DS3TR_C_GY_ODR_ND;
  408. break;
  409. }
  410. return ret;
  411. }
  412. /**
  413. * @brief Block data update.[set]
  414. *
  415. * @param ctx Read / write interface definitions
  416. * @param val Change the values of bdu in reg CTRL3_C
  417. * @retval Interface status (MANDATORY: return 0 -> no Error).
  418. *
  419. */
  420. int32_t lsm6ds3tr_c_block_data_update_set(stmdev_ctx_t *ctx,
  421. uint8_t val)
  422. {
  423. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  424. int32_t ret;
  425. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  426. (uint8_t *)&ctrl3_c, 1);
  427. if (ret == 0)
  428. {
  429. ctrl3_c.bdu = val;
  430. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  431. (uint8_t *)&ctrl3_c, 1);
  432. }
  433. return ret;
  434. }
  435. /**
  436. * @brief Block data update.[get]
  437. *
  438. * @param ctx Read / write interface definitions
  439. * @param val Change the values of bdu in reg CTRL3_C
  440. * @retval Interface status (MANDATORY: return 0 -> no Error).
  441. *
  442. */
  443. int32_t lsm6ds3tr_c_block_data_update_get(stmdev_ctx_t *ctx,
  444. uint8_t *val)
  445. {
  446. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  447. int32_t ret;
  448. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  449. (uint8_t *)&ctrl3_c, 1);
  450. *val = ctrl3_c.bdu;
  451. return ret;
  452. }
  453. /**
  454. * @brief Weight of XL user offset bits of registers
  455. * X_OFS_USR(73h), Y_OFS_USR(74h), Z_OFS_USR(75h).[set]
  456. *
  457. * @param ctx Read / write interface definitions
  458. * @param val Change the values of usr_off_w in reg CTRL6_C
  459. * @retval Interface status (MANDATORY: return 0 -> no Error).
  460. *
  461. */
  462. int32_t lsm6ds3tr_c_xl_offset_weight_set(stmdev_ctx_t *ctx,
  463. lsm6ds3tr_c_usr_off_w_t val)
  464. {
  465. lsm6ds3tr_c_ctrl6_c_t ctrl6_c;
  466. int32_t ret;
  467. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  468. (uint8_t *)&ctrl6_c, 1);
  469. if (ret == 0)
  470. {
  471. ctrl6_c.usr_off_w = (uint8_t) val;
  472. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  473. (uint8_t *)&ctrl6_c, 1);
  474. }
  475. return ret;
  476. }
  477. /**
  478. * @brief Weight of XL user offset bits of registers
  479. * X_OFS_USR(73h), Y_OFS_USR(74h), Z_OFS_USR(75h).[get]
  480. *
  481. * @param ctx Read / write interface definitions
  482. * @param val Get the values of usr_off_w in reg CTRL6_C
  483. * @retval Interface status (MANDATORY: return 0 -> no Error).
  484. *
  485. */
  486. int32_t lsm6ds3tr_c_xl_offset_weight_get(stmdev_ctx_t *ctx,
  487. lsm6ds3tr_c_usr_off_w_t *val)
  488. {
  489. lsm6ds3tr_c_ctrl6_c_t ctrl6_c;
  490. int32_t ret;
  491. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  492. (uint8_t *)&ctrl6_c, 1);
  493. switch (ctrl6_c.usr_off_w)
  494. {
  495. case LSM6DS3TR_C_LSb_1mg:
  496. *val = LSM6DS3TR_C_LSb_1mg;
  497. break;
  498. case LSM6DS3TR_C_LSb_16mg:
  499. *val = LSM6DS3TR_C_LSb_16mg;
  500. break;
  501. default:
  502. *val = LSM6DS3TR_C_WEIGHT_ND;
  503. break;
  504. }
  505. return ret;
  506. }
  507. /**
  508. * @brief High-performance operating mode for accelerometer[set]
  509. *
  510. * @param ctx Read / write interface definitions
  511. * @param val Change the values of xl_hm_mode in reg CTRL6_C
  512. * @retval Interface status (MANDATORY: return 0 -> no Error).
  513. *
  514. */
  515. int32_t lsm6ds3tr_c_xl_power_mode_set(stmdev_ctx_t *ctx,
  516. lsm6ds3tr_c_xl_hm_mode_t val)
  517. {
  518. lsm6ds3tr_c_ctrl6_c_t ctrl6_c;
  519. int32_t ret;
  520. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  521. (uint8_t *)&ctrl6_c, 1);
  522. if (ret == 0)
  523. {
  524. ctrl6_c.xl_hm_mode = (uint8_t) val;
  525. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  526. (uint8_t *)&ctrl6_c, 1);
  527. }
  528. return ret;
  529. }
  530. /**
  531. * @brief High-performance operating mode for accelerometer.[get]
  532. *
  533. * @param ctx Read / write interface definitions
  534. * @param val Get the values of xl_hm_mode in reg CTRL6_C
  535. * @retval Interface status (MANDATORY: return 0 -> no Error).
  536. *
  537. */
  538. int32_t lsm6ds3tr_c_xl_power_mode_get(stmdev_ctx_t *ctx,
  539. lsm6ds3tr_c_xl_hm_mode_t *val)
  540. {
  541. lsm6ds3tr_c_ctrl6_c_t ctrl6_c;
  542. int32_t ret;
  543. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  544. (uint8_t *)&ctrl6_c, 1);
  545. switch (ctrl6_c.xl_hm_mode)
  546. {
  547. case LSM6DS3TR_C_XL_HIGH_PERFORMANCE:
  548. *val = LSM6DS3TR_C_XL_HIGH_PERFORMANCE;
  549. break;
  550. case LSM6DS3TR_C_XL_NORMAL:
  551. *val = LSM6DS3TR_C_XL_NORMAL;
  552. break;
  553. default:
  554. *val = LSM6DS3TR_C_XL_PW_MODE_ND;
  555. break;
  556. }
  557. return ret;
  558. }
  559. /**
  560. * @brief Source register rounding function on WAKE_UP_SRC (1Bh),
  561. * TAP_SRC (1Ch), D6D_SRC (1Dh), STATUS_REG (1Eh) and
  562. * FUNC_SRC1 (53h) registers in the primary interface.[set]
  563. *
  564. * @param ctx Read / write interface definitions
  565. * @param val Change the values of rounding_status in reg CTRL7_G
  566. * @retval Interface status (MANDATORY: return 0 -> no Error).
  567. *
  568. */
  569. int32_t lsm6ds3tr_c_rounding_on_status_set(stmdev_ctx_t *ctx,
  570. lsm6ds3tr_c_rounding_status_t val)
  571. {
  572. lsm6ds3tr_c_ctrl7_g_t ctrl7_g;
  573. int32_t ret;
  574. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL7_G,
  575. (uint8_t *)&ctrl7_g, 1);
  576. if (ret == 0)
  577. {
  578. ctrl7_g.rounding_status = (uint8_t) val;
  579. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL7_G,
  580. (uint8_t *)&ctrl7_g, 1);
  581. }
  582. return ret;
  583. }
  584. /**
  585. * @brief Source register rounding function on WAKE_UP_SRC (1Bh),
  586. * TAP_SRC (1Ch), D6D_SRC (1Dh), STATUS_REG (1Eh) and
  587. * FUNC_SRC1 (53h) registers in the primary interface.[get]
  588. *
  589. * @param ctx Read / write interface definitions
  590. * @param val Get the values of rounding_status in reg CTRL7_G
  591. * @retval Interface status (MANDATORY: return 0 -> no Error).
  592. *
  593. */
  594. int32_t lsm6ds3tr_c_rounding_on_status_get(stmdev_ctx_t *ctx,
  595. lsm6ds3tr_c_rounding_status_t *val)
  596. {
  597. lsm6ds3tr_c_ctrl7_g_t ctrl7_g;
  598. int32_t ret;
  599. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL7_G,
  600. (uint8_t *)&ctrl7_g, 1);
  601. switch (ctrl7_g.rounding_status)
  602. {
  603. case LSM6DS3TR_C_STAT_RND_DISABLE:
  604. *val = LSM6DS3TR_C_STAT_RND_DISABLE;
  605. break;
  606. case LSM6DS3TR_C_STAT_RND_ENABLE:
  607. *val = LSM6DS3TR_C_STAT_RND_ENABLE;
  608. break;
  609. default:
  610. *val = LSM6DS3TR_C_STAT_RND_ND;
  611. break;
  612. }
  613. return ret;
  614. }
  615. /**
  616. * @brief High-performance operating mode disable for gyroscope.[set]
  617. *
  618. * @param ctx Read / write interface definitions
  619. * @param val Change the values of g_hm_mode in reg CTRL7_G
  620. * @retval Interface status (MANDATORY: return 0 -> no Error).
  621. *
  622. */
  623. int32_t lsm6ds3tr_c_gy_power_mode_set(stmdev_ctx_t *ctx,
  624. lsm6ds3tr_c_g_hm_mode_t val)
  625. {
  626. lsm6ds3tr_c_ctrl7_g_t ctrl7_g;
  627. int32_t ret;
  628. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL7_G,
  629. (uint8_t *)&ctrl7_g, 1);
  630. if (ret == 0)
  631. {
  632. ctrl7_g.g_hm_mode = (uint8_t) val;
  633. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL7_G,
  634. (uint8_t *)&ctrl7_g, 1);
  635. }
  636. return ret;
  637. }
  638. /**
  639. * @brief High-performance operating mode disable for gyroscope.[get]
  640. *
  641. * @param ctx Read / write interface definitions
  642. * @param val Get the values of g_hm_mode in reg CTRL7_G
  643. * @retval Interface status (MANDATORY: return 0 -> no Error).
  644. *
  645. */
  646. int32_t lsm6ds3tr_c_gy_power_mode_get(stmdev_ctx_t *ctx,
  647. lsm6ds3tr_c_g_hm_mode_t *val)
  648. {
  649. lsm6ds3tr_c_ctrl7_g_t ctrl7_g;
  650. int32_t ret;
  651. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL7_G,
  652. (uint8_t *)&ctrl7_g, 1);
  653. switch (ctrl7_g.g_hm_mode)
  654. {
  655. case LSM6DS3TR_C_GY_HIGH_PERFORMANCE:
  656. *val = LSM6DS3TR_C_GY_HIGH_PERFORMANCE;
  657. break;
  658. case LSM6DS3TR_C_GY_NORMAL:
  659. *val = LSM6DS3TR_C_GY_NORMAL;
  660. break;
  661. default:
  662. *val = LSM6DS3TR_C_GY_PW_MODE_ND;
  663. break;
  664. }
  665. return ret;
  666. }
  667. /**
  668. * @brief Read all the interrupt/status flag of the device.[get]
  669. *
  670. * @param ctx Read / write interface definitions
  671. * @param val WAKE_UP_SRC, TAP_SRC, D6D_SRC, STATUS_REG,
  672. * FUNC_SRC1, FUNC_SRC2, WRIST_TILT_IA, A_WRIST_TILT_Mask
  673. * @retval Interface status (MANDATORY: return 0 -> no Error).
  674. *
  675. */
  676. int32_t lsm6ds3tr_c_all_sources_get(stmdev_ctx_t *ctx,
  677. lsm6ds3tr_c_all_sources_t *val)
  678. {
  679. int32_t ret;
  680. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_SRC,
  681. (uint8_t *) & (val->wake_up_src), 1);
  682. if (ret == 0)
  683. {
  684. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_SRC,
  685. (uint8_t *) & (val->tap_src), 1);
  686. }
  687. if (ret == 0)
  688. {
  689. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_D6D_SRC,
  690. (uint8_t *) & (val->d6d_src), 1);
  691. }
  692. if (ret == 0)
  693. {
  694. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_STATUS_REG,
  695. (uint8_t *) & (val->status_reg), 1);
  696. }
  697. if (ret == 0)
  698. {
  699. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FUNC_SRC1,
  700. (uint8_t *) & (val->func_src1), 1);
  701. }
  702. if (ret == 0)
  703. {
  704. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FUNC_SRC2,
  705. (uint8_t *) & (val->func_src2), 1);
  706. }
  707. if (ret == 0)
  708. {
  709. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WRIST_TILT_IA,
  710. (uint8_t *) & (val->wrist_tilt_ia), 1);
  711. }
  712. if (ret == 0)
  713. {
  714. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_B);
  715. }
  716. if (ret == 0)
  717. {
  718. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_A_WRIST_TILT_MASK,
  719. (uint8_t *) & (val->a_wrist_tilt_mask), 1);
  720. }
  721. if (ret == 0)
  722. {
  723. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  724. }
  725. return ret;
  726. }
  727. /**
  728. * @brief The STATUS_REG register is read by the primary interface[get]
  729. *
  730. * @param ctx Read / write interface definitions
  731. * @param val Registers STATUS_REG
  732. * @retval Interface status (MANDATORY: return 0 -> no Error).
  733. *
  734. */
  735. int32_t lsm6ds3tr_c_status_reg_get(stmdev_ctx_t *ctx,
  736. lsm6ds3tr_c_status_reg_t *val)
  737. {
  738. int32_t ret;
  739. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_STATUS_REG,
  740. (uint8_t *) val, 1);
  741. return ret;
  742. }
  743. /**
  744. * @brief Accelerometer new data available.[get]
  745. *
  746. * @param ctx Read / write interface definitions
  747. * @param val Change the values of xlda in reg STATUS_REG
  748. * @retval Interface status (MANDATORY: return 0 -> no Error).
  749. *
  750. */
  751. int32_t lsm6ds3tr_c_xl_flag_data_ready_get(stmdev_ctx_t *ctx,
  752. uint8_t *val)
  753. {
  754. lsm6ds3tr_c_status_reg_t status_reg;
  755. int32_t ret;
  756. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_STATUS_REG,
  757. (uint8_t *)&status_reg, 1);
  758. *val = status_reg.xlda;
  759. return ret;
  760. }
  761. /**
  762. * @brief Gyroscope new data available.[get]
  763. *
  764. * @param ctx Read / write interface definitions
  765. * @param val Change the values of gda in reg STATUS_REG
  766. * @retval Interface status (MANDATORY: return 0 -> no Error).
  767. *
  768. */
  769. int32_t lsm6ds3tr_c_gy_flag_data_ready_get(stmdev_ctx_t *ctx,
  770. uint8_t *val)
  771. {
  772. lsm6ds3tr_c_status_reg_t status_reg;
  773. int32_t ret;
  774. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_STATUS_REG,
  775. (uint8_t *)&status_reg, 1);
  776. *val = status_reg.gda;
  777. return ret;
  778. }
  779. /**
  780. * @brief Temperature new data available.[get]
  781. *
  782. * @param ctx Read / write interface definitions
  783. * @param val Change the values of tda in reg STATUS_REG
  784. * @retval Interface status (MANDATORY: return 0 -> no Error).
  785. *
  786. */
  787. int32_t lsm6ds3tr_c_temp_flag_data_ready_get(stmdev_ctx_t *ctx,
  788. uint8_t *val)
  789. {
  790. lsm6ds3tr_c_status_reg_t status_reg;
  791. int32_t ret;
  792. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_STATUS_REG,
  793. (uint8_t *)&status_reg, 1);
  794. *val = status_reg.tda;
  795. return ret;
  796. }
  797. /**
  798. * @brief Accelerometer axis user offset correction expressed in two’s
  799. * complement, weight depends on USR_OFF_W in CTRL6_C.
  800. * The value must be in the range [-127 127].[set]
  801. *
  802. * @param ctx Read / write interface definitions
  803. * @param buff Buffer that contains data to write
  804. * @retval Interface status (MANDATORY: return 0 -> no Error).
  805. *
  806. */
  807. int32_t lsm6ds3tr_c_xl_usr_offset_set(stmdev_ctx_t *ctx,
  808. uint8_t *buff)
  809. {
  810. int32_t ret;
  811. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_X_OFS_USR, buff, 3);
  812. return ret;
  813. }
  814. /**
  815. * @brief Accelerometer axis user offset correction xpressed in two’s
  816. * complement, weight depends on USR_OFF_W in CTRL6_C.
  817. * The value must be in the range [-127 127].[get]
  818. *
  819. * @param ctx Read / write interface definitions
  820. * @param buff Buffer that stores data read
  821. * @retval Interface status (MANDATORY: return 0 -> no Error).
  822. *
  823. */
  824. int32_t lsm6ds3tr_c_xl_usr_offset_get(stmdev_ctx_t *ctx,
  825. uint8_t *buff)
  826. {
  827. int32_t ret;
  828. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_X_OFS_USR, buff, 3);
  829. return ret;
  830. }
  831. /**
  832. * @}
  833. *
  834. */
  835. /**
  836. * @defgroup LSM6DS3TR_C_Timestamp
  837. * @brief This section groups all the functions that manage the
  838. * timestamp generation.
  839. * @{
  840. *
  841. */
  842. /**
  843. * @brief Enable timestamp count. The count is saved in TIMESTAMP0_REG (40h),
  844. * TIMESTAMP1_REG (41h) and TIMESTAMP2_REG (42h).[set]
  845. *
  846. * @param ctx Read / write interface definitions
  847. * @param val Change the values of timer_en in reg CTRL10_C
  848. * @retval Interface status (MANDATORY: return 0 -> no Error).
  849. *
  850. */
  851. int32_t lsm6ds3tr_c_timestamp_set(stmdev_ctx_t *ctx, uint8_t val)
  852. {
  853. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  854. int32_t ret;
  855. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  856. (uint8_t *)&ctrl10_c, 1);
  857. if (ret == 0)
  858. {
  859. ctrl10_c.timer_en = val;
  860. if (val != 0x00U)
  861. {
  862. ctrl10_c.func_en = val;
  863. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  864. (uint8_t *)&ctrl10_c, 1);
  865. }
  866. }
  867. return ret;
  868. }
  869. /**
  870. * @brief Enable timestamp count. The count is saved in TIMESTAMP0_REG (40h),
  871. * TIMESTAMP1_REG (41h) and TIMESTAMP2_REG (42h).[get]
  872. *
  873. * @param ctx Read / write interface definitions
  874. * @param val Change the values of timer_en in reg CTRL10_C
  875. * @retval Interface status (MANDATORY: return 0 -> no Error).
  876. *
  877. */
  878. int32_t lsm6ds3tr_c_timestamp_get(stmdev_ctx_t *ctx, uint8_t *val)
  879. {
  880. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  881. int32_t ret;
  882. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  883. (uint8_t *)&ctrl10_c, 1);
  884. *val = ctrl10_c.timer_en;
  885. return ret;
  886. }
  887. /**
  888. * @brief Timestamp register resolution setting.
  889. * Configuration of this bit affects
  890. * TIMESTAMP0_REG(40h), TIMESTAMP1_REG(41h),
  891. * TIMESTAMP2_REG(42h), STEP_TIMESTAMP_L(49h),
  892. * STEP_TIMESTAMP_H(4Ah) and
  893. * STEP_COUNT_DELTA(15h) registers.[set]
  894. *
  895. * @param ctx Read / write interface definitions
  896. * @param val Change the values of timer_hr in reg WAKE_UP_DUR
  897. * @retval Interface status (MANDATORY: return 0 -> no Error).
  898. *
  899. */
  900. int32_t lsm6ds3tr_c_timestamp_res_set(stmdev_ctx_t *ctx,
  901. lsm6ds3tr_c_timer_hr_t val)
  902. {
  903. lsm6ds3tr_c_wake_up_dur_t wake_up_dur;
  904. int32_t ret;
  905. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  906. (uint8_t *)&wake_up_dur, 1);
  907. if (ret == 0)
  908. {
  909. wake_up_dur.timer_hr = (uint8_t) val;
  910. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  911. (uint8_t *)&wake_up_dur, 1);
  912. }
  913. return ret;
  914. }
  915. /**
  916. * @brief Timestamp register resolution setting.
  917. * Configuration of this bit affects
  918. * TIMESTAMP0_REG(40h), TIMESTAMP1_REG(41h),
  919. * TIMESTAMP2_REG(42h), STEP_TIMESTAMP_L(49h),
  920. * STEP_TIMESTAMP_H(4Ah) and
  921. * STEP_COUNT_DELTA(15h) registers.[get]
  922. *
  923. * @param ctx Read / write interface definitions
  924. * @param val Get the values of timer_hr in reg WAKE_UP_DUR
  925. * @retval Interface status (MANDATORY: return 0 -> no Error).
  926. *
  927. */
  928. int32_t lsm6ds3tr_c_timestamp_res_get(stmdev_ctx_t *ctx,
  929. lsm6ds3tr_c_timer_hr_t *val)
  930. {
  931. lsm6ds3tr_c_wake_up_dur_t wake_up_dur;
  932. int32_t ret;
  933. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  934. (uint8_t *)&wake_up_dur, 1);
  935. switch (wake_up_dur.timer_hr)
  936. {
  937. case LSM6DS3TR_C_LSB_6ms4:
  938. *val = LSM6DS3TR_C_LSB_6ms4;
  939. break;
  940. case LSM6DS3TR_C_LSB_25us:
  941. *val = LSM6DS3TR_C_LSB_25us;
  942. break;
  943. default:
  944. *val = LSM6DS3TR_C_TS_RES_ND;
  945. break;
  946. }
  947. return ret;
  948. }
  949. /**
  950. * @}
  951. *
  952. */
  953. /**
  954. * @defgroup LSM6DS3TR_C_Dataoutput
  955. * @brief This section groups all the data output functions.
  956. * @{
  957. *
  958. */
  959. /**
  960. * @brief Circular burst-mode (rounding) read from output registers
  961. * through the primary interface.[set]
  962. *
  963. * @param ctx Read / write interface definitions
  964. * @param val Change the values of rounding in reg CTRL5_C
  965. * @retval Interface status (MANDATORY: return 0 -> no Error).
  966. *
  967. */
  968. int32_t lsm6ds3tr_c_rounding_mode_set(stmdev_ctx_t *ctx,
  969. lsm6ds3tr_c_rounding_t val)
  970. {
  971. lsm6ds3tr_c_ctrl5_c_t ctrl5_c;
  972. int32_t ret;
  973. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  974. (uint8_t *)&ctrl5_c, 1);
  975. if (ret == 0)
  976. {
  977. ctrl5_c.rounding = (uint8_t) val;
  978. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  979. (uint8_t *)&ctrl5_c, 1);
  980. }
  981. return ret;
  982. }
  983. /**
  984. * @brief Circular burst-mode (rounding) read from output registers
  985. * through the primary interface.[get]
  986. *
  987. * @param ctx Read / write interface definitions
  988. * @param val Get the values of rounding in reg CTRL5_C
  989. * @retval Interface status (MANDATORY: return 0 -> no Error).
  990. *
  991. */
  992. int32_t lsm6ds3tr_c_rounding_mode_get(stmdev_ctx_t *ctx,
  993. lsm6ds3tr_c_rounding_t *val)
  994. {
  995. lsm6ds3tr_c_ctrl5_c_t ctrl5_c;
  996. int32_t ret;
  997. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  998. (uint8_t *)&ctrl5_c, 1);
  999. switch (ctrl5_c.rounding)
  1000. {
  1001. case LSM6DS3TR_C_ROUND_DISABLE:
  1002. *val = LSM6DS3TR_C_ROUND_DISABLE;
  1003. break;
  1004. case LSM6DS3TR_C_ROUND_XL:
  1005. *val = LSM6DS3TR_C_ROUND_XL;
  1006. break;
  1007. case LSM6DS3TR_C_ROUND_GY:
  1008. *val = LSM6DS3TR_C_ROUND_GY;
  1009. break;
  1010. case LSM6DS3TR_C_ROUND_GY_XL:
  1011. *val = LSM6DS3TR_C_ROUND_GY_XL;
  1012. break;
  1013. case LSM6DS3TR_C_ROUND_SH1_TO_SH6:
  1014. *val = LSM6DS3TR_C_ROUND_SH1_TO_SH6;
  1015. break;
  1016. case LSM6DS3TR_C_ROUND_XL_SH1_TO_SH6:
  1017. *val = LSM6DS3TR_C_ROUND_XL_SH1_TO_SH6;
  1018. break;
  1019. case LSM6DS3TR_C_ROUND_GY_XL_SH1_TO_SH12:
  1020. *val = LSM6DS3TR_C_ROUND_GY_XL_SH1_TO_SH12;
  1021. break;
  1022. case LSM6DS3TR_C_ROUND_GY_XL_SH1_TO_SH6:
  1023. *val = LSM6DS3TR_C_ROUND_GY_XL_SH1_TO_SH6;
  1024. break;
  1025. default:
  1026. *val = LSM6DS3TR_C_ROUND_OUT_ND;
  1027. break;
  1028. }
  1029. return ret;
  1030. }
  1031. /**
  1032. * @brief Temperature data output register (r). L and H registers together
  1033. * express a 16-bit word in two’s complement.[get]
  1034. *
  1035. * @param ctx Read / write interface definitions
  1036. * @param buff Buffer that stores data read
  1037. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1038. *
  1039. */
  1040. int32_t lsm6ds3tr_c_temperature_raw_get(stmdev_ctx_t *ctx,
  1041. int16_t *val)
  1042. {
  1043. uint8_t buff[2];
  1044. int32_t ret;
  1045. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_OUT_TEMP_L, buff, 2);
  1046. *val = (int16_t)buff[1];
  1047. *val = (*val * 256) + (int16_t)buff[0];
  1048. return ret;
  1049. }
  1050. /**
  1051. * @brief Angular rate sensor. The value is expressed as a 16-bit word in
  1052. * two’s complement.[get]
  1053. *
  1054. * @param ctx Read / write interface definitions
  1055. * @param buff Buffer that stores data read
  1056. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1057. *
  1058. */
  1059. int32_t lsm6ds3tr_c_angular_rate_raw_get(stmdev_ctx_t *ctx,
  1060. int16_t *val)
  1061. {
  1062. uint8_t buff[6];
  1063. int32_t ret;
  1064. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_OUTX_L_G, buff, 6);
  1065. val[0] = (int16_t)buff[1];
  1066. val[0] = (val[0] * 256) + (int16_t)buff[0];
  1067. val[1] = (int16_t)buff[3];
  1068. val[1] = (val[1] * 256) + (int16_t)buff[2];
  1069. val[2] = (int16_t)buff[5];
  1070. val[2] = (val[2] * 256) + (int16_t)buff[4];
  1071. return ret;
  1072. }
  1073. /**
  1074. * @brief Linear acceleration output register. The value is expressed
  1075. * as a 16-bit word in two’s complement.[get]
  1076. *
  1077. * @param ctx Read / write interface definitions
  1078. * @param buff Buffer that stores data read
  1079. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1080. *
  1081. */
  1082. int32_t lsm6ds3tr_c_acceleration_raw_get(stmdev_ctx_t *ctx,
  1083. int16_t *val)
  1084. {
  1085. uint8_t buff[6];
  1086. int32_t ret;
  1087. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_OUTX_L_XL, buff, 6);
  1088. val[0] = (int16_t)buff[1];
  1089. val[0] = (val[0] * 256) + (int16_t)buff[0];
  1090. val[1] = (int16_t)buff[3];
  1091. val[1] = (val[1] * 256) + (int16_t)buff[2];
  1092. val[2] = (int16_t)buff[5];
  1093. val[2] = (val[2] * 256) + (int16_t)buff[4];
  1094. return ret;
  1095. }
  1096. /**
  1097. * @brief External magnetometer raw data.[get]
  1098. *
  1099. * @param ctx Read / write interface definitions
  1100. * @param buff Buffer that stores data read
  1101. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1102. *
  1103. */
  1104. int32_t lsm6ds3tr_c_mag_calibrated_raw_get(stmdev_ctx_t *ctx,
  1105. int16_t *val)
  1106. {
  1107. uint8_t buff[6];
  1108. int32_t ret;
  1109. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_OUT_MAG_RAW_X_L, buff, 6);
  1110. val[0] = (int16_t)buff[1];
  1111. val[0] = (val[0] * 256) + (int16_t)buff[0];
  1112. val[1] = (int16_t)buff[3];
  1113. val[1] = (val[1] * 256) + (int16_t)buff[2];
  1114. val[2] = (int16_t)buff[5];
  1115. val[2] = (val[2] * 256) + (int16_t)buff[4];
  1116. return ret;
  1117. }
  1118. /**
  1119. * @brief Read data in FIFO.[get]
  1120. *
  1121. * @param ctx Read / write interface definitions
  1122. * @param buffer Data buffer to store FIFO data.
  1123. * @param len Number of data to read from FIFO.
  1124. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1125. *
  1126. */
  1127. int32_t lsm6ds3tr_c_fifo_raw_data_get(stmdev_ctx_t *ctx,
  1128. uint8_t *buffer,
  1129. uint8_t len)
  1130. {
  1131. int32_t ret;
  1132. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_DATA_OUT_L, buffer,
  1133. len);
  1134. return ret;
  1135. }
  1136. /**
  1137. * @}
  1138. *
  1139. */
  1140. /**
  1141. * @defgroup LSM6DS3TR_C_common
  1142. * @brief This section groups common useful functions.
  1143. * @{
  1144. *
  1145. */
  1146. /**
  1147. * @brief Enable access to the embedded functions/sensor hub
  1148. * configuration registers[set]
  1149. *
  1150. * @param ctx Read / write interface definitions
  1151. * @param val Change the values of func_cfg_en in reg FUNC_CFG_ACCESS
  1152. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1153. *
  1154. */
  1155. int32_t lsm6ds3tr_c_mem_bank_set(stmdev_ctx_t *ctx,
  1156. lsm6ds3tr_c_func_cfg_en_t val)
  1157. {
  1158. lsm6ds3tr_c_func_cfg_access_t func_cfg_access;
  1159. int32_t ret;
  1160. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FUNC_CFG_ACCESS,
  1161. (uint8_t *)&func_cfg_access, 1);
  1162. if (ret == 0)
  1163. {
  1164. func_cfg_access.func_cfg_en = (uint8_t) val;
  1165. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FUNC_CFG_ACCESS,
  1166. (uint8_t *)&func_cfg_access, 1);
  1167. }
  1168. return ret;
  1169. }
  1170. /**
  1171. * @brief Enable access to the embedded functions/sensor hub configuration
  1172. * registers[get]
  1173. *
  1174. * @param ctx Read / write interface definitions
  1175. * @param val Get the values of func_cfg_en in reg FUNC_CFG_ACCESS
  1176. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1177. *
  1178. */
  1179. int32_t lsm6ds3tr_c_mem_bank_get(stmdev_ctx_t *ctx,
  1180. lsm6ds3tr_c_func_cfg_en_t *val)
  1181. {
  1182. lsm6ds3tr_c_func_cfg_access_t func_cfg_access;
  1183. int32_t ret;
  1184. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FUNC_CFG_ACCESS,
  1185. (uint8_t *)&func_cfg_access, 1);
  1186. switch (func_cfg_access.func_cfg_en)
  1187. {
  1188. case LSM6DS3TR_C_USER_BANK:
  1189. *val = LSM6DS3TR_C_USER_BANK;
  1190. break;
  1191. case LSM6DS3TR_C_BANK_B:
  1192. *val = LSM6DS3TR_C_BANK_B;
  1193. break;
  1194. default:
  1195. *val = LSM6DS3TR_C_BANK_ND;
  1196. break;
  1197. }
  1198. return ret;
  1199. }
  1200. /**
  1201. * @brief Data-ready pulsed / letched mode[set]
  1202. *
  1203. * @param ctx Read / write interface definitions
  1204. * @param val Change the values of drdy_pulsed in reg DRDY_PULSE_CFG
  1205. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1206. *
  1207. */
  1208. int32_t lsm6ds3tr_c_data_ready_mode_set(stmdev_ctx_t *ctx,
  1209. lsm6ds3tr_c_drdy_pulsed_g_t val)
  1210. {
  1211. lsm6ds3tr_c_drdy_pulse_cfg_g_t drdy_pulse_cfg_g;
  1212. int32_t ret;
  1213. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_DRDY_PULSE_CFG_G,
  1214. (uint8_t *)&drdy_pulse_cfg_g, 1);
  1215. if (ret == 0)
  1216. {
  1217. drdy_pulse_cfg_g.drdy_pulsed = (uint8_t) val;
  1218. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_DRDY_PULSE_CFG_G,
  1219. (uint8_t *)&drdy_pulse_cfg_g, 1);
  1220. }
  1221. return ret;
  1222. }
  1223. /**
  1224. * @brief Data-ready pulsed / letched mode[get]
  1225. *
  1226. * @param ctx Read / write interface definitions
  1227. * @param val Get the values of drdy_pulsed in reg DRDY_PULSE_CFG
  1228. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1229. *
  1230. */
  1231. int32_t lsm6ds3tr_c_data_ready_mode_get(stmdev_ctx_t *ctx,
  1232. lsm6ds3tr_c_drdy_pulsed_g_t *val)
  1233. {
  1234. lsm6ds3tr_c_drdy_pulse_cfg_g_t drdy_pulse_cfg_g;
  1235. int32_t ret;
  1236. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_DRDY_PULSE_CFG_G,
  1237. (uint8_t *)&drdy_pulse_cfg_g, 1);
  1238. switch (drdy_pulse_cfg_g.drdy_pulsed)
  1239. {
  1240. case LSM6DS3TR_C_DRDY_LATCHED:
  1241. *val = LSM6DS3TR_C_DRDY_LATCHED;
  1242. break;
  1243. case LSM6DS3TR_C_DRDY_PULSED:
  1244. *val = LSM6DS3TR_C_DRDY_PULSED;
  1245. break;
  1246. default:
  1247. *val = LSM6DS3TR_C_DRDY_ND;
  1248. break;
  1249. }
  1250. return ret;
  1251. }
  1252. /**
  1253. * @brief DeviceWhoamI.[get]
  1254. *
  1255. * @param ctx Read / write interface definitions
  1256. * @param buff Buffer that stores data read
  1257. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1258. *
  1259. */
  1260. int32_t lsm6ds3tr_c_device_id_get(stmdev_ctx_t *ctx, uint8_t *buff)
  1261. {
  1262. int32_t ret;
  1263. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WHO_AM_I, buff, 1);
  1264. return ret;
  1265. }
  1266. /**
  1267. * @brief Software reset. Restore the default values in user registers[set]
  1268. *
  1269. * @param ctx Read / write interface definitions
  1270. * @param val Change the values of sw_reset in reg CTRL3_C
  1271. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1272. *
  1273. */
  1274. int32_t lsm6ds3tr_c_reset_set(stmdev_ctx_t *ctx, uint8_t val)
  1275. {
  1276. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  1277. int32_t ret;
  1278. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1279. (uint8_t *)&ctrl3_c, 1);
  1280. if (ret == 0)
  1281. {
  1282. ctrl3_c.sw_reset = val;
  1283. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1284. (uint8_t *)&ctrl3_c, 1);
  1285. }
  1286. return ret;
  1287. }
  1288. /**
  1289. * @brief Software reset. Restore the default values in user registers[get]
  1290. *
  1291. * @param ctx Read / write interface definitions
  1292. * @param val Change the values of sw_reset in reg CTRL3_C
  1293. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1294. *
  1295. */
  1296. int32_t lsm6ds3tr_c_reset_get(stmdev_ctx_t *ctx, uint8_t *val)
  1297. {
  1298. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  1299. int32_t ret;
  1300. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1301. (uint8_t *)&ctrl3_c, 1);
  1302. *val = ctrl3_c.sw_reset;
  1303. return ret;
  1304. }
  1305. /**
  1306. * @brief Big/Little Endian Data selection.[set]
  1307. *
  1308. * @param ctx Read / write interface definitions
  1309. * @param val Change the values of ble in reg CTRL3_C
  1310. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1311. *
  1312. */
  1313. int32_t lsm6ds3tr_c_data_format_set(stmdev_ctx_t *ctx,
  1314. lsm6ds3tr_c_ble_t val)
  1315. {
  1316. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  1317. int32_t ret;
  1318. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1319. (uint8_t *)&ctrl3_c, 1);
  1320. if (ret == 0)
  1321. {
  1322. ctrl3_c.ble = (uint8_t) val;
  1323. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1324. (uint8_t *)&ctrl3_c, 1);
  1325. }
  1326. return ret;
  1327. }
  1328. /**
  1329. * @brief Big/Little Endian Data selection.[get]
  1330. *
  1331. * @param ctx Read / write interface definitions
  1332. * @param val Get the values of ble in reg CTRL3_C
  1333. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1334. *
  1335. */
  1336. int32_t lsm6ds3tr_c_data_format_get(stmdev_ctx_t *ctx,
  1337. lsm6ds3tr_c_ble_t *val)
  1338. {
  1339. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  1340. int32_t ret;
  1341. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1342. (uint8_t *)&ctrl3_c, 1);
  1343. switch (ctrl3_c.ble)
  1344. {
  1345. case LSM6DS3TR_C_LSB_AT_LOW_ADD:
  1346. *val = LSM6DS3TR_C_LSB_AT_LOW_ADD;
  1347. break;
  1348. case LSM6DS3TR_C_MSB_AT_LOW_ADD:
  1349. *val = LSM6DS3TR_C_MSB_AT_LOW_ADD;
  1350. break;
  1351. default:
  1352. *val = LSM6DS3TR_C_DATA_FMT_ND;
  1353. break;
  1354. }
  1355. return ret;
  1356. }
  1357. /**
  1358. * @brief Register address automatically incremented during a multiple byte
  1359. * access with a serial interface.[set]
  1360. *
  1361. * @param ctx Read / write interface definitions
  1362. * @param val Change the values of if_inc in reg CTRL3_C
  1363. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1364. *
  1365. */
  1366. int32_t lsm6ds3tr_c_auto_increment_set(stmdev_ctx_t *ctx, uint8_t val)
  1367. {
  1368. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  1369. int32_t ret;
  1370. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1371. (uint8_t *)&ctrl3_c, 1);
  1372. if (ret == 0)
  1373. {
  1374. ctrl3_c.if_inc = val;
  1375. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1376. (uint8_t *)&ctrl3_c, 1);
  1377. }
  1378. return ret;
  1379. }
  1380. /**
  1381. * @brief Register address automatically incremented during a multiple byte
  1382. * access with a serial interface.[get]
  1383. *
  1384. * @param ctx Read / write interface definitions
  1385. * @param val Change the values of if_inc in reg CTRL3_C
  1386. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1387. *
  1388. */
  1389. int32_t lsm6ds3tr_c_auto_increment_get(stmdev_ctx_t *ctx,
  1390. uint8_t *val)
  1391. {
  1392. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  1393. int32_t ret;
  1394. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1395. (uint8_t *)&ctrl3_c, 1);
  1396. *val = ctrl3_c.if_inc;
  1397. return ret;
  1398. }
  1399. /**
  1400. * @brief Reboot memory content. Reload the calibration parameters.[set]
  1401. *
  1402. * @param ctx Read / write interface definitions
  1403. * @param val Change the values of boot in reg CTRL3_C
  1404. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1405. *
  1406. */
  1407. int32_t lsm6ds3tr_c_boot_set(stmdev_ctx_t *ctx, uint8_t val)
  1408. {
  1409. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  1410. int32_t ret;
  1411. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1412. (uint8_t *)&ctrl3_c, 1);
  1413. if (ret == 0)
  1414. {
  1415. ctrl3_c.boot = val;
  1416. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1417. (uint8_t *)&ctrl3_c, 1);
  1418. }
  1419. return ret;
  1420. }
  1421. /**
  1422. * @brief Reboot memory content. Reload the calibration parameters.[get]
  1423. *
  1424. * @param ctx Read / write interface definitions
  1425. * @param val Change the values of boot in reg CTRL3_C
  1426. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1427. *
  1428. */
  1429. int32_t lsm6ds3tr_c_boot_get(stmdev_ctx_t *ctx, uint8_t *val)
  1430. {
  1431. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  1432. int32_t ret;
  1433. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  1434. (uint8_t *)&ctrl3_c, 1);
  1435. *val = ctrl3_c.boot;
  1436. return ret;
  1437. }
  1438. /**
  1439. * @brief Linear acceleration sensor self-test enable.[set]
  1440. *
  1441. * @param ctx Read / write interface definitions
  1442. * @param val Change the values of st_xl in reg CTRL5_C
  1443. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1444. *
  1445. */
  1446. int32_t lsm6ds3tr_c_xl_self_test_set(stmdev_ctx_t *ctx,
  1447. lsm6ds3tr_c_st_xl_t val)
  1448. {
  1449. lsm6ds3tr_c_ctrl5_c_t ctrl5_c;
  1450. int32_t ret;
  1451. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  1452. (uint8_t *)&ctrl5_c, 1);
  1453. if (ret == 0)
  1454. {
  1455. ctrl5_c.st_xl = (uint8_t) val;
  1456. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  1457. (uint8_t *)&ctrl5_c, 1);
  1458. }
  1459. return ret;
  1460. }
  1461. /**
  1462. * @brief Linear acceleration sensor self-test enable.[get]
  1463. *
  1464. * @param ctx Read / write interface definitions
  1465. * @param val Get the values of st_xl in reg CTRL5_C
  1466. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1467. *
  1468. */
  1469. int32_t lsm6ds3tr_c_xl_self_test_get(stmdev_ctx_t *ctx,
  1470. lsm6ds3tr_c_st_xl_t *val)
  1471. {
  1472. lsm6ds3tr_c_ctrl5_c_t ctrl5_c;
  1473. int32_t ret;
  1474. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  1475. (uint8_t *)&ctrl5_c, 1);
  1476. switch (ctrl5_c.st_xl)
  1477. {
  1478. case LSM6DS3TR_C_XL_ST_DISABLE:
  1479. *val = LSM6DS3TR_C_XL_ST_DISABLE;
  1480. break;
  1481. case LSM6DS3TR_C_XL_ST_POSITIVE:
  1482. *val = LSM6DS3TR_C_XL_ST_POSITIVE;
  1483. break;
  1484. case LSM6DS3TR_C_XL_ST_NEGATIVE:
  1485. *val = LSM6DS3TR_C_XL_ST_NEGATIVE;
  1486. break;
  1487. default:
  1488. *val = LSM6DS3TR_C_XL_ST_ND;
  1489. break;
  1490. }
  1491. return ret;
  1492. }
  1493. /**
  1494. * @brief Angular rate sensor self-test enable.[set]
  1495. *
  1496. * @param ctx Read / write interface definitions
  1497. * @param val Change the values of st_g in reg CTRL5_C
  1498. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1499. *
  1500. */
  1501. int32_t lsm6ds3tr_c_gy_self_test_set(stmdev_ctx_t *ctx,
  1502. lsm6ds3tr_c_st_g_t val)
  1503. {
  1504. lsm6ds3tr_c_ctrl5_c_t ctrl5_c;
  1505. int32_t ret;
  1506. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  1507. (uint8_t *)&ctrl5_c, 1);
  1508. if (ret == 0)
  1509. {
  1510. ctrl5_c.st_g = (uint8_t) val;
  1511. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  1512. (uint8_t *)&ctrl5_c, 1);
  1513. }
  1514. return ret;
  1515. }
  1516. /**
  1517. * @brief Angular rate sensor self-test enable.[get]
  1518. *
  1519. * @param ctx Read / write interface definitions
  1520. * @param val Get the values of st_g in reg CTRL5_C
  1521. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1522. *
  1523. */
  1524. int32_t lsm6ds3tr_c_gy_self_test_get(stmdev_ctx_t *ctx,
  1525. lsm6ds3tr_c_st_g_t *val)
  1526. {
  1527. lsm6ds3tr_c_ctrl5_c_t ctrl5_c;
  1528. int32_t ret;
  1529. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  1530. (uint8_t *)&ctrl5_c, 1);
  1531. switch (ctrl5_c.st_g)
  1532. {
  1533. case LSM6DS3TR_C_GY_ST_DISABLE:
  1534. *val = LSM6DS3TR_C_GY_ST_DISABLE;
  1535. break;
  1536. case LSM6DS3TR_C_GY_ST_POSITIVE:
  1537. *val = LSM6DS3TR_C_GY_ST_POSITIVE;
  1538. break;
  1539. case LSM6DS3TR_C_GY_ST_NEGATIVE:
  1540. *val = LSM6DS3TR_C_GY_ST_NEGATIVE;
  1541. break;
  1542. default:
  1543. *val = LSM6DS3TR_C_GY_ST_ND;
  1544. break;
  1545. }
  1546. return ret;
  1547. }
  1548. /**
  1549. * @}
  1550. *
  1551. */
  1552. /**
  1553. * @defgroup LSM6DS3TR_C_filters
  1554. * @brief This section group all the functions concerning the filters
  1555. * configuration that impact both accelerometer and gyro.
  1556. * @{
  1557. *
  1558. */
  1559. /**
  1560. * @brief Mask DRDY on pin (both XL & Gyro) until filter settling ends
  1561. * (XL and Gyro independently masked).[set]
  1562. *
  1563. * @param ctx Read / write interface definitions
  1564. * @param val Change the values of drdy_mask in reg CTRL4_C
  1565. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1566. *
  1567. */
  1568. int32_t lsm6ds3tr_c_filter_settling_mask_set(stmdev_ctx_t *ctx,
  1569. uint8_t val)
  1570. {
  1571. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  1572. int32_t ret;
  1573. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  1574. (uint8_t *)&ctrl4_c, 1);
  1575. if (ret == 0)
  1576. {
  1577. ctrl4_c.drdy_mask = val;
  1578. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  1579. (uint8_t *)&ctrl4_c, 1);
  1580. }
  1581. return ret;
  1582. }
  1583. /**
  1584. * @brief Mask DRDY on pin (both XL & Gyro) until filter settling ends
  1585. * (XL and Gyro independently masked).[get]
  1586. *
  1587. * @param ctx Read / write interface definitions
  1588. * @param val Change the values of drdy_mask in reg CTRL4_C
  1589. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1590. *
  1591. */
  1592. int32_t lsm6ds3tr_c_filter_settling_mask_get(stmdev_ctx_t *ctx,
  1593. uint8_t *val)
  1594. {
  1595. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  1596. int32_t ret;
  1597. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  1598. (uint8_t *)&ctrl4_c, 1);
  1599. *val = ctrl4_c.drdy_mask;
  1600. return ret;
  1601. }
  1602. /**
  1603. * @brief HPF or SLOPE filter selection on wake-up and Activity/Inactivity
  1604. * functions.[set]
  1605. *
  1606. * @param ctx Read / write interface definitions
  1607. * @param val Change the values of slope_fds in reg TAP_CFG
  1608. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1609. *
  1610. */
  1611. int32_t lsm6ds3tr_c_xl_hp_path_internal_set(stmdev_ctx_t *ctx,
  1612. lsm6ds3tr_c_slope_fds_t val)
  1613. {
  1614. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  1615. int32_t ret;
  1616. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  1617. (uint8_t *)&tap_cfg, 1);
  1618. if (ret == 0)
  1619. {
  1620. tap_cfg.slope_fds = (uint8_t) val;
  1621. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  1622. (uint8_t *)&tap_cfg, 1);
  1623. }
  1624. return ret;
  1625. }
  1626. /**
  1627. * @brief HPF or SLOPE filter selection on wake-up and Activity/Inactivity
  1628. * functions.[get]
  1629. *
  1630. * @param ctx Read / write interface definitions
  1631. * @param val Get the values of slope_fds in reg TAP_CFG
  1632. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1633. *
  1634. */
  1635. int32_t lsm6ds3tr_c_xl_hp_path_internal_get(stmdev_ctx_t *ctx,
  1636. lsm6ds3tr_c_slope_fds_t *val)
  1637. {
  1638. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  1639. int32_t ret;
  1640. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  1641. (uint8_t *)&tap_cfg, 1);
  1642. switch (tap_cfg.slope_fds)
  1643. {
  1644. case LSM6DS3TR_C_USE_SLOPE:
  1645. *val = LSM6DS3TR_C_USE_SLOPE;
  1646. break;
  1647. case LSM6DS3TR_C_USE_HPF:
  1648. *val = LSM6DS3TR_C_USE_HPF;
  1649. break;
  1650. default:
  1651. *val = LSM6DS3TR_C_HP_PATH_ND;
  1652. break;
  1653. }
  1654. return ret;
  1655. }
  1656. /**
  1657. * @}
  1658. *
  1659. */
  1660. /**
  1661. * @defgroup LSM6DS3TR_C_accelerometer_filters
  1662. * @brief This section group all the functions concerning the filters
  1663. * configuration that impact accelerometer in every mode.
  1664. * @{
  1665. *
  1666. */
  1667. /**
  1668. * @brief Accelerometer analog chain bandwidth selection (only for
  1669. * accelerometer ODR ≥ 1.67 kHz).[set]
  1670. *
  1671. * @param ctx Read / write interface definitions
  1672. * @param val Change the values of bw0_xl in reg CTRL1_XL
  1673. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1674. *
  1675. */
  1676. int32_t lsm6ds3tr_c_xl_filter_analog_set(stmdev_ctx_t *ctx,
  1677. lsm6ds3tr_c_bw0_xl_t val)
  1678. {
  1679. lsm6ds3tr_c_ctrl1_xl_t ctrl1_xl;
  1680. int32_t ret;
  1681. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  1682. (uint8_t *)&ctrl1_xl, 1);
  1683. if (ret == 0)
  1684. {
  1685. ctrl1_xl.bw0_xl = (uint8_t) val;
  1686. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  1687. (uint8_t *)&ctrl1_xl, 1);
  1688. }
  1689. return ret;
  1690. }
  1691. /**
  1692. * @brief Accelerometer analog chain bandwidth selection (only for
  1693. * accelerometer ODR ≥ 1.67 kHz).[get]
  1694. *
  1695. * @param ctx Read / write interface definitions
  1696. * @param val Get the values of bw0_xl in reg CTRL1_XL
  1697. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1698. *
  1699. */
  1700. int32_t lsm6ds3tr_c_xl_filter_analog_get(stmdev_ctx_t *ctx,
  1701. lsm6ds3tr_c_bw0_xl_t *val)
  1702. {
  1703. lsm6ds3tr_c_ctrl1_xl_t ctrl1_xl;
  1704. int32_t ret;
  1705. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  1706. (uint8_t *)&ctrl1_xl, 1);
  1707. switch (ctrl1_xl.bw0_xl)
  1708. {
  1709. case LSM6DS3TR_C_XL_ANA_BW_1k5Hz:
  1710. *val = LSM6DS3TR_C_XL_ANA_BW_1k5Hz;
  1711. break;
  1712. case LSM6DS3TR_C_XL_ANA_BW_400Hz:
  1713. *val = LSM6DS3TR_C_XL_ANA_BW_400Hz;
  1714. break;
  1715. default:
  1716. *val = LSM6DS3TR_C_XL_ANA_BW_ND;
  1717. break;
  1718. }
  1719. return ret;
  1720. }
  1721. /**
  1722. * @}
  1723. *
  1724. */
  1725. /**
  1726. * @defgroup LSM6DS3TR_C_accelerometer_filters
  1727. * @brief This section group all the functions concerning the filters
  1728. * configuration that impact accelerometer.
  1729. * @{
  1730. *
  1731. */
  1732. /**
  1733. * @brief Accelerometer digital LPF (LPF1) bandwidth selection LPF2 is
  1734. * not used.[set]
  1735. *
  1736. * @param ctx Read / write interface definitions
  1737. * @param val Change the values of lpf1_bw_sel in reg CTRL1_XL
  1738. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1739. *
  1740. */
  1741. int32_t lsm6ds3tr_c_xl_lp1_bandwidth_set(stmdev_ctx_t *ctx,
  1742. lsm6ds3tr_c_lpf1_bw_sel_t val)
  1743. {
  1744. lsm6ds3tr_c_ctrl1_xl_t ctrl1_xl;
  1745. lsm6ds3tr_c_ctrl8_xl_t ctrl8_xl;
  1746. int32_t ret;
  1747. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  1748. (uint8_t *)&ctrl1_xl, 1);
  1749. if (ret == 0)
  1750. {
  1751. ctrl1_xl.lpf1_bw_sel = (uint8_t) val;
  1752. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  1753. (uint8_t *)&ctrl1_xl, 1);
  1754. if (ret == 0)
  1755. {
  1756. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1757. (uint8_t *)&ctrl8_xl, 1);
  1758. if (ret == 0)
  1759. {
  1760. ctrl8_xl.lpf2_xl_en = 0;
  1761. ctrl8_xl.hp_slope_xl_en = 0;
  1762. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1763. (uint8_t *)&ctrl8_xl, 1);
  1764. }
  1765. }
  1766. }
  1767. return ret;
  1768. }
  1769. /**
  1770. * @brief Accelerometer digital LPF (LPF1) bandwidth selection LPF2
  1771. * is not used.[get]
  1772. *
  1773. * @param ctx Read / write interface definitions
  1774. * @param val Get the values of lpf1_bw_sel in reg CTRL1_XL
  1775. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1776. *
  1777. */
  1778. int32_t lsm6ds3tr_c_xl_lp1_bandwidth_get(stmdev_ctx_t *ctx,
  1779. lsm6ds3tr_c_lpf1_bw_sel_t *val)
  1780. {
  1781. lsm6ds3tr_c_ctrl1_xl_t ctrl1_xl;
  1782. lsm6ds3tr_c_ctrl8_xl_t ctrl8_xl;
  1783. int32_t ret;
  1784. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1785. (uint8_t *)&ctrl8_xl, 1);
  1786. if (ret == 0)
  1787. {
  1788. if ((ctrl8_xl.lpf2_xl_en != 0x00U) ||
  1789. (ctrl8_xl.hp_slope_xl_en != 0x00U))
  1790. {
  1791. *val = LSM6DS3TR_C_XL_LP1_NA;
  1792. }
  1793. else
  1794. {
  1795. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL1_XL,
  1796. (uint8_t *)&ctrl1_xl, 1);
  1797. switch (ctrl1_xl.lpf1_bw_sel)
  1798. {
  1799. case LSM6DS3TR_C_XL_LP1_ODR_DIV_2:
  1800. *val = LSM6DS3TR_C_XL_LP1_ODR_DIV_2;
  1801. break;
  1802. case LSM6DS3TR_C_XL_LP1_ODR_DIV_4:
  1803. *val = LSM6DS3TR_C_XL_LP1_ODR_DIV_4;
  1804. break;
  1805. default:
  1806. *val = LSM6DS3TR_C_XL_LP1_NA;
  1807. break;
  1808. }
  1809. }
  1810. }
  1811. return ret;
  1812. }
  1813. /**
  1814. * @brief LPF2 on outputs[set]
  1815. *
  1816. * @param ctx Read / write interface definitions
  1817. * @param val Change the values of input_composite in reg CTRL8_XL
  1818. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1819. *
  1820. */
  1821. int32_t lsm6ds3tr_c_xl_lp2_bandwidth_set(stmdev_ctx_t *ctx,
  1822. lsm6ds3tr_c_input_composite_t val)
  1823. {
  1824. lsm6ds3tr_c_ctrl8_xl_t ctrl8_xl;
  1825. int32_t ret;
  1826. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1827. (uint8_t *)&ctrl8_xl, 1);
  1828. if (ret == 0)
  1829. {
  1830. ctrl8_xl.input_composite = ((uint8_t) val & 0x10U) >> 4;
  1831. ctrl8_xl.hpcf_xl = (uint8_t) val & 0x03U;
  1832. ctrl8_xl.lpf2_xl_en = 1;
  1833. ctrl8_xl.hp_slope_xl_en = 0;
  1834. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1835. (uint8_t *)&ctrl8_xl, 1);
  1836. }
  1837. return ret;
  1838. }
  1839. /**
  1840. * @brief LPF2 on outputs[get]
  1841. *
  1842. * @param ctx Read / write interface definitions
  1843. * @param val Get the values of input_composite in reg CTRL8_XL
  1844. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1845. *
  1846. */
  1847. int32_t lsm6ds3tr_c_xl_lp2_bandwidth_get(stmdev_ctx_t *ctx,
  1848. lsm6ds3tr_c_input_composite_t *val)
  1849. {
  1850. lsm6ds3tr_c_ctrl8_xl_t ctrl8_xl;
  1851. int32_t ret;
  1852. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1853. (uint8_t *)&ctrl8_xl, 1);
  1854. if (ret == 0)
  1855. {
  1856. if ((ctrl8_xl.lpf2_xl_en == 0x00U) ||
  1857. (ctrl8_xl.hp_slope_xl_en != 0x00U))
  1858. {
  1859. *val = LSM6DS3TR_C_XL_LP_NA;
  1860. }
  1861. else
  1862. {
  1863. switch ((ctrl8_xl.input_composite << 4) + ctrl8_xl.hpcf_xl)
  1864. {
  1865. case LSM6DS3TR_C_XL_LOW_LAT_LP_ODR_DIV_50:
  1866. *val = LSM6DS3TR_C_XL_LOW_LAT_LP_ODR_DIV_50;
  1867. break;
  1868. case LSM6DS3TR_C_XL_LOW_LAT_LP_ODR_DIV_100:
  1869. *val = LSM6DS3TR_C_XL_LOW_LAT_LP_ODR_DIV_100;
  1870. break;
  1871. case LSM6DS3TR_C_XL_LOW_LAT_LP_ODR_DIV_9:
  1872. *val = LSM6DS3TR_C_XL_LOW_LAT_LP_ODR_DIV_9;
  1873. break;
  1874. case LSM6DS3TR_C_XL_LOW_LAT_LP_ODR_DIV_400:
  1875. *val = LSM6DS3TR_C_XL_LOW_LAT_LP_ODR_DIV_400;
  1876. break;
  1877. case LSM6DS3TR_C_XL_LOW_NOISE_LP_ODR_DIV_50:
  1878. *val = LSM6DS3TR_C_XL_LOW_NOISE_LP_ODR_DIV_50;
  1879. break;
  1880. case LSM6DS3TR_C_XL_LOW_NOISE_LP_ODR_DIV_100:
  1881. *val = LSM6DS3TR_C_XL_LOW_NOISE_LP_ODR_DIV_100;
  1882. break;
  1883. case LSM6DS3TR_C_XL_LOW_NOISE_LP_ODR_DIV_9:
  1884. *val = LSM6DS3TR_C_XL_LOW_NOISE_LP_ODR_DIV_9;
  1885. break;
  1886. case LSM6DS3TR_C_XL_LOW_NOISE_LP_ODR_DIV_400:
  1887. *val = LSM6DS3TR_C_XL_LOW_NOISE_LP_ODR_DIV_400;
  1888. break;
  1889. default:
  1890. *val = LSM6DS3TR_C_XL_LP_NA;
  1891. break;
  1892. }
  1893. }
  1894. }
  1895. return ret;
  1896. }
  1897. /**
  1898. * @brief Enable HP filter reference mode.[set]
  1899. *
  1900. * @param ctx Read / write interface definitions
  1901. * @param val Change the values of hp_ref_mode in reg CTRL8_XL
  1902. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1903. *
  1904. */
  1905. int32_t lsm6ds3tr_c_xl_reference_mode_set(stmdev_ctx_t *ctx,
  1906. uint8_t val)
  1907. {
  1908. lsm6ds3tr_c_ctrl8_xl_t ctrl8_xl;
  1909. int32_t ret;
  1910. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1911. (uint8_t *)&ctrl8_xl, 1);
  1912. if (ret == 0)
  1913. {
  1914. ctrl8_xl.hp_ref_mode = val;
  1915. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1916. (uint8_t *)&ctrl8_xl, 1);
  1917. }
  1918. return ret;
  1919. }
  1920. /**
  1921. * @brief Enable HP filter reference mode.[get]
  1922. *
  1923. * @param ctx Read / write interface definitions
  1924. * @param val Change the values of hp_ref_mode in reg CTRL8_XL
  1925. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1926. *
  1927. */
  1928. int32_t lsm6ds3tr_c_xl_reference_mode_get(stmdev_ctx_t *ctx,
  1929. uint8_t *val)
  1930. {
  1931. lsm6ds3tr_c_ctrl8_xl_t ctrl8_xl;
  1932. int32_t ret;
  1933. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1934. (uint8_t *)&ctrl8_xl, 1);
  1935. *val = ctrl8_xl.hp_ref_mode;
  1936. return ret;
  1937. }
  1938. /**
  1939. * @brief High pass/Slope on outputs.[set]
  1940. *
  1941. * @param ctx Read / write interface definitions
  1942. * @param val Change the values of hpcf_xl in reg CTRL8_XL
  1943. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1944. *
  1945. */
  1946. int32_t lsm6ds3tr_c_xl_hp_bandwidth_set(stmdev_ctx_t *ctx,
  1947. lsm6ds3tr_c_hpcf_xl_t val)
  1948. {
  1949. lsm6ds3tr_c_ctrl8_xl_t ctrl8_xl;
  1950. int32_t ret;
  1951. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1952. (uint8_t *)&ctrl8_xl, 1);
  1953. if (ret == 0)
  1954. {
  1955. ctrl8_xl.input_composite = 0;
  1956. ctrl8_xl.hpcf_xl = (uint8_t)val & 0x03U;
  1957. ctrl8_xl.hp_slope_xl_en = 1;
  1958. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1959. (uint8_t *)&ctrl8_xl, 1);
  1960. }
  1961. return ret;
  1962. }
  1963. /**
  1964. * @brief High pass/Slope on outputs.[get]
  1965. *
  1966. * @param ctx Read / write interface definitions
  1967. * @param val Get the values of hpcf_xl in reg CTRL8_XL
  1968. * @retval Interface status (MANDATORY: return 0 -> no Error).
  1969. *
  1970. */
  1971. int32_t lsm6ds3tr_c_xl_hp_bandwidth_get(stmdev_ctx_t *ctx,
  1972. lsm6ds3tr_c_hpcf_xl_t *val)
  1973. {
  1974. lsm6ds3tr_c_ctrl8_xl_t ctrl8_xl;
  1975. int32_t ret;
  1976. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  1977. (uint8_t *)&ctrl8_xl, 1);
  1978. if (ctrl8_xl.hp_slope_xl_en == 0x00U)
  1979. {
  1980. *val = LSM6DS3TR_C_XL_HP_NA;
  1981. }
  1982. switch (ctrl8_xl.hpcf_xl)
  1983. {
  1984. case LSM6DS3TR_C_XL_HP_ODR_DIV_4:
  1985. *val = LSM6DS3TR_C_XL_HP_ODR_DIV_4;
  1986. break;
  1987. case LSM6DS3TR_C_XL_HP_ODR_DIV_100:
  1988. *val = LSM6DS3TR_C_XL_HP_ODR_DIV_100;
  1989. break;
  1990. case LSM6DS3TR_C_XL_HP_ODR_DIV_9:
  1991. *val = LSM6DS3TR_C_XL_HP_ODR_DIV_9;
  1992. break;
  1993. case LSM6DS3TR_C_XL_HP_ODR_DIV_400:
  1994. *val = LSM6DS3TR_C_XL_HP_ODR_DIV_400;
  1995. break;
  1996. default:
  1997. *val = LSM6DS3TR_C_XL_HP_NA;
  1998. break;
  1999. }
  2000. return ret;
  2001. }
  2002. /**
  2003. * @}
  2004. *
  2005. */
  2006. /**
  2007. * @defgroup LSM6DS3TR_C_gyroscope_filters
  2008. * @brief This section group all the functions concerning the filters
  2009. * configuration that impact gyroscope.
  2010. * @{
  2011. *
  2012. */
  2013. /**
  2014. * @brief Gyroscope low pass path bandwidth.[set]
  2015. *
  2016. * @param ctx Read / write interface definitions
  2017. * @param val gyroscope filtering chain configuration.
  2018. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2019. *
  2020. */
  2021. int32_t lsm6ds3tr_c_gy_band_pass_set(stmdev_ctx_t *ctx,
  2022. lsm6ds3tr_c_lpf1_sel_g_t val)
  2023. {
  2024. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  2025. lsm6ds3tr_c_ctrl6_c_t ctrl6_c;
  2026. lsm6ds3tr_c_ctrl7_g_t ctrl7_g;
  2027. int32_t ret;
  2028. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL7_G,
  2029. (uint8_t *)&ctrl7_g, 1);
  2030. if (ret == 0)
  2031. {
  2032. ctrl7_g.hpm_g = ((uint8_t)val & 0x30U) >> 4;
  2033. ctrl7_g.hp_en_g = ((uint8_t)val & 0x80U) >> 7;
  2034. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL7_G,
  2035. (uint8_t *)&ctrl7_g, 1);
  2036. if (ret == 0)
  2037. {
  2038. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  2039. (uint8_t *)&ctrl6_c, 1);
  2040. if (ret == 0)
  2041. {
  2042. ctrl6_c.ftype = (uint8_t)val & 0x03U;
  2043. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  2044. (uint8_t *)&ctrl6_c, 1);
  2045. if (ret == 0)
  2046. {
  2047. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2048. (uint8_t *)&ctrl4_c, 1);
  2049. if (ret == 0)
  2050. {
  2051. ctrl4_c.lpf1_sel_g = ((uint8_t)val & 0x08U) >> 3;
  2052. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2053. (uint8_t *)&ctrl4_c, 1);
  2054. }
  2055. }
  2056. }
  2057. }
  2058. }
  2059. return ret;
  2060. }
  2061. /**
  2062. * @brief Gyroscope low pass path bandwidth.[get]
  2063. *
  2064. * @param ctx Read / write interface definitions
  2065. * @param val gyroscope filtering chain
  2066. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2067. *
  2068. */
  2069. int32_t lsm6ds3tr_c_gy_band_pass_get(stmdev_ctx_t *ctx,
  2070. lsm6ds3tr_c_lpf1_sel_g_t *val)
  2071. {
  2072. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  2073. lsm6ds3tr_c_ctrl6_c_t ctrl6_c;
  2074. lsm6ds3tr_c_ctrl7_g_t ctrl7_g;
  2075. int32_t ret;
  2076. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  2077. (uint8_t *)&ctrl6_c, 1);
  2078. if (ret == 0)
  2079. {
  2080. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2081. (uint8_t *)&ctrl4_c, 1);
  2082. if (ret == 0)
  2083. {
  2084. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL7_G,
  2085. (uint8_t *)&ctrl7_g, 1);
  2086. switch ((ctrl7_g.hp_en_g << 7) + (ctrl7_g.hpm_g << 4) +
  2087. (ctrl4_c.lpf1_sel_g << 3) + ctrl6_c.ftype)
  2088. {
  2089. case LSM6DS3TR_C_HP_16mHz_LP2:
  2090. *val = LSM6DS3TR_C_HP_16mHz_LP2;
  2091. break;
  2092. case LSM6DS3TR_C_HP_65mHz_LP2:
  2093. *val = LSM6DS3TR_C_HP_65mHz_LP2;
  2094. break;
  2095. case LSM6DS3TR_C_HP_260mHz_LP2:
  2096. *val = LSM6DS3TR_C_HP_260mHz_LP2;
  2097. break;
  2098. case LSM6DS3TR_C_HP_1Hz04_LP2:
  2099. *val = LSM6DS3TR_C_HP_1Hz04_LP2;
  2100. break;
  2101. case LSM6DS3TR_C_HP_DISABLE_LP1_LIGHT:
  2102. *val = LSM6DS3TR_C_HP_DISABLE_LP1_LIGHT;
  2103. break;
  2104. case LSM6DS3TR_C_HP_DISABLE_LP1_NORMAL:
  2105. *val = LSM6DS3TR_C_HP_DISABLE_LP1_NORMAL;
  2106. break;
  2107. case LSM6DS3TR_C_HP_DISABLE_LP_STRONG:
  2108. *val = LSM6DS3TR_C_HP_DISABLE_LP_STRONG;
  2109. break;
  2110. case LSM6DS3TR_C_HP_DISABLE_LP1_AGGRESSIVE:
  2111. *val = LSM6DS3TR_C_HP_DISABLE_LP1_AGGRESSIVE;
  2112. break;
  2113. case LSM6DS3TR_C_HP_16mHz_LP1_LIGHT:
  2114. *val = LSM6DS3TR_C_HP_16mHz_LP1_LIGHT;
  2115. break;
  2116. case LSM6DS3TR_C_HP_65mHz_LP1_NORMAL:
  2117. *val = LSM6DS3TR_C_HP_65mHz_LP1_NORMAL;
  2118. break;
  2119. case LSM6DS3TR_C_HP_260mHz_LP1_STRONG:
  2120. *val = LSM6DS3TR_C_HP_260mHz_LP1_STRONG;
  2121. break;
  2122. case LSM6DS3TR_C_HP_1Hz04_LP1_AGGRESSIVE:
  2123. *val = LSM6DS3TR_C_HP_1Hz04_LP1_AGGRESSIVE;
  2124. break;
  2125. default:
  2126. *val = LSM6DS3TR_C_HP_GY_BAND_NA;
  2127. break;
  2128. }
  2129. }
  2130. }
  2131. return ret;
  2132. }
  2133. /**
  2134. * @}
  2135. *
  2136. */
  2137. /**
  2138. * @defgroup LSM6DS3TR_C_serial_interface
  2139. * @brief This section groups all the functions concerning serial
  2140. * interface management
  2141. * @{
  2142. *
  2143. */
  2144. /**
  2145. * @brief SPI Serial Interface Mode selection.[set]
  2146. *
  2147. * @param ctx Read / write interface definitions
  2148. * @param val Change the values of sim in reg CTRL3_C
  2149. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2150. *
  2151. */
  2152. int32_t lsm6ds3tr_c_spi_mode_set(stmdev_ctx_t *ctx,
  2153. lsm6ds3tr_c_sim_t val)
  2154. {
  2155. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  2156. int32_t ret;
  2157. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  2158. (uint8_t *)&ctrl3_c, 1);
  2159. if (ret == 0)
  2160. {
  2161. ctrl3_c.sim = (uint8_t) val;
  2162. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  2163. (uint8_t *)&ctrl3_c, 1);
  2164. }
  2165. return ret;
  2166. }
  2167. /**
  2168. * @brief SPI Serial Interface Mode selection.[get]
  2169. *
  2170. * @param ctx Read / write interface definitions
  2171. * @param val Get the values of sim in reg CTRL3_C
  2172. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2173. *
  2174. */
  2175. int32_t lsm6ds3tr_c_spi_mode_get(stmdev_ctx_t *ctx,
  2176. lsm6ds3tr_c_sim_t *val)
  2177. {
  2178. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  2179. int32_t ret;
  2180. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  2181. (uint8_t *)&ctrl3_c, 1);
  2182. switch (ctrl3_c.sim)
  2183. {
  2184. case LSM6DS3TR_C_SPI_4_WIRE:
  2185. *val = LSM6DS3TR_C_SPI_4_WIRE;
  2186. break;
  2187. case LSM6DS3TR_C_SPI_3_WIRE:
  2188. *val = LSM6DS3TR_C_SPI_3_WIRE;
  2189. break;
  2190. default:
  2191. *val = LSM6DS3TR_C_SPI_MODE_ND;
  2192. break;
  2193. }
  2194. return ret;
  2195. }
  2196. /**
  2197. * @brief Disable / Enable I2C interface.[set]
  2198. *
  2199. * @param ctx Read / write interface definitions
  2200. * @param val Change the values of i2c_disable in reg CTRL4_C
  2201. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2202. *
  2203. */
  2204. int32_t lsm6ds3tr_c_i2c_interface_set(stmdev_ctx_t *ctx,
  2205. lsm6ds3tr_c_i2c_disable_t val)
  2206. {
  2207. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  2208. int32_t ret;
  2209. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2210. (uint8_t *)&ctrl4_c, 1);
  2211. if (ret == 0)
  2212. {
  2213. ctrl4_c.i2c_disable = (uint8_t)val;
  2214. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2215. (uint8_t *)&ctrl4_c, 1);
  2216. }
  2217. return ret;
  2218. }
  2219. /**
  2220. * @brief Disable / Enable I2C interface.[get]
  2221. *
  2222. * @param ctx Read / write interface definitions
  2223. * @param val Get the values of i2c_disable in reg CTRL4_C
  2224. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2225. *
  2226. */
  2227. int32_t lsm6ds3tr_c_i2c_interface_get(stmdev_ctx_t *ctx,
  2228. lsm6ds3tr_c_i2c_disable_t *val)
  2229. {
  2230. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  2231. int32_t ret;
  2232. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2233. (uint8_t *)&ctrl4_c, 1);
  2234. switch (ctrl4_c.i2c_disable)
  2235. {
  2236. case LSM6DS3TR_C_I2C_ENABLE:
  2237. *val = LSM6DS3TR_C_I2C_ENABLE;
  2238. break;
  2239. case LSM6DS3TR_C_I2C_DISABLE:
  2240. *val = LSM6DS3TR_C_I2C_DISABLE;
  2241. break;
  2242. default:
  2243. *val = LSM6DS3TR_C_I2C_MODE_ND;
  2244. break;
  2245. }
  2246. return ret;
  2247. }
  2248. /**
  2249. * @}
  2250. *
  2251. */
  2252. /**
  2253. * @defgroup LSM6DS3TR_C_interrupt_pins
  2254. * @brief This section groups all the functions that manage
  2255. * interrupt pins
  2256. * @{
  2257. *
  2258. */
  2259. /**
  2260. * @brief Select the signal that need to route on int1 pad[set]
  2261. *
  2262. * @param ctx Read / write interface definitions
  2263. * @param val configure INT1_CTRL, MD1_CFG, CTRL4_C(den_drdy_int1),
  2264. * MASTER_CONFIG(drdy_on_int1)
  2265. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2266. *
  2267. */
  2268. int32_t lsm6ds3tr_c_pin_int1_route_set(stmdev_ctx_t *ctx,
  2269. lsm6ds3tr_c_int1_route_t val)
  2270. {
  2271. lsm6ds3tr_c_master_config_t master_config;
  2272. lsm6ds3tr_c_int1_ctrl_t int1_ctrl;
  2273. lsm6ds3tr_c_md1_cfg_t md1_cfg;
  2274. lsm6ds3tr_c_md2_cfg_t md2_cfg;
  2275. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  2276. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  2277. int32_t ret;
  2278. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_INT1_CTRL,
  2279. (uint8_t *)&int1_ctrl, 1);
  2280. if (ret == 0)
  2281. {
  2282. int1_ctrl.int1_drdy_xl = val.int1_drdy_xl;
  2283. int1_ctrl.int1_drdy_g = val.int1_drdy_g;
  2284. int1_ctrl.int1_boot = val.int1_boot;
  2285. int1_ctrl.int1_fth = val.int1_fth;
  2286. int1_ctrl.int1_fifo_ovr = val.int1_fifo_ovr;
  2287. int1_ctrl.int1_full_flag = val.int1_full_flag;
  2288. int1_ctrl.int1_sign_mot = val.int1_sign_mot;
  2289. int1_ctrl.int1_step_detector = val.int1_step_detector;
  2290. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_INT1_CTRL,
  2291. (uint8_t *)&int1_ctrl, 1);
  2292. }
  2293. if (ret == 0)
  2294. {
  2295. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MD1_CFG,
  2296. (uint8_t *)&md1_cfg, 1);
  2297. }
  2298. if (ret == 0)
  2299. {
  2300. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MD2_CFG,
  2301. (uint8_t *)&md2_cfg, 1);
  2302. }
  2303. if (ret == 0)
  2304. {
  2305. md1_cfg.int1_timer = val.int1_timer;
  2306. md1_cfg.int1_tilt = val.int1_tilt;
  2307. md1_cfg.int1_6d = val.int1_6d;
  2308. md1_cfg.int1_double_tap = val.int1_double_tap;
  2309. md1_cfg.int1_ff = val.int1_ff;
  2310. md1_cfg.int1_wu = val.int1_wu;
  2311. md1_cfg.int1_single_tap = val.int1_single_tap;
  2312. md1_cfg.int1_inact_state = val.int1_inact_state;
  2313. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MD1_CFG,
  2314. (uint8_t *)&md1_cfg, 1);
  2315. }
  2316. if (ret == 0)
  2317. {
  2318. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2319. (uint8_t *)&ctrl4_c, 1);
  2320. }
  2321. if (ret == 0)
  2322. {
  2323. ctrl4_c.den_drdy_int1 = val.den_drdy_int1;
  2324. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2325. (uint8_t *)&ctrl4_c, 1);
  2326. }
  2327. if (ret == 0)
  2328. {
  2329. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  2330. (uint8_t *)&master_config, 1);
  2331. }
  2332. if (ret == 0)
  2333. {
  2334. master_config.drdy_on_int1 = val.den_drdy_int1;
  2335. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  2336. (uint8_t *)&master_config, 1);
  2337. }
  2338. if (ret == 0)
  2339. {
  2340. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  2341. (uint8_t *)&tap_cfg, 1);
  2342. if ((val.int1_6d != 0x00U) ||
  2343. (val.int1_ff != 0x00U) ||
  2344. (val.int1_wu != 0x00U) ||
  2345. (val.int1_single_tap != 0x00U) ||
  2346. (val.int1_double_tap != 0x00U) ||
  2347. (val.int1_inact_state != 0x00U) ||
  2348. (md2_cfg.int2_6d != 0x00U) ||
  2349. (md2_cfg.int2_ff != 0x00U) ||
  2350. (md2_cfg.int2_wu != 0x00U) ||
  2351. (md2_cfg.int2_single_tap != 0x00U) ||
  2352. (md2_cfg.int2_double_tap != 0x00U) ||
  2353. (md2_cfg.int2_inact_state != 0x00U))
  2354. {
  2355. tap_cfg.interrupts_enable = PROPERTY_ENABLE;
  2356. }
  2357. else
  2358. {
  2359. tap_cfg.interrupts_enable = PROPERTY_DISABLE;
  2360. }
  2361. }
  2362. if (ret == 0)
  2363. {
  2364. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  2365. (uint8_t *)&tap_cfg, 1);
  2366. }
  2367. return ret;
  2368. }
  2369. /**
  2370. * @brief Select the signal that need to route on int1 pad[get]
  2371. *
  2372. * @param ctx Read / write interface definitions
  2373. * @param val read INT1_CTRL, MD1_CFG, CTRL4_C(den_drdy_int1),
  2374. * MASTER_CONFIG(drdy_on_int1)
  2375. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2376. *
  2377. */
  2378. int32_t lsm6ds3tr_c_pin_int1_route_get(stmdev_ctx_t *ctx,
  2379. lsm6ds3tr_c_int1_route_t *val)
  2380. {
  2381. lsm6ds3tr_c_master_config_t master_config;
  2382. lsm6ds3tr_c_int1_ctrl_t int1_ctrl;
  2383. lsm6ds3tr_c_md1_cfg_t md1_cfg;
  2384. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  2385. int32_t ret;
  2386. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_INT1_CTRL,
  2387. (uint8_t *)&int1_ctrl, 1);
  2388. if (ret == 0)
  2389. {
  2390. val->int1_drdy_xl = int1_ctrl.int1_drdy_xl;
  2391. val->int1_drdy_g = int1_ctrl.int1_drdy_g;
  2392. val->int1_boot = int1_ctrl.int1_boot;
  2393. val->int1_fth = int1_ctrl.int1_fth;
  2394. val->int1_fifo_ovr = int1_ctrl.int1_fifo_ovr;
  2395. val->int1_full_flag = int1_ctrl.int1_full_flag;
  2396. val->int1_sign_mot = int1_ctrl.int1_sign_mot;
  2397. val->int1_step_detector = int1_ctrl.int1_step_detector ;
  2398. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MD1_CFG,
  2399. (uint8_t *)&md1_cfg, 1);
  2400. if (ret == 0)
  2401. {
  2402. val->int1_timer = md1_cfg.int1_timer;
  2403. val->int1_tilt = md1_cfg.int1_tilt;
  2404. val->int1_6d = md1_cfg.int1_6d;
  2405. val->int1_double_tap = md1_cfg.int1_double_tap;
  2406. val->int1_ff = md1_cfg.int1_ff;
  2407. val->int1_wu = md1_cfg.int1_wu;
  2408. val->int1_single_tap = md1_cfg.int1_single_tap;
  2409. val->int1_inact_state = md1_cfg.int1_inact_state;
  2410. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2411. (uint8_t *)&ctrl4_c, 1);
  2412. if (ret == 0)
  2413. {
  2414. val->den_drdy_int1 = ctrl4_c.den_drdy_int1;
  2415. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  2416. (uint8_t *)&master_config, 1);
  2417. val->den_drdy_int1 = master_config.drdy_on_int1;
  2418. }
  2419. }
  2420. }
  2421. return ret;
  2422. }
  2423. /**
  2424. * @brief Select the signal that need to route on int2 pad[set]
  2425. *
  2426. * @param ctx Read / write interface definitions
  2427. * @param val INT2_CTRL, DRDY_PULSE_CFG(int2_wrist_tilt), MD2_CFG
  2428. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2429. *
  2430. */
  2431. int32_t lsm6ds3tr_c_pin_int2_route_set(stmdev_ctx_t *ctx,
  2432. lsm6ds3tr_c_int2_route_t val)
  2433. {
  2434. lsm6ds3tr_c_int2_ctrl_t int2_ctrl;
  2435. lsm6ds3tr_c_md1_cfg_t md1_cfg;
  2436. lsm6ds3tr_c_md2_cfg_t md2_cfg;
  2437. lsm6ds3tr_c_drdy_pulse_cfg_g_t drdy_pulse_cfg_g;
  2438. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  2439. int32_t ret;
  2440. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_INT2_CTRL,
  2441. (uint8_t *)&int2_ctrl, 1);
  2442. if (ret == 0)
  2443. {
  2444. int2_ctrl.int2_drdy_xl = val.int2_drdy_xl;
  2445. int2_ctrl.int2_drdy_g = val.int2_drdy_g;
  2446. int2_ctrl.int2_drdy_temp = val.int2_drdy_temp;
  2447. int2_ctrl.int2_fth = val.int2_fth;
  2448. int2_ctrl.int2_fifo_ovr = val.int2_fifo_ovr;
  2449. int2_ctrl.int2_full_flag = val.int2_full_flag;
  2450. int2_ctrl.int2_step_count_ov = val.int2_step_count_ov;
  2451. int2_ctrl.int2_step_delta = val.int2_step_delta;
  2452. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_INT2_CTRL,
  2453. (uint8_t *)&int2_ctrl, 1);
  2454. }
  2455. if (ret == 0)
  2456. {
  2457. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MD1_CFG,
  2458. (uint8_t *)&md1_cfg, 1);
  2459. }
  2460. if (ret == 0)
  2461. {
  2462. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MD2_CFG,
  2463. (uint8_t *)&md2_cfg, 1);
  2464. }
  2465. if (ret == 0)
  2466. {
  2467. md2_cfg.int2_iron = val.int2_iron;
  2468. md2_cfg.int2_tilt = val.int2_tilt;
  2469. md2_cfg.int2_6d = val.int2_6d;
  2470. md2_cfg.int2_double_tap = val.int2_double_tap;
  2471. md2_cfg.int2_ff = val.int2_ff;
  2472. md2_cfg.int2_wu = val.int2_wu;
  2473. md2_cfg.int2_single_tap = val.int2_single_tap;
  2474. md2_cfg.int2_inact_state = val.int2_inact_state;
  2475. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MD2_CFG,
  2476. (uint8_t *)&md2_cfg, 1);
  2477. }
  2478. if (ret == 0)
  2479. {
  2480. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_DRDY_PULSE_CFG_G,
  2481. (uint8_t *)&drdy_pulse_cfg_g, 1);
  2482. }
  2483. if (ret == 0)
  2484. {
  2485. drdy_pulse_cfg_g.int2_wrist_tilt = val.int2_wrist_tilt;
  2486. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_DRDY_PULSE_CFG_G,
  2487. (uint8_t *)&drdy_pulse_cfg_g, 1);
  2488. }
  2489. if (ret == 0)
  2490. {
  2491. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  2492. (uint8_t *)&tap_cfg, 1);
  2493. if ((md1_cfg.int1_6d != 0x00U) ||
  2494. (md1_cfg.int1_ff != 0x00U) ||
  2495. (md1_cfg.int1_wu != 0x00U) ||
  2496. (md1_cfg.int1_single_tap != 0x00U) ||
  2497. (md1_cfg.int1_double_tap != 0x00U) ||
  2498. (md1_cfg.int1_inact_state != 0x00U) ||
  2499. (val.int2_6d != 0x00U) ||
  2500. (val.int2_ff != 0x00U) ||
  2501. (val.int2_wu != 0x00U) ||
  2502. (val.int2_single_tap != 0x00U) ||
  2503. (val.int2_double_tap != 0x00U) ||
  2504. (val.int2_inact_state != 0x00U))
  2505. {
  2506. tap_cfg.interrupts_enable = PROPERTY_ENABLE;
  2507. }
  2508. else
  2509. {
  2510. tap_cfg.interrupts_enable = PROPERTY_DISABLE;
  2511. }
  2512. }
  2513. if (ret == 0)
  2514. {
  2515. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  2516. (uint8_t *)&tap_cfg, 1);
  2517. }
  2518. return ret;
  2519. }
  2520. /**
  2521. * @brief Select the signal that need to route on int2 pad[get]
  2522. *
  2523. * @param ctx Read / write interface definitions
  2524. * @param val INT2_CTRL, DRDY_PULSE_CFG(int2_wrist_tilt), MD2_CFG
  2525. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2526. *
  2527. */
  2528. int32_t lsm6ds3tr_c_pin_int2_route_get(stmdev_ctx_t *ctx,
  2529. lsm6ds3tr_c_int2_route_t *val)
  2530. {
  2531. lsm6ds3tr_c_int2_ctrl_t int2_ctrl;
  2532. lsm6ds3tr_c_md2_cfg_t md2_cfg;
  2533. lsm6ds3tr_c_drdy_pulse_cfg_g_t drdy_pulse_cfg_g;
  2534. int32_t ret;
  2535. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_INT2_CTRL,
  2536. (uint8_t *)&int2_ctrl, 1);
  2537. if (ret == 0)
  2538. {
  2539. val->int2_drdy_xl = int2_ctrl.int2_drdy_xl;
  2540. val->int2_drdy_g = int2_ctrl.int2_drdy_g;
  2541. val->int2_drdy_temp = int2_ctrl.int2_drdy_temp;
  2542. val->int2_fth = int2_ctrl.int2_fth;
  2543. val->int2_fifo_ovr = int2_ctrl.int2_fifo_ovr;
  2544. val->int2_full_flag = int2_ctrl.int2_full_flag;
  2545. val->int2_step_count_ov = int2_ctrl.int2_step_count_ov;
  2546. val->int2_step_delta = int2_ctrl.int2_step_delta;
  2547. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MD2_CFG,
  2548. (uint8_t *)&md2_cfg, 1);
  2549. if (ret == 0)
  2550. {
  2551. val->int2_iron = md2_cfg.int2_iron;
  2552. val->int2_tilt = md2_cfg.int2_tilt;
  2553. val->int2_6d = md2_cfg.int2_6d;
  2554. val->int2_double_tap = md2_cfg.int2_double_tap;
  2555. val->int2_ff = md2_cfg.int2_ff;
  2556. val->int2_wu = md2_cfg.int2_wu;
  2557. val->int2_single_tap = md2_cfg.int2_single_tap;
  2558. val->int2_inact_state = md2_cfg.int2_inact_state;
  2559. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_DRDY_PULSE_CFG_G,
  2560. (uint8_t *)&drdy_pulse_cfg_g, 1);
  2561. val->int2_wrist_tilt = drdy_pulse_cfg_g.int2_wrist_tilt;
  2562. }
  2563. }
  2564. return ret;
  2565. }
  2566. /**
  2567. * @brief Push-pull/open drain selection on interrupt pads.[set]
  2568. *
  2569. * @param ctx Read / write interface definitions
  2570. * @param val Change the values of pp_od in reg CTRL3_C
  2571. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2572. *
  2573. */
  2574. int32_t lsm6ds3tr_c_pin_mode_set(stmdev_ctx_t *ctx,
  2575. lsm6ds3tr_c_pp_od_t val)
  2576. {
  2577. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  2578. int32_t ret;
  2579. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  2580. (uint8_t *)&ctrl3_c, 1);
  2581. if (ret == 0)
  2582. {
  2583. ctrl3_c.pp_od = (uint8_t) val;
  2584. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  2585. (uint8_t *)&ctrl3_c, 1);
  2586. }
  2587. return ret;
  2588. }
  2589. /**
  2590. * @brief Push-pull/open drain selection on interrupt pads.[get]
  2591. *
  2592. * @param ctx Read / write interface definitions
  2593. * @param val Get the values of pp_od in reg CTRL3_C
  2594. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2595. *
  2596. */
  2597. int32_t lsm6ds3tr_c_pin_mode_get(stmdev_ctx_t *ctx,
  2598. lsm6ds3tr_c_pp_od_t *val)
  2599. {
  2600. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  2601. int32_t ret;
  2602. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  2603. (uint8_t *)&ctrl3_c, 1);
  2604. switch (ctrl3_c.pp_od)
  2605. {
  2606. case LSM6DS3TR_C_PUSH_PULL:
  2607. *val = LSM6DS3TR_C_PUSH_PULL;
  2608. break;
  2609. case LSM6DS3TR_C_OPEN_DRAIN:
  2610. *val = LSM6DS3TR_C_OPEN_DRAIN;
  2611. break;
  2612. default:
  2613. *val = LSM6DS3TR_C_PIN_MODE_ND;
  2614. break;
  2615. }
  2616. return ret;
  2617. }
  2618. /**
  2619. * @brief Interrupt active-high/low.[set]
  2620. *
  2621. * @param ctx Read / write interface definitions
  2622. * @param val Change the values of h_lactive in reg CTRL3_C
  2623. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2624. *
  2625. */
  2626. int32_t lsm6ds3tr_c_pin_polarity_set(stmdev_ctx_t *ctx,
  2627. lsm6ds3tr_c_h_lactive_t val)
  2628. {
  2629. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  2630. int32_t ret;
  2631. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  2632. (uint8_t *)&ctrl3_c, 1);
  2633. if (ret == 0)
  2634. {
  2635. ctrl3_c.h_lactive = (uint8_t) val;
  2636. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  2637. (uint8_t *)&ctrl3_c, 1);
  2638. }
  2639. return ret;
  2640. }
  2641. /**
  2642. * @brief Interrupt active-high/low.[get]
  2643. *
  2644. * @param ctx Read / write interface definitions
  2645. * @param val Get the values of h_lactive in reg CTRL3_C
  2646. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2647. *
  2648. */
  2649. int32_t lsm6ds3tr_c_pin_polarity_get(stmdev_ctx_t *ctx,
  2650. lsm6ds3tr_c_h_lactive_t *val)
  2651. {
  2652. lsm6ds3tr_c_ctrl3_c_t ctrl3_c;
  2653. int32_t ret;
  2654. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL3_C,
  2655. (uint8_t *)&ctrl3_c, 1);
  2656. switch (ctrl3_c.h_lactive)
  2657. {
  2658. case LSM6DS3TR_C_ACTIVE_HIGH:
  2659. *val = LSM6DS3TR_C_ACTIVE_HIGH;
  2660. break;
  2661. case LSM6DS3TR_C_ACTIVE_LOW:
  2662. *val = LSM6DS3TR_C_ACTIVE_LOW;
  2663. break;
  2664. default:
  2665. *val = LSM6DS3TR_C_POLARITY_ND;
  2666. break;
  2667. }
  2668. return ret;
  2669. }
  2670. /**
  2671. * @brief All interrupt signals become available on INT1 pin.[set]
  2672. *
  2673. * @param ctx Read / write interface definitions
  2674. * @param val Change the values of int2_on_int1 in reg CTRL4_C
  2675. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2676. *
  2677. */
  2678. int32_t lsm6ds3tr_c_all_on_int1_set(stmdev_ctx_t *ctx, uint8_t val)
  2679. {
  2680. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  2681. int32_t ret;
  2682. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2683. (uint8_t *)&ctrl4_c, 1);
  2684. if (ret == 0)
  2685. {
  2686. ctrl4_c.int2_on_int1 = val;
  2687. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2688. (uint8_t *)&ctrl4_c, 1);
  2689. }
  2690. return ret;
  2691. }
  2692. /**
  2693. * @brief All interrupt signals become available on INT1 pin.[get]
  2694. *
  2695. * @param ctx Read / write interface definitions
  2696. * @param val Change the values of int2_on_int1 in reg CTRL4_C
  2697. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2698. *
  2699. */
  2700. int32_t lsm6ds3tr_c_all_on_int1_get(stmdev_ctx_t *ctx, uint8_t *val)
  2701. {
  2702. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  2703. int32_t ret;
  2704. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2705. (uint8_t *)&ctrl4_c, 1);
  2706. *val = ctrl4_c.int2_on_int1;
  2707. return ret;
  2708. }
  2709. /**
  2710. * @brief Latched/pulsed interrupt.[set]
  2711. *
  2712. * @param ctx Read / write interface definitions
  2713. * @param val Change the values of lir in reg TAP_CFG
  2714. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2715. *
  2716. */
  2717. int32_t lsm6ds3tr_c_int_notification_set(stmdev_ctx_t *ctx,
  2718. lsm6ds3tr_c_lir_t val)
  2719. {
  2720. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  2721. int32_t ret;
  2722. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  2723. (uint8_t *)&tap_cfg, 1);
  2724. if (ret == 0)
  2725. {
  2726. tap_cfg.lir = (uint8_t) val;
  2727. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  2728. (uint8_t *)&tap_cfg, 1);
  2729. }
  2730. return ret;
  2731. }
  2732. /**
  2733. * @brief Latched/pulsed interrupt.[get]
  2734. *
  2735. * @param ctx Read / write interface definitions
  2736. * @param val Get the values of lir in reg TAP_CFG
  2737. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2738. *
  2739. */
  2740. int32_t lsm6ds3tr_c_int_notification_get(stmdev_ctx_t *ctx,
  2741. lsm6ds3tr_c_lir_t *val)
  2742. {
  2743. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  2744. int32_t ret;
  2745. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  2746. (uint8_t *)&tap_cfg, 1);
  2747. switch (tap_cfg.lir)
  2748. {
  2749. case LSM6DS3TR_C_INT_PULSED:
  2750. *val = LSM6DS3TR_C_INT_PULSED;
  2751. break;
  2752. case LSM6DS3TR_C_INT_LATCHED:
  2753. *val = LSM6DS3TR_C_INT_LATCHED;
  2754. break;
  2755. default:
  2756. *val = LSM6DS3TR_C_INT_MODE;
  2757. break;
  2758. }
  2759. return ret;
  2760. }
  2761. /**
  2762. * @}
  2763. *
  2764. */
  2765. /**
  2766. * @defgroup LSM6DS3TR_C_Wake_Up_event
  2767. * @brief This section groups all the functions that manage the
  2768. * Wake Up event generation.
  2769. * @{
  2770. *
  2771. */
  2772. /**
  2773. * @brief Threshold for wakeup.1 LSB = FS_XL / 64.[set]
  2774. *
  2775. * @param ctx Read / write interface definitions
  2776. * @param val Change the values of wk_ths in reg WAKE_UP_THS
  2777. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2778. *
  2779. */
  2780. int32_t lsm6ds3tr_c_wkup_threshold_set(stmdev_ctx_t *ctx, uint8_t val)
  2781. {
  2782. lsm6ds3tr_c_wake_up_ths_t wake_up_ths;
  2783. int32_t ret;
  2784. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_THS,
  2785. (uint8_t *)&wake_up_ths, 1);
  2786. if (ret == 0)
  2787. {
  2788. wake_up_ths.wk_ths = val;
  2789. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_WAKE_UP_THS,
  2790. (uint8_t *)&wake_up_ths, 1);
  2791. }
  2792. return ret;
  2793. }
  2794. /**
  2795. * @brief Threshold for wakeup.1 LSB = FS_XL / 64.[get]
  2796. *
  2797. * @param ctx Read / write interface definitions
  2798. * @param val Change the values of wk_ths in reg WAKE_UP_THS
  2799. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2800. *
  2801. */
  2802. int32_t lsm6ds3tr_c_wkup_threshold_get(stmdev_ctx_t *ctx,
  2803. uint8_t *val)
  2804. {
  2805. lsm6ds3tr_c_wake_up_ths_t wake_up_ths;
  2806. int32_t ret;
  2807. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_THS,
  2808. (uint8_t *)&wake_up_ths, 1);
  2809. *val = wake_up_ths.wk_ths;
  2810. return ret;
  2811. }
  2812. /**
  2813. * @brief Wake up duration event.1LSb = 1 / ODR[set]
  2814. *
  2815. * @param ctx Read / write interface definitions
  2816. * @param val Change the values of wake_dur in reg WAKE_UP_DUR
  2817. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2818. *
  2819. */
  2820. int32_t lsm6ds3tr_c_wkup_dur_set(stmdev_ctx_t *ctx, uint8_t val)
  2821. {
  2822. lsm6ds3tr_c_wake_up_dur_t wake_up_dur;
  2823. int32_t ret;
  2824. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  2825. (uint8_t *)&wake_up_dur, 1);
  2826. if (ret == 0)
  2827. {
  2828. wake_up_dur.wake_dur = val;
  2829. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  2830. (uint8_t *)&wake_up_dur, 1);
  2831. }
  2832. return ret;
  2833. }
  2834. /**
  2835. * @brief Wake up duration event.1LSb = 1 / ODR[get]
  2836. *
  2837. * @param ctx Read / write interface definitions
  2838. * @param val Change the values of wake_dur in reg WAKE_UP_DUR
  2839. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2840. *
  2841. */
  2842. int32_t lsm6ds3tr_c_wkup_dur_get(stmdev_ctx_t *ctx, uint8_t *val)
  2843. {
  2844. lsm6ds3tr_c_wake_up_dur_t wake_up_dur;
  2845. int32_t ret;
  2846. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  2847. (uint8_t *)&wake_up_dur, 1);
  2848. *val = wake_up_dur.wake_dur;
  2849. return ret;
  2850. }
  2851. /**
  2852. * @}
  2853. *
  2854. */
  2855. /**
  2856. * @defgroup LSM6DS3TR_C_Activity/Inactivity_detection
  2857. * @brief This section groups all the functions concerning
  2858. * activity/inactivity detection.
  2859. * @{
  2860. *
  2861. */
  2862. /**
  2863. * @brief Enables gyroscope Sleep mode.[set]
  2864. *
  2865. * @param ctx Read / write interface definitions
  2866. * @param val Change the values of sleep in reg CTRL4_C
  2867. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2868. *
  2869. */
  2870. int32_t lsm6ds3tr_c_gy_sleep_mode_set(stmdev_ctx_t *ctx, uint8_t val)
  2871. {
  2872. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  2873. int32_t ret;
  2874. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2875. (uint8_t *)&ctrl4_c, 1);
  2876. if (ret == 0)
  2877. {
  2878. ctrl4_c.sleep = val;
  2879. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2880. (uint8_t *)&ctrl4_c, 1);
  2881. }
  2882. return ret;
  2883. }
  2884. /**
  2885. * @brief Enables gyroscope Sleep mode.[get]
  2886. *
  2887. * @param ctx Read / write interface definitions
  2888. * @param val Change the values of sleep in reg CTRL4_C
  2889. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2890. *
  2891. */
  2892. int32_t lsm6ds3tr_c_gy_sleep_mode_get(stmdev_ctx_t *ctx, uint8_t *val)
  2893. {
  2894. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  2895. int32_t ret;
  2896. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  2897. (uint8_t *)&ctrl4_c, 1);
  2898. *val = ctrl4_c.sleep;
  2899. return ret;
  2900. }
  2901. /**
  2902. * @brief Enable inactivity function.[set]
  2903. *
  2904. * @param ctx Read / write interface definitions
  2905. * @param val Change the values of inact_en in reg TAP_CFG
  2906. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2907. *
  2908. */
  2909. int32_t lsm6ds3tr_c_act_mode_set(stmdev_ctx_t *ctx,
  2910. lsm6ds3tr_c_inact_en_t val)
  2911. {
  2912. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  2913. int32_t ret;
  2914. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  2915. (uint8_t *)&tap_cfg, 1);
  2916. if (ret == 0)
  2917. {
  2918. tap_cfg.inact_en = (uint8_t) val;
  2919. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  2920. (uint8_t *)&tap_cfg, 1);
  2921. }
  2922. return ret;
  2923. }
  2924. /**
  2925. * @brief Enable inactivity function.[get]
  2926. *
  2927. * @param ctx Read / write interface definitions
  2928. * @param val Get the values of inact_en in reg TAP_CFG
  2929. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2930. *
  2931. */
  2932. int32_t lsm6ds3tr_c_act_mode_get(stmdev_ctx_t *ctx,
  2933. lsm6ds3tr_c_inact_en_t *val)
  2934. {
  2935. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  2936. int32_t ret;
  2937. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  2938. (uint8_t *)&tap_cfg, 1);
  2939. switch (tap_cfg.inact_en)
  2940. {
  2941. case LSM6DS3TR_C_PROPERTY_DISABLE:
  2942. *val = LSM6DS3TR_C_PROPERTY_DISABLE;
  2943. break;
  2944. case LSM6DS3TR_C_XL_12Hz5_GY_NOT_AFFECTED:
  2945. *val = LSM6DS3TR_C_XL_12Hz5_GY_NOT_AFFECTED;
  2946. break;
  2947. case LSM6DS3TR_C_XL_12Hz5_GY_SLEEP:
  2948. *val = LSM6DS3TR_C_XL_12Hz5_GY_SLEEP;
  2949. break;
  2950. case LSM6DS3TR_C_XL_12Hz5_GY_PD:
  2951. *val = LSM6DS3TR_C_XL_12Hz5_GY_PD;
  2952. break;
  2953. default:
  2954. *val = LSM6DS3TR_C_ACT_MODE_ND;
  2955. break;
  2956. }
  2957. return ret;
  2958. }
  2959. /**
  2960. * @brief Duration to go in sleep mode.1 LSb = 512 / ODR[set]
  2961. *
  2962. * @param ctx Read / write interface definitions
  2963. * @param val Change the values of sleep_dur in reg WAKE_UP_DUR
  2964. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2965. *
  2966. */
  2967. int32_t lsm6ds3tr_c_act_sleep_dur_set(stmdev_ctx_t *ctx, uint8_t val)
  2968. {
  2969. lsm6ds3tr_c_wake_up_dur_t wake_up_dur;
  2970. int32_t ret;
  2971. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  2972. (uint8_t *)&wake_up_dur, 1);
  2973. if (ret == 0)
  2974. {
  2975. wake_up_dur.sleep_dur = val;
  2976. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  2977. (uint8_t *)&wake_up_dur, 1);
  2978. }
  2979. return ret;
  2980. }
  2981. /**
  2982. * @brief Duration to go in sleep mode. 1 LSb = 512 / ODR[get]
  2983. *
  2984. * @param ctx Read / write interface definitions
  2985. * @param val Change the values of sleep_dur in reg WAKE_UP_DUR
  2986. * @retval Interface status (MANDATORY: return 0 -> no Error).
  2987. *
  2988. */
  2989. int32_t lsm6ds3tr_c_act_sleep_dur_get(stmdev_ctx_t *ctx, uint8_t *val)
  2990. {
  2991. lsm6ds3tr_c_wake_up_dur_t wake_up_dur;
  2992. int32_t ret;
  2993. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  2994. (uint8_t *)&wake_up_dur, 1);
  2995. *val = wake_up_dur.sleep_dur;
  2996. return ret;
  2997. }
  2998. /**
  2999. * @}
  3000. *
  3001. */
  3002. /**
  3003. * @defgroup LSM6DS3TR_C_tap_generator
  3004. * @brief This section groups all the functions that manage the
  3005. * tap and double tap event generation.
  3006. * @{
  3007. *
  3008. */
  3009. /**
  3010. * @brief Read the tap / double tap source register.[get]
  3011. *
  3012. * @param ctx Read / write interface definitions
  3013. * @param val Structure of registers from TAP_SRC
  3014. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3015. *
  3016. */
  3017. int32_t lsm6ds3tr_c_tap_src_get(stmdev_ctx_t *ctx,
  3018. lsm6ds3tr_c_tap_src_t *val)
  3019. {
  3020. int32_t ret;
  3021. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_SRC, (uint8_t *) val, 1);
  3022. return ret;
  3023. }
  3024. /**
  3025. * @brief Enable Z direction in tap recognition.[set]
  3026. *
  3027. * @param ctx Read / write interface definitions
  3028. * @param val Change the values of tap_z_en in reg TAP_CFG
  3029. *
  3030. */
  3031. int32_t lsm6ds3tr_c_tap_detection_on_z_set(stmdev_ctx_t *ctx,
  3032. uint8_t val)
  3033. {
  3034. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  3035. int32_t ret;
  3036. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  3037. (uint8_t *)&tap_cfg, 1);
  3038. if (ret == 0)
  3039. {
  3040. tap_cfg.tap_z_en = val;
  3041. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  3042. (uint8_t *)&tap_cfg, 1);
  3043. }
  3044. return ret;
  3045. }
  3046. /**
  3047. * @brief Enable Z direction in tap recognition.[get]
  3048. *
  3049. * @param ctx Read / write interface definitions
  3050. * @param val Change the values of tap_z_en in reg TAP_CFG
  3051. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3052. *
  3053. */
  3054. int32_t lsm6ds3tr_c_tap_detection_on_z_get(stmdev_ctx_t *ctx,
  3055. uint8_t *val)
  3056. {
  3057. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  3058. int32_t ret;
  3059. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  3060. (uint8_t *)&tap_cfg, 1);
  3061. *val = tap_cfg.tap_z_en;
  3062. return ret;
  3063. }
  3064. /**
  3065. * @brief Enable Y direction in tap recognition.[set]
  3066. *
  3067. * @param ctx Read / write interface definitions
  3068. * @param val Change the values of tap_y_en in reg TAP_CFG
  3069. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3070. *
  3071. */
  3072. int32_t lsm6ds3tr_c_tap_detection_on_y_set(stmdev_ctx_t *ctx,
  3073. uint8_t val)
  3074. {
  3075. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  3076. int32_t ret;
  3077. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  3078. (uint8_t *)&tap_cfg, 1);
  3079. if (ret == 0)
  3080. {
  3081. tap_cfg.tap_y_en = val;
  3082. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  3083. (uint8_t *)&tap_cfg, 1);
  3084. }
  3085. return ret;
  3086. }
  3087. /**
  3088. * @brief Enable Y direction in tap recognition.[get]
  3089. *
  3090. * @param ctx Read / write interface definitions
  3091. * @param val Change the values of tap_y_en in reg TAP_CFG
  3092. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3093. *
  3094. */
  3095. int32_t lsm6ds3tr_c_tap_detection_on_y_get(stmdev_ctx_t *ctx,
  3096. uint8_t *val)
  3097. {
  3098. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  3099. int32_t ret;
  3100. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  3101. (uint8_t *)&tap_cfg, 1);
  3102. *val = tap_cfg.tap_y_en;
  3103. return ret;
  3104. }
  3105. /**
  3106. * @brief Enable X direction in tap recognition.[set]
  3107. *
  3108. * @param ctx Read / write interface definitions
  3109. * @param val Change the values of tap_x_en in reg TAP_CFG
  3110. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3111. *
  3112. */
  3113. int32_t lsm6ds3tr_c_tap_detection_on_x_set(stmdev_ctx_t *ctx,
  3114. uint8_t val)
  3115. {
  3116. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  3117. int32_t ret;
  3118. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  3119. (uint8_t *)&tap_cfg, 1);
  3120. if (ret == 0)
  3121. {
  3122. tap_cfg.tap_x_en = val;
  3123. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  3124. (uint8_t *)&tap_cfg, 1);
  3125. }
  3126. return ret;
  3127. }
  3128. /**
  3129. * @brief Enable X direction in tap recognition.[get]
  3130. *
  3131. * @param ctx Read / write interface definitions
  3132. * @param val Change the values of tap_x_en in reg TAP_CFG
  3133. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3134. *
  3135. */
  3136. int32_t lsm6ds3tr_c_tap_detection_on_x_get(stmdev_ctx_t *ctx,
  3137. uint8_t *val)
  3138. {
  3139. lsm6ds3tr_c_tap_cfg_t tap_cfg;
  3140. int32_t ret;
  3141. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_CFG,
  3142. (uint8_t *)&tap_cfg, 1);
  3143. *val = tap_cfg.tap_x_en;
  3144. return ret;
  3145. }
  3146. /**
  3147. * @brief Threshold for tap recognition.[set]
  3148. *
  3149. * @param ctx Read / write interface definitions
  3150. * @param val Change the values of tap_ths in reg TAP_THS_6D
  3151. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3152. *
  3153. */
  3154. int32_t lsm6ds3tr_c_tap_threshold_x_set(stmdev_ctx_t *ctx,
  3155. uint8_t val)
  3156. {
  3157. lsm6ds3tr_c_tap_ths_6d_t tap_ths_6d;
  3158. int32_t ret;
  3159. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_THS_6D,
  3160. (uint8_t *)&tap_ths_6d, 1);
  3161. if (ret == 0)
  3162. {
  3163. tap_ths_6d.tap_ths = val;
  3164. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_TAP_THS_6D,
  3165. (uint8_t *)&tap_ths_6d, 1);
  3166. }
  3167. return ret;
  3168. }
  3169. /**
  3170. * @brief Threshold for tap recognition.[get]
  3171. *
  3172. * @param ctx Read / write interface definitions
  3173. * @param val Change the values of tap_ths in reg TAP_THS_6D
  3174. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3175. *
  3176. */
  3177. int32_t lsm6ds3tr_c_tap_threshold_x_get(stmdev_ctx_t *ctx,
  3178. uint8_t *val)
  3179. {
  3180. lsm6ds3tr_c_tap_ths_6d_t tap_ths_6d;
  3181. int32_t ret;
  3182. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_THS_6D,
  3183. (uint8_t *)&tap_ths_6d, 1);
  3184. *val = tap_ths_6d.tap_ths;
  3185. return ret;
  3186. }
  3187. /**
  3188. * @brief Maximum duration is the maximum time of an overthreshold signal
  3189. * detection to be recognized as a tap event.
  3190. * The default value of these bits is 00b which corresponds to
  3191. * 4*ODR_XL time.
  3192. * If the SHOCK[1:0] bits are set to a different
  3193. * value, 1LSB corresponds to 8*ODR_XL time.[set]
  3194. *
  3195. * @param ctx Read / write interface definitions
  3196. * @param val Change the values of shock in reg INT_DUR2
  3197. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3198. *
  3199. */
  3200. int32_t lsm6ds3tr_c_tap_shock_set(stmdev_ctx_t *ctx, uint8_t val)
  3201. {
  3202. lsm6ds3tr_c_int_dur2_t int_dur2;
  3203. int32_t ret;
  3204. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_INT_DUR2,
  3205. (uint8_t *)&int_dur2, 1);
  3206. if (ret == 0)
  3207. {
  3208. int_dur2.shock = val;
  3209. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_INT_DUR2,
  3210. (uint8_t *)&int_dur2, 1);
  3211. }
  3212. return ret;
  3213. }
  3214. /**
  3215. * @brief Maximum duration is the maximum time of an overthreshold signal
  3216. * detection to be recognized as a tap event.
  3217. * The default value of these bits is 00b which corresponds to
  3218. * 4*ODR_XL time.
  3219. * If the SHOCK[1:0] bits are set to a different value, 1LSB
  3220. * corresponds to 8*ODR_XL time.[get]
  3221. *
  3222. * @param ctx Read / write interface definitions
  3223. * @param val Change the values of shock in reg INT_DUR2
  3224. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3225. *
  3226. */
  3227. int32_t lsm6ds3tr_c_tap_shock_get(stmdev_ctx_t *ctx, uint8_t *val)
  3228. {
  3229. lsm6ds3tr_c_int_dur2_t int_dur2;
  3230. int32_t ret;
  3231. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_INT_DUR2,
  3232. (uint8_t *)&int_dur2, 1);
  3233. *val = int_dur2.shock;
  3234. return ret;
  3235. }
  3236. /**
  3237. * @brief Quiet time is the time after the first detected tap in which there
  3238. * must not be any overthreshold event.
  3239. * The default value of these bits is 00b which corresponds to
  3240. * 2*ODR_XL time.
  3241. * If the QUIET[1:0] bits are set to a different value, 1LSB
  3242. * corresponds to 4*ODR_XL time.[set]
  3243. *
  3244. * @param ctx Read / write interface definitions
  3245. * @param val Change the values of quiet in reg INT_DUR2
  3246. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3247. *
  3248. */
  3249. int32_t lsm6ds3tr_c_tap_quiet_set(stmdev_ctx_t *ctx, uint8_t val)
  3250. {
  3251. lsm6ds3tr_c_int_dur2_t int_dur2;
  3252. int32_t ret;
  3253. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_INT_DUR2,
  3254. (uint8_t *)&int_dur2, 1);
  3255. if (ret == 0)
  3256. {
  3257. int_dur2.quiet = val;
  3258. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_INT_DUR2,
  3259. (uint8_t *)&int_dur2, 1);
  3260. }
  3261. return ret;
  3262. }
  3263. /**
  3264. * @brief Quiet time is the time after the first detected tap in which there
  3265. * must not be any overthreshold event.
  3266. * The default value of these bits is 00b which corresponds to
  3267. * 2*ODR_XL time.
  3268. * If the QUIET[1:0] bits are set to a different value, 1LSB
  3269. * corresponds to 4*ODR_XL time.[get]
  3270. *
  3271. * @param ctx Read / write interface definitions
  3272. * @param val Change the values of quiet in reg INT_DUR2
  3273. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3274. *
  3275. */
  3276. int32_t lsm6ds3tr_c_tap_quiet_get(stmdev_ctx_t *ctx, uint8_t *val)
  3277. {
  3278. lsm6ds3tr_c_int_dur2_t int_dur2;
  3279. int32_t ret;
  3280. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_INT_DUR2,
  3281. (uint8_t *)&int_dur2, 1);
  3282. *val = int_dur2.quiet;
  3283. return ret;
  3284. }
  3285. /**
  3286. * @brief When double tap recognition is enabled, this register expresses the
  3287. * maximum time between two consecutive detected taps to determine a
  3288. * double tap event.
  3289. * The default value of these bits is 0000b which corresponds to
  3290. * 16*ODR_XL time.
  3291. * If the DUR[3:0] bits are set to a different value,1LSB corresponds
  3292. * to 32*ODR_XL time.[set]
  3293. *
  3294. * @param ctx Read / write interface definitions
  3295. * @param val Change the values of dur in reg INT_DUR2
  3296. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3297. *
  3298. */
  3299. int32_t lsm6ds3tr_c_tap_dur_set(stmdev_ctx_t *ctx, uint8_t val)
  3300. {
  3301. lsm6ds3tr_c_int_dur2_t int_dur2;
  3302. int32_t ret;
  3303. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_INT_DUR2,
  3304. (uint8_t *)&int_dur2, 1);
  3305. if (ret == 0)
  3306. {
  3307. int_dur2.dur = val;
  3308. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_INT_DUR2,
  3309. (uint8_t *)&int_dur2, 1);
  3310. }
  3311. return ret;
  3312. }
  3313. /**
  3314. * @brief When double tap recognition is enabled, this register expresses the
  3315. * maximum time between two consecutive detected taps to determine a
  3316. * double tap event.
  3317. * The default value of these bits is 0000b which corresponds to
  3318. * 16*ODR_XL time.
  3319. * If the DUR[3:0] bits are set to a different value,1LSB corresponds
  3320. * to 32*ODR_XL time.[get]
  3321. *
  3322. * @param ctx Read / write interface definitions
  3323. * @param val Change the values of dur in reg INT_DUR2
  3324. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3325. *
  3326. */
  3327. int32_t lsm6ds3tr_c_tap_dur_get(stmdev_ctx_t *ctx, uint8_t *val)
  3328. {
  3329. lsm6ds3tr_c_int_dur2_t int_dur2;
  3330. int32_t ret;
  3331. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_INT_DUR2,
  3332. (uint8_t *)&int_dur2, 1);
  3333. *val = int_dur2.dur;
  3334. return ret;
  3335. }
  3336. /**
  3337. * @brief Single/double-tap event enable/disable.[set]
  3338. *
  3339. * @param ctx Read / write interface definitions
  3340. * @param val Change the values of
  3341. * single_double_tap in reg WAKE_UP_THS
  3342. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3343. *
  3344. */
  3345. int32_t lsm6ds3tr_c_tap_mode_set(stmdev_ctx_t *ctx,
  3346. lsm6ds3tr_c_single_double_tap_t val)
  3347. {
  3348. lsm6ds3tr_c_wake_up_ths_t wake_up_ths;
  3349. int32_t ret;
  3350. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_THS,
  3351. (uint8_t *)&wake_up_ths, 1);
  3352. if (ret == 0)
  3353. {
  3354. wake_up_ths.single_double_tap = (uint8_t) val;
  3355. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_WAKE_UP_THS,
  3356. (uint8_t *)&wake_up_ths, 1);
  3357. }
  3358. return ret;
  3359. }
  3360. /**
  3361. * @brief Single/double-tap event enable/disable.[get]
  3362. *
  3363. * @param ctx Read / write interface definitions
  3364. * @param val Get the values of single_double_tap
  3365. * in reg WAKE_UP_THS
  3366. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3367. *
  3368. */
  3369. int32_t lsm6ds3tr_c_tap_mode_get(stmdev_ctx_t *ctx,
  3370. lsm6ds3tr_c_single_double_tap_t *val)
  3371. {
  3372. lsm6ds3tr_c_wake_up_ths_t wake_up_ths;
  3373. int32_t ret;
  3374. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_THS,
  3375. (uint8_t *)&wake_up_ths, 1);
  3376. switch (wake_up_ths.single_double_tap)
  3377. {
  3378. case LSM6DS3TR_C_ONLY_SINGLE:
  3379. *val = LSM6DS3TR_C_ONLY_SINGLE;
  3380. break;
  3381. case LSM6DS3TR_C_BOTH_SINGLE_DOUBLE:
  3382. *val = LSM6DS3TR_C_BOTH_SINGLE_DOUBLE;
  3383. break;
  3384. default:
  3385. *val = LSM6DS3TR_C_TAP_MODE_ND;
  3386. break;
  3387. }
  3388. return ret;
  3389. }
  3390. /**
  3391. * @}
  3392. *
  3393. */
  3394. /**
  3395. * @defgroup LSM6DS3TR_C_ Six_position_detection(6D/4D)
  3396. * @brief This section groups all the functions concerning six
  3397. * position detection (6D).
  3398. * @{
  3399. *
  3400. */
  3401. /**
  3402. * @brief LPF2 feed 6D function selection.[set]
  3403. *
  3404. * @param ctx Read / write interface definitions
  3405. * @param val Change the values of low_pass_on_6d in
  3406. * reg CTRL8_XL
  3407. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3408. *
  3409. */
  3410. int32_t lsm6ds3tr_c_6d_feed_data_set(stmdev_ctx_t *ctx,
  3411. lsm6ds3tr_c_low_pass_on_6d_t val)
  3412. {
  3413. lsm6ds3tr_c_ctrl8_xl_t ctrl8_xl;
  3414. int32_t ret;
  3415. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  3416. (uint8_t *)&ctrl8_xl, 1);
  3417. if (ret == 0)
  3418. {
  3419. ctrl8_xl.low_pass_on_6d = (uint8_t) val;
  3420. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  3421. (uint8_t *)&ctrl8_xl, 1);
  3422. }
  3423. return ret;
  3424. }
  3425. /**
  3426. * @brief LPF2 feed 6D function selection.[get]
  3427. *
  3428. * @param ctx Read / write interface definitions
  3429. * @param val Get the values of low_pass_on_6d in reg CTRL8_XL
  3430. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3431. *
  3432. */
  3433. int32_t lsm6ds3tr_c_6d_feed_data_get(stmdev_ctx_t *ctx,
  3434. lsm6ds3tr_c_low_pass_on_6d_t *val)
  3435. {
  3436. lsm6ds3tr_c_ctrl8_xl_t ctrl8_xl;
  3437. int32_t ret;
  3438. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL8_XL,
  3439. (uint8_t *)&ctrl8_xl, 1);
  3440. switch (ctrl8_xl.low_pass_on_6d)
  3441. {
  3442. case LSM6DS3TR_C_ODR_DIV_2_FEED:
  3443. *val = LSM6DS3TR_C_ODR_DIV_2_FEED;
  3444. break;
  3445. case LSM6DS3TR_C_LPF2_FEED:
  3446. *val = LSM6DS3TR_C_LPF2_FEED;
  3447. break;
  3448. default:
  3449. *val = LSM6DS3TR_C_6D_FEED_ND;
  3450. break;
  3451. }
  3452. return ret;
  3453. }
  3454. /**
  3455. * @brief Threshold for 4D/6D function.[set]
  3456. *
  3457. * @param ctx Read / write interface definitions
  3458. * @param val Change the values of sixd_ths in reg TAP_THS_6D
  3459. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3460. *
  3461. */
  3462. int32_t lsm6ds3tr_c_6d_threshold_set(stmdev_ctx_t *ctx,
  3463. lsm6ds3tr_c_sixd_ths_t val)
  3464. {
  3465. lsm6ds3tr_c_tap_ths_6d_t tap_ths_6d;
  3466. int32_t ret;
  3467. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_THS_6D,
  3468. (uint8_t *)&tap_ths_6d, 1);
  3469. if (ret == 0)
  3470. {
  3471. tap_ths_6d.sixd_ths = (uint8_t) val;
  3472. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_TAP_THS_6D,
  3473. (uint8_t *)&tap_ths_6d, 1);
  3474. }
  3475. return ret;
  3476. }
  3477. /**
  3478. * @brief Threshold for 4D/6D function.[get]
  3479. *
  3480. * @param ctx Read / write interface definitions
  3481. * @param val Get the values of sixd_ths in reg TAP_THS_6D
  3482. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3483. *
  3484. */
  3485. int32_t lsm6ds3tr_c_6d_threshold_get(stmdev_ctx_t *ctx,
  3486. lsm6ds3tr_c_sixd_ths_t *val)
  3487. {
  3488. lsm6ds3tr_c_tap_ths_6d_t tap_ths_6d;
  3489. int32_t ret;
  3490. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_THS_6D,
  3491. (uint8_t *)&tap_ths_6d, 1);
  3492. switch (tap_ths_6d.sixd_ths)
  3493. {
  3494. case LSM6DS3TR_C_DEG_80:
  3495. *val = LSM6DS3TR_C_DEG_80;
  3496. break;
  3497. case LSM6DS3TR_C_DEG_70:
  3498. *val = LSM6DS3TR_C_DEG_70;
  3499. break;
  3500. case LSM6DS3TR_C_DEG_60:
  3501. *val = LSM6DS3TR_C_DEG_60;
  3502. break;
  3503. case LSM6DS3TR_C_DEG_50:
  3504. *val = LSM6DS3TR_C_DEG_50;
  3505. break;
  3506. default:
  3507. *val = LSM6DS3TR_C_6D_TH_ND;
  3508. break;
  3509. }
  3510. return ret;
  3511. }
  3512. /**
  3513. * @brief 4D orientation detection enable.[set]
  3514. *
  3515. * @param ctx Read / write interface definitions
  3516. * @param val Change the values of d4d_en in reg TAP_THS_6D
  3517. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3518. *
  3519. */
  3520. int32_t lsm6ds3tr_c_4d_mode_set(stmdev_ctx_t *ctx, uint8_t val)
  3521. {
  3522. lsm6ds3tr_c_tap_ths_6d_t tap_ths_6d;
  3523. int32_t ret;
  3524. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_THS_6D,
  3525. (uint8_t *)&tap_ths_6d, 1);
  3526. if (ret == 0)
  3527. {
  3528. tap_ths_6d.d4d_en = val;
  3529. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_TAP_THS_6D,
  3530. (uint8_t *)&tap_ths_6d, 1);
  3531. }
  3532. return ret;
  3533. }
  3534. /**
  3535. * @brief 4D orientation detection enable.[get]
  3536. *
  3537. * @param ctx Read / write interface definitions
  3538. * @param val Change the values of d4d_en in reg TAP_THS_6D
  3539. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3540. *
  3541. */
  3542. int32_t lsm6ds3tr_c_4d_mode_get(stmdev_ctx_t *ctx, uint8_t *val)
  3543. {
  3544. lsm6ds3tr_c_tap_ths_6d_t tap_ths_6d;
  3545. int32_t ret;
  3546. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_TAP_THS_6D,
  3547. (uint8_t *)&tap_ths_6d, 1);
  3548. *val = tap_ths_6d.d4d_en;
  3549. return ret;
  3550. }
  3551. /**
  3552. * @}
  3553. *
  3554. */
  3555. /**
  3556. * @defgroup LSM6DS3TR_C_free_fall
  3557. * @brief This section group all the functions concerning the free
  3558. * fall detection.
  3559. * @{
  3560. *
  3561. */
  3562. /**
  3563. * @brief Free-fall duration event. 1LSb = 1 / ODR[set]
  3564. *
  3565. * @param ctx Read / write interface definitions
  3566. * @param val Change the values of ff_dur in reg WAKE_UP_DUR
  3567. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3568. *
  3569. */
  3570. int32_t lsm6ds3tr_c_ff_dur_set(stmdev_ctx_t *ctx, uint8_t val)
  3571. {
  3572. lsm6ds3tr_c_wake_up_dur_t wake_up_dur;
  3573. lsm6ds3tr_c_free_fall_t free_fall;
  3574. int32_t ret;
  3575. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FREE_FALL,
  3576. (uint8_t *)&free_fall, 1);
  3577. if (ret == 0)
  3578. {
  3579. free_fall.ff_dur = (val & 0x1FU);
  3580. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FREE_FALL,
  3581. (uint8_t *)&free_fall, 1);
  3582. if (ret == 0)
  3583. {
  3584. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  3585. (uint8_t *)&wake_up_dur, 1);
  3586. if (ret == 0)
  3587. {
  3588. wake_up_dur.ff_dur = (val & 0x20U) >> 5;
  3589. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  3590. (uint8_t *)&wake_up_dur, 1);
  3591. }
  3592. }
  3593. }
  3594. return ret;
  3595. }
  3596. /**
  3597. * @brief Free-fall duration event. 1LSb = 1 / ODR[get]
  3598. *
  3599. * @param ctx Read / write interface definitions
  3600. * @param val Change the values of ff_dur in reg WAKE_UP_DUR
  3601. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3602. *
  3603. */
  3604. int32_t lsm6ds3tr_c_ff_dur_get(stmdev_ctx_t *ctx, uint8_t *val)
  3605. {
  3606. lsm6ds3tr_c_wake_up_dur_t wake_up_dur;
  3607. lsm6ds3tr_c_free_fall_t free_fall;
  3608. int32_t ret;
  3609. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_WAKE_UP_DUR,
  3610. (uint8_t *)&wake_up_dur, 1);
  3611. if (ret == 0)
  3612. {
  3613. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FREE_FALL,
  3614. (uint8_t *)&free_fall, 1);
  3615. }
  3616. *val = (wake_up_dur.ff_dur << 5) + free_fall.ff_dur;
  3617. return ret;
  3618. }
  3619. /**
  3620. * @brief Free fall threshold setting.[set]
  3621. *
  3622. * @param ctx Read / write interface definitions
  3623. * @param val Change the values of ff_ths in reg FREE_FALL
  3624. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3625. *
  3626. */
  3627. int32_t lsm6ds3tr_c_ff_threshold_set(stmdev_ctx_t *ctx,
  3628. lsm6ds3tr_c_ff_ths_t val)
  3629. {
  3630. lsm6ds3tr_c_free_fall_t free_fall;
  3631. int32_t ret;
  3632. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FREE_FALL,
  3633. (uint8_t *)&free_fall, 1);
  3634. if (ret == 0)
  3635. {
  3636. free_fall.ff_ths = (uint8_t) val;
  3637. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FREE_FALL,
  3638. (uint8_t *)&free_fall, 1);
  3639. }
  3640. return ret;
  3641. }
  3642. /**
  3643. * @brief Free fall threshold setting.[get]
  3644. *
  3645. * @param ctx Read / write interface definitions
  3646. * @param val Get the values of ff_ths in reg FREE_FALL
  3647. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3648. *
  3649. */
  3650. int32_t lsm6ds3tr_c_ff_threshold_get(stmdev_ctx_t *ctx,
  3651. lsm6ds3tr_c_ff_ths_t *val)
  3652. {
  3653. lsm6ds3tr_c_free_fall_t free_fall;
  3654. int32_t ret;
  3655. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FREE_FALL,
  3656. (uint8_t *)&free_fall, 1);
  3657. switch (free_fall.ff_ths)
  3658. {
  3659. case LSM6DS3TR_C_FF_TSH_156mg:
  3660. *val = LSM6DS3TR_C_FF_TSH_156mg;
  3661. break;
  3662. case LSM6DS3TR_C_FF_TSH_219mg:
  3663. *val = LSM6DS3TR_C_FF_TSH_219mg;
  3664. break;
  3665. case LSM6DS3TR_C_FF_TSH_250mg:
  3666. *val = LSM6DS3TR_C_FF_TSH_250mg;
  3667. break;
  3668. case LSM6DS3TR_C_FF_TSH_312mg:
  3669. *val = LSM6DS3TR_C_FF_TSH_312mg;
  3670. break;
  3671. case LSM6DS3TR_C_FF_TSH_344mg:
  3672. *val = LSM6DS3TR_C_FF_TSH_344mg;
  3673. break;
  3674. case LSM6DS3TR_C_FF_TSH_406mg:
  3675. *val = LSM6DS3TR_C_FF_TSH_406mg;
  3676. break;
  3677. case LSM6DS3TR_C_FF_TSH_469mg:
  3678. *val = LSM6DS3TR_C_FF_TSH_469mg;
  3679. break;
  3680. case LSM6DS3TR_C_FF_TSH_500mg:
  3681. *val = LSM6DS3TR_C_FF_TSH_500mg;
  3682. break;
  3683. default:
  3684. *val = LSM6DS3TR_C_FF_TSH_ND;
  3685. break;
  3686. }
  3687. return ret;
  3688. }
  3689. /**
  3690. * @}
  3691. *
  3692. */
  3693. /**
  3694. * @defgroup LSM6DS3TR_C_fifo
  3695. * @brief This section group all the functions concerning the
  3696. * fifo usage
  3697. * @{
  3698. *
  3699. */
  3700. /**
  3701. * @brief FIFO watermark level selection.[set]
  3702. *
  3703. * @param ctx Read / write interface definitions
  3704. * @param val Change the values of fth in reg FIFO_CTRL1
  3705. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3706. *
  3707. */
  3708. int32_t lsm6ds3tr_c_fifo_watermark_set(stmdev_ctx_t *ctx,
  3709. uint16_t val)
  3710. {
  3711. lsm6ds3tr_c_fifo_ctrl1_t fifo_ctrl1;
  3712. lsm6ds3tr_c_fifo_ctrl2_t fifo_ctrl2;
  3713. int32_t ret;
  3714. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3715. (uint8_t *)&fifo_ctrl2, 1);
  3716. if (ret == 0)
  3717. {
  3718. fifo_ctrl1.fth = (uint8_t)(0x00FFU & val);
  3719. fifo_ctrl2.fth = (uint8_t)((0x0700U & val) >> 8);
  3720. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL1,
  3721. (uint8_t *)&fifo_ctrl1, 1);
  3722. if (ret == 0)
  3723. {
  3724. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3725. (uint8_t *)&fifo_ctrl2, 1);
  3726. }
  3727. }
  3728. return ret;
  3729. }
  3730. /**
  3731. * @brief FIFO watermark level selection.[get]
  3732. *
  3733. * @param ctx Read / write interface definitions
  3734. * @param val Change the values of fth in reg FIFO_CTRL1
  3735. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3736. *
  3737. */
  3738. int32_t lsm6ds3tr_c_fifo_watermark_get(stmdev_ctx_t *ctx,
  3739. uint16_t *val)
  3740. {
  3741. lsm6ds3tr_c_fifo_ctrl1_t fifo_ctrl1;
  3742. lsm6ds3tr_c_fifo_ctrl2_t fifo_ctrl2;
  3743. int32_t ret;
  3744. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL1,
  3745. (uint8_t *)&fifo_ctrl1, 1);
  3746. if (ret == 0)
  3747. {
  3748. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3749. (uint8_t *)&fifo_ctrl2, 1);
  3750. }
  3751. *val = ((uint16_t)fifo_ctrl2.fth << 8) + (uint16_t)fifo_ctrl1.fth;
  3752. return ret;
  3753. }
  3754. /**
  3755. * @brief FIFO data level.[get]
  3756. *
  3757. * @param ctx Read / write interface definitions
  3758. * @param val get the values of diff_fifo in reg FIFO_STATUS1 and
  3759. * FIFO_STATUS2(diff_fifo), it is recommended to set the
  3760. * BDU bit.
  3761. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3762. *
  3763. */
  3764. int32_t lsm6ds3tr_c_fifo_data_level_get(stmdev_ctx_t *ctx,
  3765. uint16_t *val)
  3766. {
  3767. lsm6ds3tr_c_fifo_status1_t fifo_status1;
  3768. lsm6ds3tr_c_fifo_status2_t fifo_status2;
  3769. int32_t ret;
  3770. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_STATUS1,
  3771. (uint8_t *)&fifo_status1, 1);
  3772. if (ret == 0)
  3773. {
  3774. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_STATUS2,
  3775. (uint8_t *)&fifo_status2, 1);
  3776. *val = ((uint16_t) fifo_status2.diff_fifo << 8) +
  3777. (uint16_t) fifo_status1.diff_fifo;
  3778. }
  3779. return ret;
  3780. }
  3781. /**
  3782. * @brief FIFO watermark.[get]
  3783. *
  3784. * @param ctx Read / write interface definitions
  3785. * @param val get the values of watermark in reg FIFO_STATUS2 and
  3786. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3787. *
  3788. */
  3789. int32_t lsm6ds3tr_c_fifo_wtm_flag_get(stmdev_ctx_t *ctx, uint8_t *val)
  3790. {
  3791. lsm6ds3tr_c_fifo_status2_t fifo_status2;
  3792. int32_t ret;
  3793. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_STATUS2,
  3794. (uint8_t *)&fifo_status2, 1);
  3795. *val = fifo_status2.waterm;
  3796. return ret;
  3797. }
  3798. /**
  3799. * @brief FIFO pattern.[get]
  3800. *
  3801. * @param ctx Read / write interface definitions
  3802. * @param val get the values of fifo_pattern in reg FIFO_STATUS3 and
  3803. * FIFO_STATUS4, it is recommended to set the BDU bit
  3804. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3805. *
  3806. */
  3807. int32_t lsm6ds3tr_c_fifo_pattern_get(stmdev_ctx_t *ctx, uint16_t *val)
  3808. {
  3809. lsm6ds3tr_c_fifo_status3_t fifo_status3;
  3810. lsm6ds3tr_c_fifo_status4_t fifo_status4;
  3811. int32_t ret;
  3812. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_STATUS3,
  3813. (uint8_t *)&fifo_status3, 1);
  3814. if (ret == 0)
  3815. {
  3816. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_STATUS4,
  3817. (uint8_t *)&fifo_status4, 1);
  3818. *val = ((uint16_t)fifo_status4.fifo_pattern << 8) +
  3819. fifo_status3.fifo_pattern;
  3820. }
  3821. return ret;
  3822. }
  3823. /**
  3824. * @brief Batching of temperature data[set]
  3825. *
  3826. * @param ctx Read / write interface definitions
  3827. * @param val Change the values of fifo_temp_en in reg FIFO_CTRL2
  3828. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3829. *
  3830. */
  3831. int32_t lsm6ds3tr_c_fifo_temp_batch_set(stmdev_ctx_t *ctx,
  3832. uint8_t val)
  3833. {
  3834. lsm6ds3tr_c_fifo_ctrl2_t fifo_ctrl2;
  3835. int32_t ret;
  3836. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3837. (uint8_t *)&fifo_ctrl2, 1);
  3838. if (ret == 0)
  3839. {
  3840. fifo_ctrl2.fifo_temp_en = val;
  3841. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3842. (uint8_t *)&fifo_ctrl2, 1);
  3843. }
  3844. return ret;
  3845. }
  3846. /**
  3847. * @brief Batching of temperature data[get]
  3848. *
  3849. * @param ctx Read / write interface definitions
  3850. * @param val Change the values of fifo_temp_en in reg FIFO_CTRL2
  3851. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3852. *
  3853. */
  3854. int32_t lsm6ds3tr_c_fifo_temp_batch_get(stmdev_ctx_t *ctx,
  3855. uint8_t *val)
  3856. {
  3857. lsm6ds3tr_c_fifo_ctrl2_t fifo_ctrl2;
  3858. int32_t ret;
  3859. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3860. (uint8_t *)&fifo_ctrl2, 1);
  3861. *val = fifo_ctrl2.fifo_temp_en;
  3862. return ret;
  3863. }
  3864. /**
  3865. * @brief Trigger signal for FIFO write operation.[set]
  3866. *
  3867. * @param ctx Read / write interface definitions
  3868. * @param val act on FIFO_CTRL2(timer_pedo_fifo_drdy)
  3869. * and MASTER_CONFIG(data_valid_sel_fifo)
  3870. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3871. *
  3872. */
  3873. int32_t lsm6ds3tr_c_fifo_write_trigger_set(stmdev_ctx_t *ctx,
  3874. lsm6ds3tr_c_trigger_fifo_t val)
  3875. {
  3876. lsm6ds3tr_c_fifo_ctrl2_t fifo_ctrl2;
  3877. lsm6ds3tr_c_master_config_t master_config;
  3878. int32_t ret;
  3879. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3880. (uint8_t *)&fifo_ctrl2, 1);
  3881. if (ret == 0)
  3882. {
  3883. fifo_ctrl2.timer_pedo_fifo_drdy = (uint8_t)val & 0x01U;
  3884. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3885. (uint8_t *)&fifo_ctrl2, 1);
  3886. if (ret == 0)
  3887. {
  3888. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  3889. (uint8_t *)&master_config, 1);
  3890. if (ret == 0)
  3891. {
  3892. master_config.data_valid_sel_fifo = (((uint8_t)val & 0x02U) >> 1);
  3893. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  3894. (uint8_t *)&master_config, 1);
  3895. }
  3896. }
  3897. }
  3898. return ret;
  3899. }
  3900. /**
  3901. * @brief Trigger signal for FIFO write operation.[get]
  3902. *
  3903. * @param ctx Read / write interface definitions
  3904. * @param val act on FIFO_CTRL2(timer_pedo_fifo_drdy)
  3905. * and MASTER_CONFIG(data_valid_sel_fifo)
  3906. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3907. *
  3908. */
  3909. int32_t lsm6ds3tr_c_fifo_write_trigger_get(stmdev_ctx_t *ctx,
  3910. lsm6ds3tr_c_trigger_fifo_t *val)
  3911. {
  3912. lsm6ds3tr_c_fifo_ctrl2_t fifo_ctrl2;
  3913. lsm6ds3tr_c_master_config_t master_config;
  3914. int32_t ret;
  3915. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3916. (uint8_t *)&fifo_ctrl2, 1);
  3917. if (ret == 0)
  3918. {
  3919. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  3920. (uint8_t *)&master_config, 1);
  3921. switch ((fifo_ctrl2.timer_pedo_fifo_drdy << 1) +
  3922. fifo_ctrl2. timer_pedo_fifo_drdy)
  3923. {
  3924. case LSM6DS3TR_C_TRG_XL_GY_DRDY:
  3925. *val = LSM6DS3TR_C_TRG_XL_GY_DRDY;
  3926. break;
  3927. case LSM6DS3TR_C_TRG_STEP_DETECT:
  3928. *val = LSM6DS3TR_C_TRG_STEP_DETECT;
  3929. break;
  3930. case LSM6DS3TR_C_TRG_SH_DRDY:
  3931. *val = LSM6DS3TR_C_TRG_SH_DRDY;
  3932. break;
  3933. default:
  3934. *val = LSM6DS3TR_C_TRG_SH_ND;
  3935. break;
  3936. }
  3937. }
  3938. return ret;
  3939. }
  3940. /**
  3941. * @brief Enable pedometer step counter and timestamp as 4th
  3942. * FIFO data set.[set]
  3943. *
  3944. * @param ctx Read / write interface definitions
  3945. * @param val Change the values of timer_pedo_fifo_en in reg FIFO_CTRL2
  3946. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3947. *
  3948. */
  3949. int32_t lsm6ds3tr_c_fifo_pedo_and_timestamp_batch_set(
  3950. stmdev_ctx_t *ctx,
  3951. uint8_t val)
  3952. {
  3953. lsm6ds3tr_c_fifo_ctrl2_t fifo_ctrl2;
  3954. int32_t ret;
  3955. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3956. (uint8_t *)&fifo_ctrl2, 1);
  3957. if (ret == 0)
  3958. {
  3959. fifo_ctrl2.timer_pedo_fifo_en = val;
  3960. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3961. (uint8_t *)&fifo_ctrl2, 1);
  3962. }
  3963. return ret;
  3964. }
  3965. /**
  3966. * @brief Enable pedometer step counter and timestamp as 4th
  3967. * FIFO data set.[get]
  3968. *
  3969. * @param ctx Read / write interface definitions
  3970. * @param val Change the values of timer_pedo_fifo_en in reg FIFO_CTRL2
  3971. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3972. *
  3973. */
  3974. int32_t lsm6ds3tr_c_fifo_pedo_and_timestamp_batch_get(
  3975. stmdev_ctx_t *ctx,
  3976. uint8_t *val)
  3977. {
  3978. lsm6ds3tr_c_fifo_ctrl2_t fifo_ctrl2;
  3979. int32_t ret;
  3980. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL2,
  3981. (uint8_t *)&fifo_ctrl2, 1);
  3982. *val = fifo_ctrl2.timer_pedo_fifo_en;
  3983. return ret;
  3984. }
  3985. /**
  3986. * @brief Selects Batching Data Rate (writing frequency in FIFO) for
  3987. * accelerometer data.[set]
  3988. *
  3989. * @param ctx Read / write interface definitions
  3990. * @param val Change the values of dec_fifo_xl in reg FIFO_CTRL3
  3991. * @retval Interface status (MANDATORY: return 0 -> no Error).
  3992. *
  3993. */
  3994. int32_t lsm6ds3tr_c_fifo_xl_batch_set(stmdev_ctx_t *ctx,
  3995. lsm6ds3tr_c_dec_fifo_xl_t val)
  3996. {
  3997. lsm6ds3tr_c_fifo_ctrl3_t fifo_ctrl3;
  3998. int32_t ret;
  3999. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL3,
  4000. (uint8_t *)&fifo_ctrl3, 1);
  4001. if (ret == 0)
  4002. {
  4003. fifo_ctrl3.dec_fifo_xl = (uint8_t)val;
  4004. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL3,
  4005. (uint8_t *)&fifo_ctrl3, 1);
  4006. }
  4007. return ret;
  4008. }
  4009. /**
  4010. * @brief Selects Batching Data Rate (writing frequency in FIFO) for
  4011. * accelerometer data.[get]
  4012. *
  4013. * @param ctx Read / write interface definitions
  4014. * @param val Get the values of dec_fifo_xl in reg FIFO_CTRL3
  4015. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4016. *
  4017. */
  4018. int32_t lsm6ds3tr_c_fifo_xl_batch_get(stmdev_ctx_t *ctx,
  4019. lsm6ds3tr_c_dec_fifo_xl_t *val)
  4020. {
  4021. lsm6ds3tr_c_fifo_ctrl3_t fifo_ctrl3;
  4022. int32_t ret;
  4023. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL3,
  4024. (uint8_t *)&fifo_ctrl3, 1);
  4025. switch (fifo_ctrl3.dec_fifo_xl)
  4026. {
  4027. case LSM6DS3TR_C_FIFO_XL_DISABLE:
  4028. *val = LSM6DS3TR_C_FIFO_XL_DISABLE;
  4029. break;
  4030. case LSM6DS3TR_C_FIFO_XL_NO_DEC:
  4031. *val = LSM6DS3TR_C_FIFO_XL_NO_DEC;
  4032. break;
  4033. case LSM6DS3TR_C_FIFO_XL_DEC_2:
  4034. *val = LSM6DS3TR_C_FIFO_XL_DEC_2;
  4035. break;
  4036. case LSM6DS3TR_C_FIFO_XL_DEC_3:
  4037. *val = LSM6DS3TR_C_FIFO_XL_DEC_3;
  4038. break;
  4039. case LSM6DS3TR_C_FIFO_XL_DEC_4:
  4040. *val = LSM6DS3TR_C_FIFO_XL_DEC_4;
  4041. break;
  4042. case LSM6DS3TR_C_FIFO_XL_DEC_8:
  4043. *val = LSM6DS3TR_C_FIFO_XL_DEC_8;
  4044. break;
  4045. case LSM6DS3TR_C_FIFO_XL_DEC_16:
  4046. *val = LSM6DS3TR_C_FIFO_XL_DEC_16;
  4047. break;
  4048. case LSM6DS3TR_C_FIFO_XL_DEC_32:
  4049. *val = LSM6DS3TR_C_FIFO_XL_DEC_32;
  4050. break;
  4051. default:
  4052. *val = LSM6DS3TR_C_FIFO_XL_DEC_ND;
  4053. break;
  4054. }
  4055. return ret;
  4056. }
  4057. /**
  4058. * @brief Selects Batching Data Rate (writing frequency in FIFO)
  4059. * for gyroscope data.[set]
  4060. *
  4061. * @param ctx Read / write interface definitions
  4062. * @param val Change the values of dec_fifo_gyro in reg FIFO_CTRL3
  4063. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4064. *
  4065. */
  4066. int32_t lsm6ds3tr_c_fifo_gy_batch_set(stmdev_ctx_t *ctx,
  4067. lsm6ds3tr_c_dec_fifo_gyro_t val)
  4068. {
  4069. lsm6ds3tr_c_fifo_ctrl3_t fifo_ctrl3;
  4070. int32_t ret;
  4071. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL3,
  4072. (uint8_t *)&fifo_ctrl3, 1);
  4073. if (ret == 0)
  4074. {
  4075. fifo_ctrl3.dec_fifo_gyro = (uint8_t)val;
  4076. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL3,
  4077. (uint8_t *)&fifo_ctrl3, 1);
  4078. }
  4079. return ret;
  4080. }
  4081. /**
  4082. * @brief Selects Batching Data Rate (writing frequency in FIFO)
  4083. * for gyroscope data.[get]
  4084. *
  4085. * @param ctx Read / write interface definitions
  4086. * @param val Get the values of dec_fifo_gyro in reg FIFO_CTRL3
  4087. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4088. *
  4089. */
  4090. int32_t lsm6ds3tr_c_fifo_gy_batch_get(stmdev_ctx_t *ctx,
  4091. lsm6ds3tr_c_dec_fifo_gyro_t *val)
  4092. {
  4093. lsm6ds3tr_c_fifo_ctrl3_t fifo_ctrl3;
  4094. int32_t ret;
  4095. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL3,
  4096. (uint8_t *)&fifo_ctrl3, 1);
  4097. switch (fifo_ctrl3.dec_fifo_gyro)
  4098. {
  4099. case LSM6DS3TR_C_FIFO_GY_DISABLE:
  4100. *val = LSM6DS3TR_C_FIFO_GY_DISABLE;
  4101. break;
  4102. case LSM6DS3TR_C_FIFO_GY_NO_DEC:
  4103. *val = LSM6DS3TR_C_FIFO_GY_NO_DEC;
  4104. break;
  4105. case LSM6DS3TR_C_FIFO_GY_DEC_2:
  4106. *val = LSM6DS3TR_C_FIFO_GY_DEC_2;
  4107. break;
  4108. case LSM6DS3TR_C_FIFO_GY_DEC_3:
  4109. *val = LSM6DS3TR_C_FIFO_GY_DEC_3;
  4110. break;
  4111. case LSM6DS3TR_C_FIFO_GY_DEC_4:
  4112. *val = LSM6DS3TR_C_FIFO_GY_DEC_4;
  4113. break;
  4114. case LSM6DS3TR_C_FIFO_GY_DEC_8:
  4115. *val = LSM6DS3TR_C_FIFO_GY_DEC_8;
  4116. break;
  4117. case LSM6DS3TR_C_FIFO_GY_DEC_16:
  4118. *val = LSM6DS3TR_C_FIFO_GY_DEC_16;
  4119. break;
  4120. case LSM6DS3TR_C_FIFO_GY_DEC_32:
  4121. *val = LSM6DS3TR_C_FIFO_GY_DEC_32;
  4122. break;
  4123. default:
  4124. *val = LSM6DS3TR_C_FIFO_GY_DEC_ND;
  4125. break;
  4126. }
  4127. return ret;
  4128. }
  4129. /**
  4130. * @brief Selects Batching Data Rate (writing frequency in FIFO)
  4131. * for third data set.[set]
  4132. *
  4133. * @param ctx Read / write interface definitions
  4134. * @param val Change the values of dec_ds3_fifo in reg FIFO_CTRL4
  4135. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4136. *
  4137. */
  4138. int32_t lsm6ds3tr_c_fifo_dataset_3_batch_set(stmdev_ctx_t *ctx,
  4139. lsm6ds3tr_c_dec_ds3_fifo_t val)
  4140. {
  4141. lsm6ds3tr_c_fifo_ctrl4_t fifo_ctrl4;
  4142. int32_t ret;
  4143. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4144. (uint8_t *)&fifo_ctrl4, 1);
  4145. if (ret == 0)
  4146. {
  4147. fifo_ctrl4.dec_ds3_fifo = (uint8_t)val;
  4148. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4149. (uint8_t *)&fifo_ctrl4, 1);
  4150. }
  4151. return ret;
  4152. }
  4153. /**
  4154. * @brief Selects Batching Data Rate (writing frequency in FIFO)
  4155. * for third data set.[get]
  4156. *
  4157. * @param ctx Read / write interface definitions
  4158. * @param val Get the values of dec_ds3_fifo in reg FIFO_CTRL4
  4159. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4160. *
  4161. */
  4162. int32_t lsm6ds3tr_c_fifo_dataset_3_batch_get(stmdev_ctx_t *ctx,
  4163. lsm6ds3tr_c_dec_ds3_fifo_t *val)
  4164. {
  4165. lsm6ds3tr_c_fifo_ctrl4_t fifo_ctrl4;
  4166. int32_t ret;
  4167. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4168. (uint8_t *)&fifo_ctrl4, 1);
  4169. switch (fifo_ctrl4.dec_ds3_fifo)
  4170. {
  4171. case LSM6DS3TR_C_FIFO_DS3_DISABLE:
  4172. *val = LSM6DS3TR_C_FIFO_DS3_DISABLE;
  4173. break;
  4174. case LSM6DS3TR_C_FIFO_DS3_NO_DEC:
  4175. *val = LSM6DS3TR_C_FIFO_DS3_NO_DEC;
  4176. break;
  4177. case LSM6DS3TR_C_FIFO_DS3_DEC_2:
  4178. *val = LSM6DS3TR_C_FIFO_DS3_DEC_2;
  4179. break;
  4180. case LSM6DS3TR_C_FIFO_DS3_DEC_3:
  4181. *val = LSM6DS3TR_C_FIFO_DS3_DEC_3;
  4182. break;
  4183. case LSM6DS3TR_C_FIFO_DS3_DEC_4:
  4184. *val = LSM6DS3TR_C_FIFO_DS3_DEC_4;
  4185. break;
  4186. case LSM6DS3TR_C_FIFO_DS3_DEC_8:
  4187. *val = LSM6DS3TR_C_FIFO_DS3_DEC_8;
  4188. break;
  4189. case LSM6DS3TR_C_FIFO_DS3_DEC_16:
  4190. *val = LSM6DS3TR_C_FIFO_DS3_DEC_16;
  4191. break;
  4192. case LSM6DS3TR_C_FIFO_DS3_DEC_32:
  4193. *val = LSM6DS3TR_C_FIFO_DS3_DEC_32;
  4194. break;
  4195. default:
  4196. *val = LSM6DS3TR_C_FIFO_DS3_DEC_ND;
  4197. break;
  4198. }
  4199. return ret;
  4200. }
  4201. /**
  4202. * @brief Selects Batching Data Rate (writing frequency in FIFO)
  4203. * for fourth data set.[set]
  4204. *
  4205. * @param ctx Read / write interface definitions
  4206. * @param val Change the values of dec_ds4_fifo in reg FIFO_CTRL4
  4207. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4208. *
  4209. */
  4210. int32_t lsm6ds3tr_c_fifo_dataset_4_batch_set(stmdev_ctx_t *ctx,
  4211. lsm6ds3tr_c_dec_ds4_fifo_t val)
  4212. {
  4213. lsm6ds3tr_c_fifo_ctrl4_t fifo_ctrl4;
  4214. int32_t ret;
  4215. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4216. (uint8_t *)&fifo_ctrl4, 1);
  4217. if (ret == 0)
  4218. {
  4219. fifo_ctrl4.dec_ds4_fifo = (uint8_t)val;
  4220. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4221. (uint8_t *)&fifo_ctrl4, 1);
  4222. }
  4223. return ret;
  4224. }
  4225. /**
  4226. * @brief Selects Batching Data Rate (writing frequency in FIFO) for
  4227. * fourth data set.[get]
  4228. *
  4229. * @param ctx Read / write interface definitions
  4230. * @param val Get the values of dec_ds4_fifo in reg FIFO_CTRL4
  4231. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4232. *
  4233. */
  4234. int32_t lsm6ds3tr_c_fifo_dataset_4_batch_get(stmdev_ctx_t *ctx,
  4235. lsm6ds3tr_c_dec_ds4_fifo_t *val)
  4236. {
  4237. lsm6ds3tr_c_fifo_ctrl4_t fifo_ctrl4;
  4238. int32_t ret;
  4239. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4240. (uint8_t *)&fifo_ctrl4, 1);
  4241. switch (fifo_ctrl4.dec_ds4_fifo)
  4242. {
  4243. case LSM6DS3TR_C_FIFO_DS4_DISABLE:
  4244. *val = LSM6DS3TR_C_FIFO_DS4_DISABLE;
  4245. break;
  4246. case LSM6DS3TR_C_FIFO_DS4_NO_DEC:
  4247. *val = LSM6DS3TR_C_FIFO_DS4_NO_DEC;
  4248. break;
  4249. case LSM6DS3TR_C_FIFO_DS4_DEC_2:
  4250. *val = LSM6DS3TR_C_FIFO_DS4_DEC_2;
  4251. break;
  4252. case LSM6DS3TR_C_FIFO_DS4_DEC_3:
  4253. *val = LSM6DS3TR_C_FIFO_DS4_DEC_3;
  4254. break;
  4255. case LSM6DS3TR_C_FIFO_DS4_DEC_4:
  4256. *val = LSM6DS3TR_C_FIFO_DS4_DEC_4;
  4257. break;
  4258. case LSM6DS3TR_C_FIFO_DS4_DEC_8:
  4259. *val = LSM6DS3TR_C_FIFO_DS4_DEC_8;
  4260. break;
  4261. case LSM6DS3TR_C_FIFO_DS4_DEC_16:
  4262. *val = LSM6DS3TR_C_FIFO_DS4_DEC_16;
  4263. break;
  4264. case LSM6DS3TR_C_FIFO_DS4_DEC_32:
  4265. *val = LSM6DS3TR_C_FIFO_DS4_DEC_32;
  4266. break;
  4267. default:
  4268. *val = LSM6DS3TR_C_FIFO_DS4_DEC_ND;
  4269. break;
  4270. }
  4271. return ret;
  4272. }
  4273. /**
  4274. * @brief 8-bit data storage in FIFO.[set]
  4275. *
  4276. * @param ctx Read / write interface definitions
  4277. * @param val Change the values of only_high_data in reg FIFO_CTRL4
  4278. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4279. *
  4280. */
  4281. int32_t lsm6ds3tr_c_fifo_xl_gy_8bit_format_set(stmdev_ctx_t *ctx,
  4282. uint8_t val)
  4283. {
  4284. lsm6ds3tr_c_fifo_ctrl4_t fifo_ctrl4;
  4285. int32_t ret;
  4286. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4287. (uint8_t *)&fifo_ctrl4, 1);
  4288. if (ret == 0)
  4289. {
  4290. fifo_ctrl4.only_high_data = val;
  4291. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4292. (uint8_t *)&fifo_ctrl4, 1);
  4293. }
  4294. return ret;
  4295. }
  4296. /**
  4297. * @brief 8-bit data storage in FIFO.[get]
  4298. *
  4299. * @param ctx Read / write interface definitions
  4300. * @param val Change the values of only_high_data in reg FIFO_CTRL4
  4301. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4302. *
  4303. */
  4304. int32_t lsm6ds3tr_c_fifo_xl_gy_8bit_format_get(stmdev_ctx_t *ctx,
  4305. uint8_t *val)
  4306. {
  4307. lsm6ds3tr_c_fifo_ctrl4_t fifo_ctrl4;
  4308. int32_t ret;
  4309. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4310. (uint8_t *)&fifo_ctrl4, 1);
  4311. *val = fifo_ctrl4.only_high_data;
  4312. return ret;
  4313. }
  4314. /**
  4315. * @brief Sensing chain FIFO stop values memorization at threshold
  4316. * level.[set]
  4317. *
  4318. * @param ctx Read / write interface definitions
  4319. * @param val Change the values of stop_on_fth in reg FIFO_CTRL4
  4320. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4321. *
  4322. */
  4323. int32_t lsm6ds3tr_c_fifo_stop_on_wtm_set(stmdev_ctx_t *ctx,
  4324. uint8_t val)
  4325. {
  4326. lsm6ds3tr_c_fifo_ctrl4_t fifo_ctrl4;
  4327. int32_t ret;
  4328. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4329. (uint8_t *)&fifo_ctrl4, 1);
  4330. if (ret == 0)
  4331. {
  4332. fifo_ctrl4.stop_on_fth = val;
  4333. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4334. (uint8_t *)&fifo_ctrl4, 1);
  4335. }
  4336. return ret;
  4337. }
  4338. /**
  4339. * @brief Sensing chain FIFO stop values memorization at threshold
  4340. * level.[get]
  4341. *
  4342. * @param ctx Read / write interface definitions
  4343. * @param val Change the values of stop_on_fth in reg FIFO_CTRL4
  4344. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4345. *
  4346. */
  4347. int32_t lsm6ds3tr_c_fifo_stop_on_wtm_get(stmdev_ctx_t *ctx,
  4348. uint8_t *val)
  4349. {
  4350. lsm6ds3tr_c_fifo_ctrl4_t fifo_ctrl4;
  4351. int32_t ret;
  4352. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL4,
  4353. (uint8_t *)&fifo_ctrl4, 1);
  4354. *val = fifo_ctrl4.stop_on_fth;
  4355. return ret;
  4356. }
  4357. /**
  4358. * @brief FIFO mode selection.[set]
  4359. *
  4360. * @param ctx Read / write interface definitions
  4361. * @param val Change the values of fifo_mode in reg FIFO_CTRL5
  4362. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4363. *
  4364. */
  4365. int32_t lsm6ds3tr_c_fifo_mode_set(stmdev_ctx_t *ctx,
  4366. lsm6ds3tr_c_fifo_mode_t val)
  4367. {
  4368. lsm6ds3tr_c_fifo_ctrl5_t fifo_ctrl5;
  4369. int32_t ret;
  4370. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL5,
  4371. (uint8_t *)&fifo_ctrl5, 1);
  4372. if (ret == 0)
  4373. {
  4374. fifo_ctrl5.fifo_mode = (uint8_t)val;
  4375. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL5,
  4376. (uint8_t *)&fifo_ctrl5, 1);
  4377. }
  4378. return ret;
  4379. }
  4380. /**
  4381. * @brief FIFO mode selection.[get]
  4382. *
  4383. * @param ctx Read / write interface definitions
  4384. * @param val Get the values of fifo_mode in reg FIFO_CTRL5
  4385. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4386. *
  4387. */
  4388. int32_t lsm6ds3tr_c_fifo_mode_get(stmdev_ctx_t *ctx,
  4389. lsm6ds3tr_c_fifo_mode_t *val)
  4390. {
  4391. lsm6ds3tr_c_fifo_ctrl5_t fifo_ctrl5;
  4392. int32_t ret;
  4393. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL5,
  4394. (uint8_t *)&fifo_ctrl5, 1);
  4395. switch (fifo_ctrl5.fifo_mode)
  4396. {
  4397. case LSM6DS3TR_C_BYPASS_MODE:
  4398. *val = LSM6DS3TR_C_BYPASS_MODE;
  4399. break;
  4400. case LSM6DS3TR_C_FIFO_MODE:
  4401. *val = LSM6DS3TR_C_FIFO_MODE;
  4402. break;
  4403. case LSM6DS3TR_C_STREAM_TO_FIFO_MODE:
  4404. *val = LSM6DS3TR_C_STREAM_TO_FIFO_MODE;
  4405. break;
  4406. case LSM6DS3TR_C_BYPASS_TO_STREAM_MODE:
  4407. *val = LSM6DS3TR_C_BYPASS_TO_STREAM_MODE;
  4408. break;
  4409. case LSM6DS3TR_C_STREAM_MODE:
  4410. *val = LSM6DS3TR_C_STREAM_MODE;
  4411. break;
  4412. default:
  4413. *val = LSM6DS3TR_C_FIFO_MODE_ND;
  4414. break;
  4415. }
  4416. return ret;
  4417. }
  4418. /**
  4419. * @brief FIFO ODR selection, setting FIFO_MODE also.[set]
  4420. *
  4421. * @param ctx Read / write interface definitions
  4422. * @param val Change the values of odr_fifo in reg FIFO_CTRL5
  4423. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4424. *
  4425. */
  4426. int32_t lsm6ds3tr_c_fifo_data_rate_set(stmdev_ctx_t *ctx,
  4427. lsm6ds3tr_c_odr_fifo_t val)
  4428. {
  4429. lsm6ds3tr_c_fifo_ctrl5_t fifo_ctrl5;
  4430. int32_t ret;
  4431. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL5,
  4432. (uint8_t *)&fifo_ctrl5, 1);
  4433. if (ret == 0)
  4434. {
  4435. fifo_ctrl5.odr_fifo = (uint8_t)val;
  4436. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_FIFO_CTRL5,
  4437. (uint8_t *)&fifo_ctrl5, 1);
  4438. }
  4439. return ret;
  4440. }
  4441. /**
  4442. * @brief FIFO ODR selection, setting FIFO_MODE also.[get]
  4443. *
  4444. * @param ctx Read / write interface definitions
  4445. * @param val Get the values of odr_fifo in reg FIFO_CTRL5
  4446. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4447. *
  4448. */
  4449. int32_t lsm6ds3tr_c_fifo_data_rate_get(stmdev_ctx_t *ctx,
  4450. lsm6ds3tr_c_odr_fifo_t *val)
  4451. {
  4452. lsm6ds3tr_c_fifo_ctrl5_t fifo_ctrl5;
  4453. int32_t ret;
  4454. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_FIFO_CTRL5,
  4455. (uint8_t *)&fifo_ctrl5, 1);
  4456. switch (fifo_ctrl5.odr_fifo)
  4457. {
  4458. case LSM6DS3TR_C_FIFO_DISABLE:
  4459. *val = LSM6DS3TR_C_FIFO_DISABLE;
  4460. break;
  4461. case LSM6DS3TR_C_FIFO_12Hz5:
  4462. *val = LSM6DS3TR_C_FIFO_12Hz5;
  4463. break;
  4464. case LSM6DS3TR_C_FIFO_26Hz:
  4465. *val = LSM6DS3TR_C_FIFO_26Hz;
  4466. break;
  4467. case LSM6DS3TR_C_FIFO_52Hz:
  4468. *val = LSM6DS3TR_C_FIFO_52Hz;
  4469. break;
  4470. case LSM6DS3TR_C_FIFO_104Hz:
  4471. *val = LSM6DS3TR_C_FIFO_104Hz;
  4472. break;
  4473. case LSM6DS3TR_C_FIFO_208Hz:
  4474. *val = LSM6DS3TR_C_FIFO_208Hz;
  4475. break;
  4476. case LSM6DS3TR_C_FIFO_416Hz:
  4477. *val = LSM6DS3TR_C_FIFO_416Hz;
  4478. break;
  4479. case LSM6DS3TR_C_FIFO_833Hz:
  4480. *val = LSM6DS3TR_C_FIFO_833Hz;
  4481. break;
  4482. case LSM6DS3TR_C_FIFO_1k66Hz:
  4483. *val = LSM6DS3TR_C_FIFO_1k66Hz;
  4484. break;
  4485. case LSM6DS3TR_C_FIFO_3k33Hz:
  4486. *val = LSM6DS3TR_C_FIFO_3k33Hz;
  4487. break;
  4488. case LSM6DS3TR_C_FIFO_6k66Hz:
  4489. *val = LSM6DS3TR_C_FIFO_6k66Hz;
  4490. break;
  4491. default:
  4492. *val = LSM6DS3TR_C_FIFO_RATE_ND;
  4493. break;
  4494. }
  4495. return ret;
  4496. }
  4497. /**
  4498. * @}
  4499. *
  4500. */
  4501. /**
  4502. * @defgroup LSM6DS3TR_C_DEN_functionality
  4503. * @brief This section groups all the functions concerning DEN
  4504. * functionality.
  4505. * @{
  4506. *
  4507. */
  4508. /**
  4509. * @brief DEN active level configuration.[set]
  4510. *
  4511. * @param ctx Read / write interface definitions
  4512. * @param val Change the values of den_lh in reg CTRL5_C
  4513. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4514. *
  4515. */
  4516. int32_t lsm6ds3tr_c_den_polarity_set(stmdev_ctx_t *ctx,
  4517. lsm6ds3tr_c_den_lh_t val)
  4518. {
  4519. lsm6ds3tr_c_ctrl5_c_t ctrl5_c;
  4520. int32_t ret;
  4521. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  4522. (uint8_t *)&ctrl5_c, 1);
  4523. if (ret == 0)
  4524. {
  4525. ctrl5_c.den_lh = (uint8_t)val;
  4526. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  4527. (uint8_t *)&ctrl5_c, 1);
  4528. }
  4529. return ret;
  4530. }
  4531. /**
  4532. * @brief DEN active level configuration.[get]
  4533. *
  4534. * @param ctx Read / write interface definitions
  4535. * @param val Get the values of den_lh in reg CTRL5_C
  4536. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4537. *
  4538. */
  4539. int32_t lsm6ds3tr_c_den_polarity_get(stmdev_ctx_t *ctx,
  4540. lsm6ds3tr_c_den_lh_t *val)
  4541. {
  4542. lsm6ds3tr_c_ctrl5_c_t ctrl5_c;
  4543. int32_t ret;
  4544. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL5_C,
  4545. (uint8_t *)&ctrl5_c, 1);
  4546. switch (ctrl5_c.den_lh)
  4547. {
  4548. case LSM6DS3TR_C_DEN_ACT_LOW:
  4549. *val = LSM6DS3TR_C_DEN_ACT_LOW;
  4550. break;
  4551. case LSM6DS3TR_C_DEN_ACT_HIGH:
  4552. *val = LSM6DS3TR_C_DEN_ACT_HIGH;
  4553. break;
  4554. default:
  4555. *val = LSM6DS3TR_C_DEN_POL_ND;
  4556. break;
  4557. }
  4558. return ret;
  4559. }
  4560. /**
  4561. * @brief DEN functionality marking mode[set]
  4562. *
  4563. * @param ctx Read / write interface definitions
  4564. * @param val Change the values of den_mode in reg CTRL6_C
  4565. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4566. *
  4567. */
  4568. int32_t lsm6ds3tr_c_den_mode_set(stmdev_ctx_t *ctx,
  4569. lsm6ds3tr_c_den_mode_t val)
  4570. {
  4571. lsm6ds3tr_c_ctrl6_c_t ctrl6_c;
  4572. int32_t ret;
  4573. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  4574. (uint8_t *)&ctrl6_c, 1);
  4575. if (ret == 0)
  4576. {
  4577. ctrl6_c.den_mode = (uint8_t)val;
  4578. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  4579. (uint8_t *)&ctrl6_c, 1);
  4580. }
  4581. return ret;
  4582. }
  4583. /**
  4584. * @brief DEN functionality marking mode[get]
  4585. *
  4586. * @param ctx Read / write interface definitions
  4587. * @param val Change the values of den_mode in reg CTRL6_C
  4588. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4589. *
  4590. */
  4591. int32_t lsm6ds3tr_c_den_mode_get(stmdev_ctx_t *ctx,
  4592. lsm6ds3tr_c_den_mode_t *val)
  4593. {
  4594. lsm6ds3tr_c_ctrl6_c_t ctrl6_c;
  4595. int32_t ret;
  4596. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL6_C,
  4597. (uint8_t *)&ctrl6_c, 1);
  4598. switch (ctrl6_c.den_mode)
  4599. {
  4600. case LSM6DS3TR_C_DEN_DISABLE:
  4601. *val = LSM6DS3TR_C_DEN_DISABLE;
  4602. break;
  4603. case LSM6DS3TR_C_LEVEL_LETCHED:
  4604. *val = LSM6DS3TR_C_LEVEL_LETCHED;
  4605. break;
  4606. case LSM6DS3TR_C_LEVEL_TRIGGER:
  4607. *val = LSM6DS3TR_C_LEVEL_TRIGGER;
  4608. break;
  4609. case LSM6DS3TR_C_EDGE_TRIGGER:
  4610. *val = LSM6DS3TR_C_EDGE_TRIGGER;
  4611. break;
  4612. default:
  4613. *val = LSM6DS3TR_C_DEN_MODE_ND;
  4614. break;
  4615. }
  4616. return ret;
  4617. }
  4618. /**
  4619. * @brief Extend DEN functionality to accelerometer sensor.[set]
  4620. *
  4621. * @param ctx Read / write interface definitions
  4622. * @param val Change the values of den_xl_g in reg CTRL9_XL
  4623. * and den_xl_en in CTRL4_C.
  4624. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4625. *
  4626. */
  4627. int32_t lsm6ds3tr_c_den_enable_set(stmdev_ctx_t *ctx,
  4628. lsm6ds3tr_c_den_xl_en_t val)
  4629. {
  4630. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  4631. lsm6ds3tr_c_ctrl9_xl_t ctrl9_xl;
  4632. int32_t ret;
  4633. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4634. (uint8_t *)&ctrl9_xl, 1);
  4635. if (ret == 0)
  4636. {
  4637. ctrl9_xl.den_xl_g = (uint8_t)val & 0x01U;
  4638. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4639. (uint8_t *)&ctrl9_xl, 1);
  4640. if (ret == 0)
  4641. {
  4642. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  4643. (uint8_t *)&ctrl4_c, 1);
  4644. if (ret == 0)
  4645. {
  4646. ctrl4_c.den_xl_en = (uint8_t)val & 0x02U;
  4647. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  4648. (uint8_t *)&ctrl4_c, 1);
  4649. }
  4650. }
  4651. }
  4652. return ret;
  4653. }
  4654. /**
  4655. * @brief Extend DEN functionality to accelerometer sensor. [get]
  4656. *
  4657. * @param ctx Read / write interface definitions
  4658. * @param val Get the values of den_xl_g in reg CTRL9_XL
  4659. * and den_xl_en in CTRL4_C.
  4660. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4661. *
  4662. */
  4663. int32_t lsm6ds3tr_c_den_enable_get(stmdev_ctx_t *ctx,
  4664. lsm6ds3tr_c_den_xl_en_t *val)
  4665. {
  4666. lsm6ds3tr_c_ctrl4_c_t ctrl4_c;
  4667. lsm6ds3tr_c_ctrl9_xl_t ctrl9_xl;
  4668. int32_t ret;
  4669. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL4_C,
  4670. (uint8_t *)&ctrl4_c, 1);
  4671. if (ret == 0)
  4672. {
  4673. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4674. (uint8_t *)&ctrl9_xl, 1);
  4675. switch ((ctrl4_c.den_xl_en << 1) + ctrl9_xl.den_xl_g)
  4676. {
  4677. case LSM6DS3TR_C_STAMP_IN_GY_DATA:
  4678. *val = LSM6DS3TR_C_STAMP_IN_GY_DATA;
  4679. break;
  4680. case LSM6DS3TR_C_STAMP_IN_XL_DATA:
  4681. *val = LSM6DS3TR_C_STAMP_IN_XL_DATA;
  4682. break;
  4683. case LSM6DS3TR_C_STAMP_IN_GY_XL_DATA:
  4684. *val = LSM6DS3TR_C_STAMP_IN_GY_XL_DATA;
  4685. break;
  4686. default:
  4687. *val = LSM6DS3TR_C_DEN_STAMP_ND;
  4688. break;
  4689. }
  4690. }
  4691. return ret;
  4692. }
  4693. /**
  4694. * @brief DEN value stored in LSB of Z-axis.[set]
  4695. *
  4696. * @param ctx Read / write interface definitions
  4697. * @param val Change the values of den_z in reg CTRL9_XL
  4698. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4699. *
  4700. */
  4701. int32_t lsm6ds3tr_c_den_mark_axis_z_set(stmdev_ctx_t *ctx,
  4702. uint8_t val)
  4703. {
  4704. lsm6ds3tr_c_ctrl9_xl_t ctrl9_xl;
  4705. int32_t ret;
  4706. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4707. (uint8_t *)&ctrl9_xl, 1);
  4708. if (ret == 0)
  4709. {
  4710. ctrl9_xl.den_z = val;
  4711. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4712. (uint8_t *)&ctrl9_xl, 1);
  4713. }
  4714. return ret;
  4715. }
  4716. /**
  4717. * @brief DEN value stored in LSB of Z-axis.[get]
  4718. *
  4719. * @param ctx Read / write interface definitions
  4720. * @param val Change the values of den_z in reg CTRL9_XL
  4721. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4722. *
  4723. */
  4724. int32_t lsm6ds3tr_c_den_mark_axis_z_get(stmdev_ctx_t *ctx,
  4725. uint8_t *val)
  4726. {
  4727. lsm6ds3tr_c_ctrl9_xl_t ctrl9_xl;
  4728. int32_t ret;
  4729. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4730. (uint8_t *)&ctrl9_xl, 1);
  4731. *val = ctrl9_xl.den_z;
  4732. return ret;
  4733. }
  4734. /**
  4735. * @brief DEN value stored in LSB of Y-axis.[set]
  4736. *
  4737. * @param ctx Read / write interface definitions
  4738. * @param val Change the values of den_y in reg CTRL9_XL
  4739. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4740. *
  4741. */
  4742. int32_t lsm6ds3tr_c_den_mark_axis_y_set(stmdev_ctx_t *ctx,
  4743. uint8_t val)
  4744. {
  4745. lsm6ds3tr_c_ctrl9_xl_t ctrl9_xl;
  4746. int32_t ret;
  4747. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4748. (uint8_t *)&ctrl9_xl, 1);
  4749. if (ret == 0)
  4750. {
  4751. ctrl9_xl.den_y = val;
  4752. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4753. (uint8_t *)&ctrl9_xl, 1);
  4754. }
  4755. return ret;
  4756. }
  4757. /**
  4758. * @brief DEN value stored in LSB of Y-axis.[get]
  4759. *
  4760. * @param ctx Read / write interface definitions
  4761. * @param val Change the values of den_y in reg CTRL9_XL
  4762. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4763. *
  4764. */
  4765. int32_t lsm6ds3tr_c_den_mark_axis_y_get(stmdev_ctx_t *ctx,
  4766. uint8_t *val)
  4767. {
  4768. lsm6ds3tr_c_ctrl9_xl_t ctrl9_xl;
  4769. int32_t ret;
  4770. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4771. (uint8_t *)&ctrl9_xl, 1);
  4772. *val = ctrl9_xl.den_y;
  4773. return ret;
  4774. }
  4775. /**
  4776. * @brief DEN value stored in LSB of X-axis.[set]
  4777. *
  4778. * @param ctx Read / write interface definitions
  4779. * @param val Change the values of den_x in reg CTRL9_XL
  4780. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4781. *
  4782. */
  4783. int32_t lsm6ds3tr_c_den_mark_axis_x_set(stmdev_ctx_t *ctx,
  4784. uint8_t val)
  4785. {
  4786. lsm6ds3tr_c_ctrl9_xl_t ctrl9_xl;
  4787. int32_t ret;
  4788. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4789. (uint8_t *)&ctrl9_xl, 1);
  4790. if (ret == 0)
  4791. {
  4792. ctrl9_xl.den_x = val;
  4793. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4794. (uint8_t *)&ctrl9_xl, 1);
  4795. }
  4796. return ret;
  4797. }
  4798. /**
  4799. * @brief DEN value stored in LSB of X-axis.[get]
  4800. *
  4801. * @param ctx Read / write interface definitions
  4802. * @param val Change the values of den_x in reg CTRL9_XL
  4803. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4804. *
  4805. */
  4806. int32_t lsm6ds3tr_c_den_mark_axis_x_get(stmdev_ctx_t *ctx,
  4807. uint8_t *val)
  4808. {
  4809. lsm6ds3tr_c_ctrl9_xl_t ctrl9_xl;
  4810. int32_t ret;
  4811. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  4812. (uint8_t *)&ctrl9_xl, 1);
  4813. *val = ctrl9_xl.den_x;
  4814. return ret;
  4815. }
  4816. /**
  4817. * @}
  4818. *
  4819. */
  4820. /**
  4821. * @defgroup LSM6DS3TR_C_Pedometer
  4822. * @brief This section groups all the functions that manage pedometer.
  4823. * @{
  4824. *
  4825. */
  4826. /**
  4827. * @brief Reset pedometer step counter.[set]
  4828. *
  4829. * @param ctx Read / write interface definitions
  4830. * @param val Change the values of pedo_rst_step in reg CTRL10_C
  4831. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4832. *
  4833. */
  4834. int32_t lsm6ds3tr_c_pedo_step_reset_set(stmdev_ctx_t *ctx,
  4835. uint8_t val)
  4836. {
  4837. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  4838. int32_t ret;
  4839. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  4840. (uint8_t *)&ctrl10_c, 1);
  4841. if (ret == 0)
  4842. {
  4843. ctrl10_c.pedo_rst_step = val;
  4844. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  4845. (uint8_t *)&ctrl10_c, 1);
  4846. }
  4847. return ret;
  4848. }
  4849. /**
  4850. * @brief Reset pedometer step counter.[get]
  4851. *
  4852. * @param ctx Read / write interface definitions
  4853. * @param val Change the values of pedo_rst_step in reg CTRL10_C
  4854. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4855. *
  4856. */
  4857. int32_t lsm6ds3tr_c_pedo_step_reset_get(stmdev_ctx_t *ctx,
  4858. uint8_t *val)
  4859. {
  4860. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  4861. int32_t ret;
  4862. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  4863. (uint8_t *)&ctrl10_c, 1);
  4864. *val = ctrl10_c.pedo_rst_step;
  4865. return ret;
  4866. }
  4867. /**
  4868. * @brief Enable pedometer algorithm.[set]
  4869. *
  4870. * @param ctx Read / write interface definitions
  4871. * @param val Change the values of pedo_en in reg CTRL10_C
  4872. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4873. *
  4874. */
  4875. int32_t lsm6ds3tr_c_pedo_sens_set(stmdev_ctx_t *ctx, uint8_t val)
  4876. {
  4877. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  4878. int32_t ret;
  4879. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  4880. (uint8_t *)&ctrl10_c, 1);
  4881. if (ret == 0)
  4882. {
  4883. ctrl10_c.pedo_en = val;
  4884. if (val != 0x00U)
  4885. {
  4886. ctrl10_c.func_en = val;
  4887. }
  4888. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  4889. (uint8_t *)&ctrl10_c, 1);
  4890. }
  4891. return ret;
  4892. }
  4893. /**
  4894. * @brief pedo_sens: Enable pedometer algorithm.[get]
  4895. *
  4896. * @param ctx Read / write interface definitions
  4897. * @param val Change the values of pedo_en in reg CTRL10_C
  4898. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4899. *
  4900. */
  4901. int32_t lsm6ds3tr_c_pedo_sens_get(stmdev_ctx_t *ctx, uint8_t *val)
  4902. {
  4903. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  4904. int32_t ret;
  4905. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  4906. (uint8_t *)&ctrl10_c, 1);
  4907. *val = ctrl10_c.pedo_en;
  4908. return ret;
  4909. }
  4910. /**
  4911. * @brief Minimum threshold to detect a peak. Default is 10h.[set]
  4912. *
  4913. * @param ctx Read / write interface definitions
  4914. * @param val Change the values of ths_min in reg
  4915. * CONFIG_PEDO_THS_MIN
  4916. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4917. *
  4918. */
  4919. int32_t lsm6ds3tr_c_pedo_threshold_set(stmdev_ctx_t *ctx, uint8_t val)
  4920. {
  4921. lsm6ds3tr_c_config_pedo_ths_min_t config_pedo_ths_min;
  4922. int32_t ret;
  4923. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  4924. if (ret == 0)
  4925. {
  4926. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CONFIG_PEDO_THS_MIN,
  4927. (uint8_t *)&config_pedo_ths_min, 1);
  4928. if (ret == 0)
  4929. {
  4930. config_pedo_ths_min.ths_min = val;
  4931. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CONFIG_PEDO_THS_MIN,
  4932. (uint8_t *)&config_pedo_ths_min, 1);
  4933. if (ret == 0)
  4934. {
  4935. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  4936. }
  4937. }
  4938. }
  4939. return ret;
  4940. }
  4941. /**
  4942. * @brief Minimum threshold to detect a peak. Default is 10h.[get]
  4943. *
  4944. * @param ctx Read / write interface definitions
  4945. * @param val Change the values of ths_min in reg CONFIG_PEDO_THS_MIN
  4946. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4947. *
  4948. */
  4949. int32_t lsm6ds3tr_c_pedo_threshold_get(stmdev_ctx_t *ctx,
  4950. uint8_t *val)
  4951. {
  4952. lsm6ds3tr_c_config_pedo_ths_min_t config_pedo_ths_min;
  4953. int32_t ret;
  4954. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  4955. if (ret == 0)
  4956. {
  4957. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CONFIG_PEDO_THS_MIN,
  4958. (uint8_t *)&config_pedo_ths_min, 1);
  4959. if (ret == 0)
  4960. {
  4961. *val = config_pedo_ths_min.ths_min;
  4962. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  4963. }
  4964. }
  4965. return ret;
  4966. }
  4967. /**
  4968. * @brief pedo_full_scale: Pedometer data range.[set]
  4969. *
  4970. * @param ctx Read / write interface definitions
  4971. * @param val Change the values of pedo_fs in
  4972. * reg CONFIG_PEDO_THS_MIN
  4973. * @retval Interface status (MANDATORY: return 0 -> no Error).
  4974. *
  4975. */
  4976. int32_t lsm6ds3tr_c_pedo_full_scale_set(stmdev_ctx_t *ctx,
  4977. lsm6ds3tr_c_pedo_fs_t val)
  4978. {
  4979. lsm6ds3tr_c_config_pedo_ths_min_t config_pedo_ths_min;
  4980. int32_t ret;
  4981. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  4982. if (ret == 0)
  4983. {
  4984. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CONFIG_PEDO_THS_MIN,
  4985. (uint8_t *)&config_pedo_ths_min, 1);
  4986. if (ret == 0)
  4987. {
  4988. config_pedo_ths_min.pedo_fs = (uint8_t) val;
  4989. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CONFIG_PEDO_THS_MIN,
  4990. (uint8_t *)&config_pedo_ths_min, 1);
  4991. if (ret == 0)
  4992. {
  4993. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  4994. }
  4995. }
  4996. }
  4997. return ret;
  4998. }
  4999. /**
  5000. * @brief Pedometer data range.[get]
  5001. *
  5002. * @param ctx Read / write interface definitions
  5003. * @param val Get the values of pedo_fs in
  5004. * reg CONFIG_PEDO_THS_MIN
  5005. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5006. *
  5007. */
  5008. int32_t lsm6ds3tr_c_pedo_full_scale_get(stmdev_ctx_t *ctx,
  5009. lsm6ds3tr_c_pedo_fs_t *val)
  5010. {
  5011. lsm6ds3tr_c_config_pedo_ths_min_t config_pedo_ths_min;
  5012. int32_t ret;
  5013. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5014. if (ret == 0)
  5015. {
  5016. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CONFIG_PEDO_THS_MIN,
  5017. (uint8_t *)&config_pedo_ths_min, 1);
  5018. if (ret == 0)
  5019. {
  5020. switch (config_pedo_ths_min.pedo_fs)
  5021. {
  5022. case LSM6DS3TR_C_PEDO_AT_2g:
  5023. *val = LSM6DS3TR_C_PEDO_AT_2g;
  5024. break;
  5025. case LSM6DS3TR_C_PEDO_AT_4g:
  5026. *val = LSM6DS3TR_C_PEDO_AT_4g;
  5027. break;
  5028. default:
  5029. *val = LSM6DS3TR_C_PEDO_FS_ND;
  5030. break;
  5031. }
  5032. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5033. }
  5034. }
  5035. return ret;
  5036. }
  5037. /**
  5038. * @brief Pedometer debounce configuration register (r/w).[set]
  5039. *
  5040. * @param ctx Read / write interface definitions
  5041. * @param val Change the values of deb_step in reg PEDO_DEB_REG
  5042. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5043. *
  5044. */
  5045. int32_t lsm6ds3tr_c_pedo_debounce_steps_set(stmdev_ctx_t *ctx,
  5046. uint8_t val)
  5047. {
  5048. lsm6ds3tr_c_pedo_deb_reg_t pedo_deb_reg;
  5049. int32_t ret;
  5050. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5051. if (ret == 0)
  5052. {
  5053. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_PEDO_DEB_REG,
  5054. (uint8_t *)&pedo_deb_reg, 1);
  5055. if (ret == 0)
  5056. {
  5057. pedo_deb_reg.deb_step = val;
  5058. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_PEDO_DEB_REG,
  5059. (uint8_t *)&pedo_deb_reg, 1);
  5060. if (ret == 0)
  5061. {
  5062. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5063. }
  5064. }
  5065. }
  5066. return ret;
  5067. }
  5068. /**
  5069. * @brief Pedometer debounce configuration register (r/w).[get]
  5070. *
  5071. * @param ctx Read / write interface definitions
  5072. * @param val Change the values of deb_step in reg PEDO_DEB_REG
  5073. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5074. *
  5075. */
  5076. int32_t lsm6ds3tr_c_pedo_debounce_steps_get(stmdev_ctx_t *ctx,
  5077. uint8_t *val)
  5078. {
  5079. lsm6ds3tr_c_pedo_deb_reg_t pedo_deb_reg;
  5080. int32_t ret;
  5081. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5082. if (ret == 0)
  5083. {
  5084. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_PEDO_DEB_REG,
  5085. (uint8_t *)&pedo_deb_reg, 1);
  5086. if (ret == 0)
  5087. {
  5088. *val = pedo_deb_reg.deb_step;
  5089. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5090. }
  5091. }
  5092. return ret;
  5093. }
  5094. /**
  5095. * @brief Debounce time. If the time between two consecutive steps is
  5096. * greater than DEB_TIME*80ms, the debouncer is reactivated.
  5097. * Default value: 01101[set]
  5098. *
  5099. * @param ctx Read / write interface definitions
  5100. * @param val Change the values of deb_time in reg PEDO_DEB_REG
  5101. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5102. *
  5103. */
  5104. int32_t lsm6ds3tr_c_pedo_timeout_set(stmdev_ctx_t *ctx, uint8_t val)
  5105. {
  5106. lsm6ds3tr_c_pedo_deb_reg_t pedo_deb_reg;
  5107. int32_t ret;
  5108. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5109. if (ret == 0)
  5110. {
  5111. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_PEDO_DEB_REG,
  5112. (uint8_t *)&pedo_deb_reg, 1);
  5113. if (ret == 0)
  5114. {
  5115. pedo_deb_reg.deb_time = val;
  5116. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_PEDO_DEB_REG,
  5117. (uint8_t *)&pedo_deb_reg, 1);
  5118. if (ret == 0)
  5119. {
  5120. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5121. }
  5122. }
  5123. }
  5124. return ret;
  5125. }
  5126. /**
  5127. * @brief Debounce time. If the time between two consecutive steps is
  5128. * greater than DEB_TIME*80ms, the debouncer is reactivated.
  5129. * Default value: 01101[get]
  5130. *
  5131. * @param ctx Read / write interface definitions
  5132. * @param val Change the values of deb_time in reg PEDO_DEB_REG
  5133. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5134. *
  5135. */
  5136. int32_t lsm6ds3tr_c_pedo_timeout_get(stmdev_ctx_t *ctx, uint8_t *val)
  5137. {
  5138. lsm6ds3tr_c_pedo_deb_reg_t pedo_deb_reg;
  5139. int32_t ret;
  5140. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5141. if (ret == 0)
  5142. {
  5143. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_PEDO_DEB_REG,
  5144. (uint8_t *)&pedo_deb_reg, 1);
  5145. if (ret == 0)
  5146. {
  5147. *val = pedo_deb_reg.deb_time;
  5148. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5149. }
  5150. }
  5151. return ret;
  5152. }
  5153. /**
  5154. * @brief Time period register for step detection on delta time (r/w).[set]
  5155. *
  5156. * @param ctx Read / write interface definitions
  5157. * @param buff Buffer that contains data to write
  5158. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5159. *
  5160. */
  5161. int32_t lsm6ds3tr_c_pedo_steps_period_set(stmdev_ctx_t *ctx,
  5162. uint8_t *buff)
  5163. {
  5164. int32_t ret;
  5165. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5166. if (ret == 0)
  5167. {
  5168. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_STEP_COUNT_DELTA, buff, 1);
  5169. if (ret == 0)
  5170. {
  5171. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5172. }
  5173. }
  5174. return ret;
  5175. }
  5176. /**
  5177. * @brief Time period register for step detection on delta time (r/w).[get]
  5178. *
  5179. * @param ctx Read / write interface definitions
  5180. * @param buff Buffer that stores data read
  5181. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5182. *
  5183. */
  5184. int32_t lsm6ds3tr_c_pedo_steps_period_get(stmdev_ctx_t *ctx,
  5185. uint8_t *buff)
  5186. {
  5187. int32_t ret;
  5188. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5189. if (ret == 0)
  5190. {
  5191. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_STEP_COUNT_DELTA, buff, 1);
  5192. if (ret == 0)
  5193. {
  5194. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5195. }
  5196. }
  5197. return ret;
  5198. }
  5199. /**
  5200. * @}
  5201. *
  5202. */
  5203. /**
  5204. * @defgroup LSM6DS3TR_C_significant_motion
  5205. * @brief This section groups all the functions that manage the
  5206. * significant motion detection.
  5207. * @{
  5208. *
  5209. */
  5210. /**
  5211. * @brief Enable significant motion detection function.[set]
  5212. *
  5213. * @param ctx Read / write interface definitions
  5214. * @param val Change the values of sign_motion_en in reg CTRL10_C
  5215. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5216. *
  5217. */
  5218. int32_t lsm6ds3tr_c_motion_sens_set(stmdev_ctx_t *ctx, uint8_t val)
  5219. {
  5220. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  5221. int32_t ret;
  5222. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5223. (uint8_t *)&ctrl10_c, 1);
  5224. if (ret == 0)
  5225. {
  5226. ctrl10_c.sign_motion_en = val;
  5227. if (val != 0x00U)
  5228. {
  5229. ctrl10_c.func_en = val;
  5230. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5231. (uint8_t *)&ctrl10_c, 1);
  5232. }
  5233. }
  5234. return ret;
  5235. }
  5236. /**
  5237. * @brief Enable significant motion detection function.[get]
  5238. *
  5239. * @param ctx Read / write interface definitions
  5240. * @param val Change the values of sign_motion_en in reg CTRL10_C
  5241. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5242. *
  5243. */
  5244. int32_t lsm6ds3tr_c_motion_sens_get(stmdev_ctx_t *ctx, uint8_t *val)
  5245. {
  5246. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  5247. int32_t ret;
  5248. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5249. (uint8_t *)&ctrl10_c, 1);
  5250. *val = ctrl10_c.sign_motion_en;
  5251. return ret;
  5252. }
  5253. /**
  5254. * @brief Significant motion threshold.[set]
  5255. *
  5256. * @param ctx Read / write interface definitions
  5257. * @param buff Buffer that store significant motion threshold.
  5258. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5259. *
  5260. */
  5261. int32_t lsm6ds3tr_c_motion_threshold_set(stmdev_ctx_t *ctx,
  5262. uint8_t *buff)
  5263. {
  5264. int32_t ret;
  5265. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5266. if (ret == 0)
  5267. {
  5268. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SM_THS, buff, 1);
  5269. if (ret == 0)
  5270. {
  5271. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5272. }
  5273. }
  5274. return ret;
  5275. }
  5276. /**
  5277. * @brief Significant motion threshold.[get]
  5278. *
  5279. * @param ctx Read / write interface definitions
  5280. * @param buff Buffer that store significant motion threshold.
  5281. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5282. *
  5283. */
  5284. int32_t lsm6ds3tr_c_motion_threshold_get(stmdev_ctx_t *ctx,
  5285. uint8_t *buff)
  5286. {
  5287. int32_t ret;
  5288. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5289. if (ret == 0)
  5290. {
  5291. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SM_THS, buff, 1);
  5292. if (ret == 0)
  5293. {
  5294. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5295. }
  5296. }
  5297. return ret;
  5298. }
  5299. /**
  5300. * @}
  5301. *
  5302. */
  5303. /**
  5304. * @defgroup LSM6DS3TR_C_tilt_detection
  5305. * @brief This section groups all the functions that manage the tilt
  5306. * event detection.
  5307. * @{
  5308. *
  5309. */
  5310. /**
  5311. * @brief Enable tilt calculation.[set]
  5312. *
  5313. * @param ctx Read / write interface definitions
  5314. * @param val Change the values of tilt_en in reg CTRL10_C
  5315. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5316. *
  5317. */
  5318. int32_t lsm6ds3tr_c_tilt_sens_set(stmdev_ctx_t *ctx, uint8_t val)
  5319. {
  5320. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  5321. int32_t ret;
  5322. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5323. (uint8_t *)&ctrl10_c, 1);
  5324. if (ret == 0)
  5325. {
  5326. ctrl10_c.tilt_en = val;
  5327. if (val != 0x00U)
  5328. {
  5329. ctrl10_c.func_en = val;
  5330. }
  5331. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5332. (uint8_t *)&ctrl10_c, 1);
  5333. }
  5334. return ret;
  5335. }
  5336. /**
  5337. * @brief Enable tilt calculation.[get]
  5338. *
  5339. * @param ctx Read / write interface definitions
  5340. * @param val Change the values of tilt_en in reg CTRL10_C
  5341. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5342. *
  5343. */
  5344. int32_t lsm6ds3tr_c_tilt_sens_get(stmdev_ctx_t *ctx, uint8_t *val)
  5345. {
  5346. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  5347. int32_t ret;
  5348. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5349. (uint8_t *)&ctrl10_c, 1);
  5350. *val = ctrl10_c.tilt_en;
  5351. return ret;
  5352. }
  5353. /**
  5354. * @brief Enable tilt calculation.[set]
  5355. *
  5356. * @param ctx Read / write interface definitions
  5357. * @param val Change the values of tilt_en in reg CTRL10_C
  5358. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5359. *
  5360. */
  5361. int32_t lsm6ds3tr_c_wrist_tilt_sens_set(stmdev_ctx_t *ctx,
  5362. uint8_t val)
  5363. {
  5364. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  5365. int32_t ret;
  5366. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5367. (uint8_t *)&ctrl10_c, 1);
  5368. if (ret == 0)
  5369. {
  5370. ctrl10_c.wrist_tilt_en = val;
  5371. if (val != 0x00U)
  5372. {
  5373. ctrl10_c.func_en = val;
  5374. }
  5375. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5376. (uint8_t *)&ctrl10_c, 1);
  5377. }
  5378. return ret;
  5379. }
  5380. /**
  5381. * @brief Enable tilt calculation.[get]
  5382. *
  5383. * @param ctx Read / write interface definitions
  5384. * @param val Change the values of tilt_en in reg CTRL10_C
  5385. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5386. *
  5387. */
  5388. int32_t lsm6ds3tr_c_wrist_tilt_sens_get(stmdev_ctx_t *ctx,
  5389. uint8_t *val)
  5390. {
  5391. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  5392. int32_t ret;
  5393. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5394. (uint8_t *)&ctrl10_c, 1);
  5395. *val = ctrl10_c.wrist_tilt_en;
  5396. return ret;
  5397. }
  5398. /**
  5399. * @brief Absolute Wrist Tilt latency register (r/w).
  5400. * Absolute wrist tilt latency parameters.
  5401. * 1 LSB = 40 ms. Default value: 0Fh (600 ms).[set]
  5402. *
  5403. * @param ctx Read / write interface definitions
  5404. * @param buff Buffer that contains data to write
  5405. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5406. *
  5407. */
  5408. int32_t lsm6ds3tr_c_tilt_latency_set(stmdev_ctx_t *ctx, uint8_t *buff)
  5409. {
  5410. int32_t ret;
  5411. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_B);
  5412. if (ret == 0)
  5413. {
  5414. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_A_WRIST_TILT_LAT, buff, 1);
  5415. if (ret == 0)
  5416. {
  5417. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5418. }
  5419. }
  5420. return ret;
  5421. }
  5422. /**
  5423. * @brief Absolute Wrist Tilt latency register (r/w).
  5424. * Absolute wrist tilt latency parameters.
  5425. * 1 LSB = 40 ms. Default value: 0Fh (600 ms).[get]
  5426. *
  5427. * @param ctx Read / write interface definitions
  5428. * @param buff Buffer that stores data read
  5429. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5430. *
  5431. */
  5432. int32_t lsm6ds3tr_c_tilt_latency_get(stmdev_ctx_t *ctx, uint8_t *buff)
  5433. {
  5434. int32_t ret;
  5435. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_B);
  5436. if (ret == 0)
  5437. {
  5438. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_A_WRIST_TILT_LAT, buff, 1);
  5439. if (ret == 0)
  5440. {
  5441. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5442. }
  5443. }
  5444. return ret;
  5445. }
  5446. /**
  5447. * @brief Absolute Wrist Tilt threshold register(r/w).
  5448. * Absolute wrist tilt threshold parameters.
  5449. * 1 LSB = 15.625 mg.Default value: 20h (500 mg).[set]
  5450. *
  5451. * @param ctx Read / write interface definitions
  5452. * @param buff Buffer that contains data to write
  5453. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5454. *
  5455. */
  5456. int32_t lsm6ds3tr_c_tilt_threshold_set(stmdev_ctx_t *ctx,
  5457. uint8_t *buff)
  5458. {
  5459. int32_t ret;
  5460. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_B);
  5461. if (ret == 0)
  5462. {
  5463. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_A_WRIST_TILT_THS, buff, 1);
  5464. if (ret == 0)
  5465. {
  5466. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5467. }
  5468. }
  5469. return ret;
  5470. }
  5471. /**
  5472. * @brief Absolute Wrist Tilt threshold register(r/w).
  5473. * Absolute wrist tilt threshold parameters.
  5474. * 1 LSB = 15.625 mg.Default value: 20h (500 mg).[get]
  5475. *
  5476. * @param ctx Read / write interface definitions
  5477. * @param buff Buffer that stores data read
  5478. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5479. *
  5480. */
  5481. int32_t lsm6ds3tr_c_tilt_threshold_get(stmdev_ctx_t *ctx,
  5482. uint8_t *buff)
  5483. {
  5484. int32_t ret;
  5485. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_B);
  5486. if (ret == 0)
  5487. {
  5488. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_A_WRIST_TILT_THS, buff, 1);
  5489. if (ret == 0)
  5490. {
  5491. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5492. }
  5493. }
  5494. return ret;
  5495. }
  5496. /**
  5497. * @brief Absolute Wrist Tilt mask register (r/w).[set]
  5498. *
  5499. * @param ctx Read / write interface definitions
  5500. * @param val Registers A_WRIST_TILT_MASK
  5501. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5502. *
  5503. */
  5504. int32_t lsm6ds3tr_c_tilt_src_set(stmdev_ctx_t *ctx,
  5505. lsm6ds3tr_c_a_wrist_tilt_mask_t *val)
  5506. {
  5507. int32_t ret;
  5508. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_B);
  5509. if (ret == 0)
  5510. {
  5511. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_A_WRIST_TILT_MASK,
  5512. (uint8_t *) val, 1);
  5513. if (ret == 0)
  5514. {
  5515. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5516. }
  5517. }
  5518. return ret;
  5519. }
  5520. /**
  5521. * @brief Absolute Wrist Tilt mask register (r/w).[get]
  5522. *
  5523. * @param ctx Read / write interface definitions
  5524. * @param val Registers A_WRIST_TILT_MASK
  5525. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5526. *
  5527. */
  5528. int32_t lsm6ds3tr_c_tilt_src_get(stmdev_ctx_t *ctx,
  5529. lsm6ds3tr_c_a_wrist_tilt_mask_t *val)
  5530. {
  5531. int32_t ret;
  5532. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_B);
  5533. if (ret == 0)
  5534. {
  5535. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_A_WRIST_TILT_MASK,
  5536. (uint8_t *) val, 1);
  5537. if (ret == 0)
  5538. {
  5539. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5540. }
  5541. }
  5542. return ret;
  5543. }
  5544. /**
  5545. * @}
  5546. *
  5547. */
  5548. /**
  5549. * @defgroup LSM6DS3TR_C_ magnetometer_sensor
  5550. * @brief This section groups all the functions that manage additional
  5551. * magnetometer sensor.
  5552. * @{
  5553. *
  5554. */
  5555. /**
  5556. * @brief Enable soft-iron correction algorithm for magnetometer.[set]
  5557. *
  5558. * @param ctx Read / write interface definitions
  5559. * @param val Change the values of soft_en in reg CTRL9_XL
  5560. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5561. *
  5562. */
  5563. int32_t lsm6ds3tr_c_mag_soft_iron_set(stmdev_ctx_t *ctx, uint8_t val)
  5564. {
  5565. lsm6ds3tr_c_ctrl9_xl_t ctrl9_xl;
  5566. int32_t ret;
  5567. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  5568. (uint8_t *)&ctrl9_xl, 1);
  5569. if (ret == 0)
  5570. {
  5571. ctrl9_xl.soft_en = val;
  5572. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  5573. (uint8_t *)&ctrl9_xl, 1);
  5574. }
  5575. return ret;
  5576. }
  5577. /**
  5578. * @brief Enable soft-iron correction algorithm for magnetometer.[get]
  5579. *
  5580. * @param ctx Read / write interface definitions
  5581. * @param val Change the values of soft_en in reg CTRL9_XL
  5582. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5583. *
  5584. */
  5585. int32_t lsm6ds3tr_c_mag_soft_iron_get(stmdev_ctx_t *ctx, uint8_t *val)
  5586. {
  5587. lsm6ds3tr_c_ctrl9_xl_t ctrl9_xl;
  5588. int32_t ret;
  5589. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL9_XL,
  5590. (uint8_t *)&ctrl9_xl, 1);
  5591. *val = ctrl9_xl.soft_en;
  5592. return ret;
  5593. }
  5594. /**
  5595. * @brief Enable hard-iron correction algorithm for magnetometer.[set]
  5596. *
  5597. * @param ctx Read / write interface definitions
  5598. * @param val Change the values of iron_en in reg MASTER_CONFIG
  5599. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5600. *
  5601. */
  5602. int32_t lsm6ds3tr_c_mag_hard_iron_set(stmdev_ctx_t *ctx, uint8_t val)
  5603. {
  5604. lsm6ds3tr_c_master_config_t master_config;
  5605. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  5606. int32_t ret;
  5607. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  5608. (uint8_t *)&master_config, 1);
  5609. if (ret == 0)
  5610. {
  5611. master_config.iron_en = val;
  5612. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  5613. (uint8_t *)&master_config, 1);
  5614. if (ret == 0)
  5615. {
  5616. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5617. (uint8_t *)&ctrl10_c, 1);
  5618. if (ret == 0)
  5619. {
  5620. if (val != 0x00U)
  5621. {
  5622. ctrl10_c.func_en = val;
  5623. }
  5624. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5625. (uint8_t *)&ctrl10_c, 1);
  5626. }
  5627. }
  5628. }
  5629. return ret;
  5630. }
  5631. /**
  5632. * @brief Enable hard-iron correction algorithm for magnetometer.[get]
  5633. *
  5634. * @param ctx Read / write interface definitions
  5635. * @param val Change the values of iron_en in reg MASTER_CONFIG
  5636. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5637. *
  5638. */
  5639. int32_t lsm6ds3tr_c_mag_hard_iron_get(stmdev_ctx_t *ctx, uint8_t *val)
  5640. {
  5641. lsm6ds3tr_c_master_config_t master_config;
  5642. int32_t ret;
  5643. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  5644. (uint8_t *)&master_config, 1);
  5645. *val = master_config.iron_en;
  5646. return ret;
  5647. }
  5648. /**
  5649. * @brief Soft iron 3x3 matrix. Value are expressed in sign-module format.
  5650. * (Es. SVVVVVVVb where S is the sign 0/+1/- and V is the value).[set]
  5651. *
  5652. * @param ctx Read / write interface definitions
  5653. * @param buff Buffer that contains data to write
  5654. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5655. *
  5656. */
  5657. int32_t lsm6ds3tr_c_mag_soft_iron_mat_set(stmdev_ctx_t *ctx,
  5658. uint8_t *buff)
  5659. {
  5660. int32_t ret;
  5661. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5662. if (ret == 0)
  5663. {
  5664. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MAG_SI_XX, buff, 9);
  5665. if (ret == 0)
  5666. {
  5667. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5668. }
  5669. }
  5670. return ret;
  5671. }
  5672. /**
  5673. * @brief Soft iron 3x3 matrix. Value are expressed in sign-module format.
  5674. * (Es. SVVVVVVVb where S is the sign 0/+1/- and V is the value).[get]
  5675. *
  5676. * @param ctx Read / write interface definitions
  5677. * @param buff Buffer that stores data read
  5678. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5679. *
  5680. */
  5681. int32_t lsm6ds3tr_c_mag_soft_iron_mat_get(stmdev_ctx_t *ctx,
  5682. uint8_t *buff)
  5683. {
  5684. int32_t ret;
  5685. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5686. if (ret == 0)
  5687. {
  5688. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MAG_SI_XX, buff, 9);
  5689. if (ret == 0)
  5690. {
  5691. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5692. }
  5693. }
  5694. return ret;
  5695. }
  5696. /**
  5697. * @brief Offset for hard-iron compensation register (r/w). The value is
  5698. * expressed as a 16-bit word in two’s complement.[set]
  5699. *
  5700. * @param ctx Read / write interface definitions
  5701. * @param buff Buffer that contains data to write
  5702. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5703. *
  5704. */
  5705. int32_t lsm6ds3tr_c_mag_offset_set(stmdev_ctx_t *ctx, int16_t *val)
  5706. {
  5707. uint8_t buff[6];
  5708. int32_t ret;
  5709. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5710. if (ret == 0)
  5711. {
  5712. buff[1] = (uint8_t)((uint16_t)val[0] / 256U);
  5713. buff[0] = (uint8_t)((uint16_t)val[0] - (buff[1] * 256U));
  5714. buff[3] = (uint8_t)((uint16_t)val[1] / 256U);
  5715. buff[2] = (uint8_t)((uint16_t)val[1] - (buff[3] * 256U));
  5716. buff[5] = (uint8_t)((uint16_t)val[2] / 256U);
  5717. buff[4] = (uint8_t)((uint16_t)val[2] - (buff[5] * 256U));
  5718. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MAG_OFFX_L, buff, 6);
  5719. if (ret == 0)
  5720. {
  5721. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5722. }
  5723. }
  5724. return ret;
  5725. }
  5726. /**
  5727. * @brief Offset for hard-iron compensation register(r/w).
  5728. * The value is expressed as a 16-bit word in two’s complement.[get]
  5729. *
  5730. * @param ctx Read / write interface definitions
  5731. * @param buff Buffer that stores data read
  5732. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5733. *
  5734. */
  5735. int32_t lsm6ds3tr_c_mag_offset_get(stmdev_ctx_t *ctx, int16_t *val)
  5736. {
  5737. uint8_t buff[6];
  5738. int32_t ret;
  5739. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  5740. if (ret == 0)
  5741. {
  5742. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MAG_OFFX_L, buff, 6);
  5743. if (ret == 0)
  5744. {
  5745. val[0] = (int16_t)buff[1];
  5746. val[0] = (val[0] * 256) + (int16_t)buff[0];
  5747. val[1] = (int16_t)buff[3];
  5748. val[1] = (val[1] * 256) + (int16_t)buff[2];
  5749. val[2] = (int16_t)buff[5];
  5750. val[2] = (val[2] * 256) + (int16_t)buff[4];
  5751. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  5752. }
  5753. }
  5754. return ret;
  5755. }
  5756. /**
  5757. * @}
  5758. *
  5759. */
  5760. /**
  5761. * @defgroup LSM6DS3TR_C_Sensor_hub
  5762. * @brief This section groups all the functions that manage the sensor
  5763. * hub functionality.
  5764. * @{
  5765. *
  5766. */
  5767. /**
  5768. * @brief Enable function.[set]
  5769. *
  5770. * @param ctx Read / write interface definitions
  5771. * @param val Change the values func_en
  5772. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5773. *
  5774. */
  5775. int32_t lsm6ds3tr_c_func_en_set(stmdev_ctx_t *ctx, uint8_t val)
  5776. {
  5777. lsm6ds3tr_c_ctrl10_c_t ctrl10_c;
  5778. int32_t ret;
  5779. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5780. (uint8_t *)&ctrl10_c, 1);
  5781. if (ret == 0)
  5782. {
  5783. ctrl10_c.func_en = val;
  5784. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_CTRL10_C,
  5785. (uint8_t *)&ctrl10_c, 1);
  5786. }
  5787. return ret;
  5788. }
  5789. /**
  5790. * @brief Sensor synchronization time frame with the step of 500 ms and
  5791. * full range of 5s. Unsigned 8-bit.[set]
  5792. *
  5793. * @param ctx Read / write interface definitions
  5794. * @param val Change the values of tph in reg SENSOR_SYNC_TIME_FRAME
  5795. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5796. *
  5797. */
  5798. int32_t lsm6ds3tr_c_sh_sync_sens_frame_set(stmdev_ctx_t *ctx,
  5799. uint8_t val)
  5800. {
  5801. lsm6ds3tr_c_sensor_sync_time_frame_t sensor_sync_time_frame;
  5802. int32_t ret;
  5803. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SENSOR_SYNC_TIME_FRAME,
  5804. (uint8_t *)&sensor_sync_time_frame, 1);
  5805. if (ret == 0)
  5806. {
  5807. sensor_sync_time_frame.tph = val;
  5808. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SENSOR_SYNC_TIME_FRAME,
  5809. (uint8_t *)&sensor_sync_time_frame, 1);
  5810. }
  5811. return ret;
  5812. }
  5813. /**
  5814. * @brief Sensor synchronization time frame with the step of 500 ms and
  5815. * full range of 5s. Unsigned 8-bit.[get]
  5816. *
  5817. * @param ctx Read / write interface definitions
  5818. * @param val Change the values of tph in reg SENSOR_SYNC_TIME_FRAME
  5819. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5820. *
  5821. */
  5822. int32_t lsm6ds3tr_c_sh_sync_sens_frame_get(stmdev_ctx_t *ctx,
  5823. uint8_t *val)
  5824. {
  5825. lsm6ds3tr_c_sensor_sync_time_frame_t sensor_sync_time_frame;
  5826. int32_t ret;
  5827. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SENSOR_SYNC_TIME_FRAME,
  5828. (uint8_t *)&sensor_sync_time_frame, 1);
  5829. *val = sensor_sync_time_frame.tph;
  5830. return ret;
  5831. }
  5832. /**
  5833. * @brief Resolution ratio of error code for sensor synchronization.[set]
  5834. *
  5835. * @param ctx Read / write interface definitions
  5836. * @param val Change the values of rr in reg SENSOR_SYNC_RES_RATIO
  5837. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5838. *
  5839. */
  5840. int32_t lsm6ds3tr_c_sh_sync_sens_ratio_set(stmdev_ctx_t *ctx,
  5841. lsm6ds3tr_c_rr_t val)
  5842. {
  5843. lsm6ds3tr_c_sensor_sync_res_ratio_t sensor_sync_res_ratio;
  5844. int32_t ret;
  5845. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SENSOR_SYNC_RES_RATIO,
  5846. (uint8_t *)&sensor_sync_res_ratio, 1);
  5847. if (ret == 0)
  5848. {
  5849. sensor_sync_res_ratio.rr = (uint8_t) val;
  5850. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SENSOR_SYNC_RES_RATIO,
  5851. (uint8_t *)&sensor_sync_res_ratio, 1);
  5852. }
  5853. return ret;
  5854. }
  5855. /**
  5856. * @brief Resolution ratio of error code for sensor synchronization.[get]
  5857. *
  5858. * @param ctx Read / write interface definitions
  5859. * @param val Get the values of rr in reg SENSOR_SYNC_RES_RATIO
  5860. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5861. *
  5862. */
  5863. int32_t lsm6ds3tr_c_sh_sync_sens_ratio_get(stmdev_ctx_t *ctx,
  5864. lsm6ds3tr_c_rr_t *val)
  5865. {
  5866. lsm6ds3tr_c_sensor_sync_res_ratio_t sensor_sync_res_ratio;
  5867. int32_t ret;
  5868. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SENSOR_SYNC_RES_RATIO,
  5869. (uint8_t *)&sensor_sync_res_ratio, 1);
  5870. switch (sensor_sync_res_ratio.rr)
  5871. {
  5872. case LSM6DS3TR_C_RES_RATIO_2_11:
  5873. *val = LSM6DS3TR_C_RES_RATIO_2_11;
  5874. break;
  5875. case LSM6DS3TR_C_RES_RATIO_2_12:
  5876. *val = LSM6DS3TR_C_RES_RATIO_2_12;
  5877. break;
  5878. case LSM6DS3TR_C_RES_RATIO_2_13:
  5879. *val = LSM6DS3TR_C_RES_RATIO_2_13;
  5880. break;
  5881. case LSM6DS3TR_C_RES_RATIO_2_14:
  5882. *val = LSM6DS3TR_C_RES_RATIO_2_14;
  5883. break;
  5884. default:
  5885. *val = LSM6DS3TR_C_RES_RATIO_ND;
  5886. break;
  5887. }
  5888. return ret;
  5889. }
  5890. /**
  5891. * @brief Sensor hub I2C master enable.[set]
  5892. *
  5893. * @param ctx Read / write interface definitions
  5894. * @param val Change the values of master_on in reg MASTER_CONFIG
  5895. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5896. *
  5897. */
  5898. int32_t lsm6ds3tr_c_sh_master_set(stmdev_ctx_t *ctx, uint8_t val)
  5899. {
  5900. lsm6ds3tr_c_master_config_t master_config;
  5901. int32_t ret;
  5902. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  5903. (uint8_t *)&master_config, 1);
  5904. if (ret == 0)
  5905. {
  5906. master_config.master_on = val;
  5907. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  5908. (uint8_t *)&master_config, 1);
  5909. }
  5910. return ret;
  5911. }
  5912. /**
  5913. * @brief Sensor hub I2C master enable.[get]
  5914. *
  5915. * @param ctx Read / write interface definitions
  5916. * @param val Change the values of master_on in reg MASTER_CONFIG
  5917. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5918. *
  5919. */
  5920. int32_t lsm6ds3tr_c_sh_master_get(stmdev_ctx_t *ctx, uint8_t *val)
  5921. {
  5922. lsm6ds3tr_c_master_config_t master_config;
  5923. int32_t ret;
  5924. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  5925. (uint8_t *)&master_config, 1);
  5926. *val = master_config.master_on;
  5927. return ret;
  5928. }
  5929. /**
  5930. * @brief I2C interface pass-through.[set]
  5931. *
  5932. * @param ctx Read / write interface definitions
  5933. * @param val Change the values of pass_through_mode in reg MASTER_CONFIG
  5934. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5935. *
  5936. */
  5937. int32_t lsm6ds3tr_c_sh_pass_through_set(stmdev_ctx_t *ctx,
  5938. uint8_t val)
  5939. {
  5940. lsm6ds3tr_c_master_config_t master_config;
  5941. int32_t ret;
  5942. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  5943. (uint8_t *)&master_config, 1);
  5944. if (ret == 0)
  5945. {
  5946. master_config.pass_through_mode = val;
  5947. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  5948. (uint8_t *)&master_config, 1);
  5949. }
  5950. return ret;
  5951. }
  5952. /**
  5953. * @brief I2C interface pass-through.[get]
  5954. *
  5955. * @param ctx Read / write interface definitions
  5956. * @param val Change the values of pass_through_mode in reg MASTER_CONFIG
  5957. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5958. *
  5959. */
  5960. int32_t lsm6ds3tr_c_sh_pass_through_get(stmdev_ctx_t *ctx,
  5961. uint8_t *val)
  5962. {
  5963. lsm6ds3tr_c_master_config_t master_config;
  5964. int32_t ret;
  5965. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  5966. (uint8_t *)&master_config, 1);
  5967. *val = master_config.pass_through_mode;
  5968. return ret;
  5969. }
  5970. /**
  5971. * @brief Master I2C pull-up enable/disable.[set]
  5972. *
  5973. * @param ctx Read / write interface definitions
  5974. * @param val Change the values of pull_up_en in reg MASTER_CONFIG
  5975. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5976. *
  5977. */
  5978. int32_t lsm6ds3tr_c_sh_pin_mode_set(stmdev_ctx_t *ctx,
  5979. lsm6ds3tr_c_pull_up_en_t val)
  5980. {
  5981. lsm6ds3tr_c_master_config_t master_config;
  5982. int32_t ret;
  5983. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  5984. (uint8_t *)&master_config, 1);
  5985. if (ret == 0)
  5986. {
  5987. master_config.pull_up_en = (uint8_t) val;
  5988. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  5989. (uint8_t *)&master_config, 1);
  5990. }
  5991. return ret;
  5992. }
  5993. /**
  5994. * @brief Master I2C pull-up enable/disable.[get]
  5995. *
  5996. * @param ctx Read / write interface definitions
  5997. * @param val Get the values of pull_up_en in reg MASTER_CONFIG
  5998. * @retval Interface status (MANDATORY: return 0 -> no Error).
  5999. *
  6000. */
  6001. int32_t lsm6ds3tr_c_sh_pin_mode_get(stmdev_ctx_t *ctx,
  6002. lsm6ds3tr_c_pull_up_en_t *val)
  6003. {
  6004. lsm6ds3tr_c_master_config_t master_config;
  6005. int32_t ret;
  6006. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  6007. (uint8_t *)&master_config, 1);
  6008. switch (master_config.pull_up_en)
  6009. {
  6010. case LSM6DS3TR_C_EXT_PULL_UP:
  6011. *val = LSM6DS3TR_C_EXT_PULL_UP;
  6012. break;
  6013. case LSM6DS3TR_C_INTERNAL_PULL_UP:
  6014. *val = LSM6DS3TR_C_INTERNAL_PULL_UP;
  6015. break;
  6016. default:
  6017. *val = LSM6DS3TR_C_SH_PIN_MODE;
  6018. break;
  6019. }
  6020. return ret;
  6021. }
  6022. /**
  6023. * @brief Sensor hub trigger signal selection.[set]
  6024. *
  6025. * @param ctx Read / write interface definitions
  6026. * @param val Change the values of start_config in reg MASTER_CONFIG
  6027. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6028. *
  6029. */
  6030. int32_t lsm6ds3tr_c_sh_syncro_mode_set(stmdev_ctx_t *ctx,
  6031. lsm6ds3tr_c_start_config_t val)
  6032. {
  6033. lsm6ds3tr_c_master_config_t master_config;
  6034. int32_t ret;
  6035. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  6036. (uint8_t *)&master_config, 1);
  6037. if (ret == 0)
  6038. {
  6039. master_config.start_config = (uint8_t)val;
  6040. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  6041. (uint8_t *)&master_config, 1);
  6042. }
  6043. return ret;
  6044. }
  6045. /**
  6046. * @brief Sensor hub trigger signal selection.[get]
  6047. *
  6048. * @param ctx Read / write interface definitions
  6049. * @param val Get the values of start_config in reg MASTER_CONFIG
  6050. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6051. *
  6052. */
  6053. int32_t lsm6ds3tr_c_sh_syncro_mode_get(stmdev_ctx_t *ctx,
  6054. lsm6ds3tr_c_start_config_t *val)
  6055. {
  6056. lsm6ds3tr_c_master_config_t master_config;
  6057. int32_t ret;
  6058. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  6059. (uint8_t *)&master_config, 1);
  6060. switch (master_config.start_config)
  6061. {
  6062. case LSM6DS3TR_C_XL_GY_DRDY:
  6063. *val = LSM6DS3TR_C_XL_GY_DRDY;
  6064. break;
  6065. case LSM6DS3TR_C_EXT_ON_INT2_PIN:
  6066. *val = LSM6DS3TR_C_EXT_ON_INT2_PIN;
  6067. break;
  6068. default:
  6069. *val = LSM6DS3TR_C_SH_SYNCRO_ND;
  6070. break;
  6071. }
  6072. return ret;
  6073. }
  6074. /**
  6075. * @brief Manage the Master DRDY signal on INT1 pad.[set]
  6076. *
  6077. * @param ctx Read / write interface definitions
  6078. * @param val Change the values of drdy_on_int1 in reg MASTER_CONFIG
  6079. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6080. *
  6081. */
  6082. int32_t lsm6ds3tr_c_sh_drdy_on_int1_set(stmdev_ctx_t *ctx,
  6083. uint8_t val)
  6084. {
  6085. lsm6ds3tr_c_master_config_t master_config;
  6086. int32_t ret;
  6087. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  6088. (uint8_t *)&master_config, 1);
  6089. if (ret == 0)
  6090. {
  6091. master_config.drdy_on_int1 = val;
  6092. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  6093. (uint8_t *)&master_config, 1);
  6094. }
  6095. return ret;
  6096. }
  6097. /**
  6098. * @brief Manage the Master DRDY signal on INT1 pad.[get]
  6099. *
  6100. * @param ctx Read / write interface definitions
  6101. * @param val Change the values of drdy_on_int1 in reg MASTER_CONFIG
  6102. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6103. *
  6104. */
  6105. int32_t lsm6ds3tr_c_sh_drdy_on_int1_get(stmdev_ctx_t *ctx,
  6106. uint8_t *val)
  6107. {
  6108. lsm6ds3tr_c_master_config_t master_config;
  6109. int32_t ret;
  6110. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CONFIG,
  6111. (uint8_t *)&master_config, 1);
  6112. *val = master_config.drdy_on_int1;
  6113. return ret;
  6114. }
  6115. /**
  6116. * @brief Sensor hub output registers.[get]
  6117. *
  6118. * @param ctx Read / write interface definitions
  6119. * @param val Structure of registers from SENSORHUB1_REG
  6120. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6121. *
  6122. */
  6123. int32_t lsm6ds3tr_c_sh_read_data_raw_get(stmdev_ctx_t *ctx,
  6124. lsm6ds3tr_c_emb_sh_read_t *val)
  6125. {
  6126. int32_t ret;
  6127. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SENSORHUB1_REG,
  6128. (uint8_t *) & (val->sh_byte_1), 12);
  6129. if (ret == 0)
  6130. {
  6131. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SENSORHUB13_REG,
  6132. (uint8_t *) & (val->sh_byte_13), 6);
  6133. }
  6134. return ret;
  6135. }
  6136. /**
  6137. * @brief Master command code used for stamping for sensor sync.[set]
  6138. *
  6139. * @param ctx Read / write interface definitions
  6140. * @param val Change the values of master_cmd_code in
  6141. * reg MASTER_CMD_CODE
  6142. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6143. *
  6144. */
  6145. int32_t lsm6ds3tr_c_sh_cmd_sens_sync_set(stmdev_ctx_t *ctx,
  6146. uint8_t val)
  6147. {
  6148. lsm6ds3tr_c_master_cmd_code_t master_cmd_code;
  6149. int32_t ret;
  6150. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CMD_CODE,
  6151. (uint8_t *)&master_cmd_code, 1);
  6152. if (ret == 0)
  6153. {
  6154. master_cmd_code.master_cmd_code = val;
  6155. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_MASTER_CMD_CODE,
  6156. (uint8_t *)&master_cmd_code, 1);
  6157. }
  6158. return ret;
  6159. }
  6160. /**
  6161. * @brief Master command code used for stamping for sensor sync.[get]
  6162. *
  6163. * @param ctx Read / write interface definitions
  6164. * @param val Change the values of master_cmd_code in
  6165. * reg MASTER_CMD_CODE
  6166. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6167. *
  6168. */
  6169. int32_t lsm6ds3tr_c_sh_cmd_sens_sync_get(stmdev_ctx_t *ctx,
  6170. uint8_t *val)
  6171. {
  6172. lsm6ds3tr_c_master_cmd_code_t master_cmd_code;
  6173. int32_t ret;
  6174. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_MASTER_CMD_CODE,
  6175. (uint8_t *)&master_cmd_code, 1);
  6176. *val = master_cmd_code.master_cmd_code;
  6177. return ret;
  6178. }
  6179. /**
  6180. * @brief Error code used for sensor synchronization.[set]
  6181. *
  6182. * @param ctx Read / write interface definitions
  6183. * @param val Change the values of error_code in
  6184. * reg SENS_SYNC_SPI_ERROR_CODE.
  6185. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6186. *
  6187. */
  6188. int32_t lsm6ds3tr_c_sh_spi_sync_error_set(stmdev_ctx_t *ctx,
  6189. uint8_t val)
  6190. {
  6191. lsm6ds3tr_c_sens_sync_spi_error_code_t sens_sync_spi_error_code;
  6192. int32_t ret;
  6193. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SENS_SYNC_SPI_ERROR_CODE,
  6194. (uint8_t *)&sens_sync_spi_error_code, 1);
  6195. if (ret == 0)
  6196. {
  6197. sens_sync_spi_error_code.error_code = val;
  6198. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SENS_SYNC_SPI_ERROR_CODE,
  6199. (uint8_t *)&sens_sync_spi_error_code, 1);
  6200. }
  6201. return ret;
  6202. }
  6203. /**
  6204. * @brief Error code used for sensor synchronization.[get]
  6205. *
  6206. * @param ctx Read / write interface definitions
  6207. * @param val Change the values of error_code in
  6208. * reg SENS_SYNC_SPI_ERROR_CODE.
  6209. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6210. *
  6211. */
  6212. int32_t lsm6ds3tr_c_sh_spi_sync_error_get(stmdev_ctx_t *ctx,
  6213. uint8_t *val)
  6214. {
  6215. lsm6ds3tr_c_sens_sync_spi_error_code_t sens_sync_spi_error_code;
  6216. int32_t ret;
  6217. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SENS_SYNC_SPI_ERROR_CODE,
  6218. (uint8_t *)&sens_sync_spi_error_code, 1);
  6219. *val = sens_sync_spi_error_code.error_code;
  6220. return ret;
  6221. }
  6222. /**
  6223. * @brief Number of external sensors to be read by the sensor hub.[set]
  6224. *
  6225. * @param ctx Read / write interface definitions
  6226. * @param val Change the values of aux_sens_on in reg SLAVE0_CONFIG.
  6227. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6228. *
  6229. */
  6230. int32_t lsm6ds3tr_c_sh_num_of_dev_connected_set(stmdev_ctx_t *ctx,
  6231. lsm6ds3tr_c_aux_sens_on_t val)
  6232. {
  6233. lsm6ds3tr_c_slave0_config_t slave0_config;
  6234. int32_t ret;
  6235. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6236. if (ret == 0)
  6237. {
  6238. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE0_CONFIG,
  6239. (uint8_t *)&slave0_config, 1);
  6240. if (ret == 0)
  6241. {
  6242. slave0_config.aux_sens_on = (uint8_t) val;
  6243. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLAVE0_CONFIG,
  6244. (uint8_t *)&slave0_config, 1);
  6245. if (ret == 0)
  6246. {
  6247. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6248. }
  6249. }
  6250. }
  6251. return ret;
  6252. }
  6253. /**
  6254. * @brief Number of external sensors to be read by the sensor hub.[get]
  6255. *
  6256. * @param ctx Read / write interface definitions
  6257. * @param val Get the values of aux_sens_on in reg SLAVE0_CONFIG.
  6258. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6259. *
  6260. */
  6261. int32_t lsm6ds3tr_c_sh_num_of_dev_connected_get(stmdev_ctx_t *ctx,
  6262. lsm6ds3tr_c_aux_sens_on_t *val)
  6263. {
  6264. lsm6ds3tr_c_slave0_config_t slave0_config;
  6265. int32_t ret;
  6266. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6267. if (ret == 0)
  6268. {
  6269. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE0_CONFIG,
  6270. (uint8_t *)&slave0_config, 1);
  6271. if (ret == 0)
  6272. {
  6273. switch (slave0_config.aux_sens_on)
  6274. {
  6275. case LSM6DS3TR_C_SLV_0:
  6276. *val = LSM6DS3TR_C_SLV_0;
  6277. break;
  6278. case LSM6DS3TR_C_SLV_0_1:
  6279. *val = LSM6DS3TR_C_SLV_0_1;
  6280. break;
  6281. case LSM6DS3TR_C_SLV_0_1_2:
  6282. *val = LSM6DS3TR_C_SLV_0_1_2;
  6283. break;
  6284. case LSM6DS3TR_C_SLV_0_1_2_3:
  6285. *val = LSM6DS3TR_C_SLV_0_1_2_3;
  6286. break;
  6287. default:
  6288. *val = LSM6DS3TR_C_SLV_EN_ND;
  6289. break;
  6290. }
  6291. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6292. }
  6293. }
  6294. return ret;
  6295. }
  6296. /**
  6297. * @brief Configure slave 0 for perform a write.[set]
  6298. *
  6299. * @param ctx Read / write interface definitions
  6300. * @param val Structure that contain:
  6301. * - uint8_t slv_add; 8 bit i2c device address
  6302. * - uint8_t slv_subadd; 8 bit register device address
  6303. * - uint8_t slv_data; 8 bit data to write
  6304. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6305. *
  6306. */
  6307. int32_t lsm6ds3tr_c_sh_cfg_write(stmdev_ctx_t *ctx,
  6308. lsm6ds3tr_c_sh_cfg_write_t *val)
  6309. {
  6310. lsm6ds3tr_c_slv0_add_t slv0_add;
  6311. int32_t ret;
  6312. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6313. if (ret == 0)
  6314. {
  6315. slv0_add.slave0_add = val->slv0_add;
  6316. slv0_add.rw_0 = 0;
  6317. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLV0_ADD,
  6318. (uint8_t *)&slv0_add, 1);
  6319. if (ret == 0)
  6320. {
  6321. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLV0_SUBADD,
  6322. &(val->slv0_subadd), 1);
  6323. if (ret == 0)
  6324. {
  6325. ret = lsm6ds3tr_c_write_reg(ctx,
  6326. LSM6DS3TR_C_DATAWRITE_SRC_MODE_SUB_SLV0,
  6327. &(val->slv0_data), 1);
  6328. if (ret == 0)
  6329. {
  6330. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6331. }
  6332. }
  6333. }
  6334. }
  6335. return ret;
  6336. }
  6337. /**
  6338. * @brief Configure slave 0 for perform a read.[get]
  6339. *
  6340. * @param ctx Read / write interface definitions
  6341. * @param val Structure that contain:
  6342. * - uint8_t slv_add; 8 bit i2c device address
  6343. * - uint8_t slv_subadd; 8 bit register device address
  6344. * - uint8_t slv_len; num of bit to read
  6345. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6346. *
  6347. */
  6348. int32_t lsm6ds3tr_c_sh_slv0_cfg_read(stmdev_ctx_t *ctx,
  6349. lsm6ds3tr_c_sh_cfg_read_t *val)
  6350. {
  6351. lsm6ds3tr_c_slave0_config_t slave0_config;
  6352. lsm6ds3tr_c_slv0_add_t slv0_add;
  6353. int32_t ret;
  6354. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6355. if (ret == 0)
  6356. {
  6357. slv0_add.slave0_add = val->slv_add;
  6358. slv0_add.rw_0 = 1;
  6359. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLV0_ADD,
  6360. (uint8_t *)&slv0_add, 1);
  6361. if (ret == 0)
  6362. {
  6363. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLV0_SUBADD,
  6364. &(val->slv_subadd), 1);
  6365. if (ret == 0)
  6366. {
  6367. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE0_CONFIG,
  6368. (uint8_t *)&slave0_config, 1);
  6369. slave0_config.slave0_numop = val->slv_len;
  6370. if (ret == 0)
  6371. {
  6372. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLAVE0_CONFIG,
  6373. (uint8_t *)&slave0_config, 1);
  6374. if (ret == 0)
  6375. {
  6376. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6377. }
  6378. }
  6379. }
  6380. }
  6381. }
  6382. return ret;
  6383. }
  6384. /**
  6385. * @brief Configure slave 1 for perform a read.[get]
  6386. *
  6387. * @param ctx Read / write interface definitions
  6388. * @param val Structure that contain:
  6389. * - uint8_t slv_add; 8 bit i2c device address
  6390. * - uint8_t slv_subadd; 8 bit register device address
  6391. * - uint8_t slv_len; num of bit to read
  6392. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6393. *
  6394. */
  6395. int32_t lsm6ds3tr_c_sh_slv1_cfg_read(stmdev_ctx_t *ctx,
  6396. lsm6ds3tr_c_sh_cfg_read_t *val)
  6397. {
  6398. lsm6ds3tr_c_slave1_config_t slave1_config;
  6399. lsm6ds3tr_c_slv1_add_t slv1_add;
  6400. int32_t ret;
  6401. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6402. if (ret == 0)
  6403. {
  6404. slv1_add.slave1_add = val->slv_add;
  6405. slv1_add.r_1 = 1;
  6406. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLV1_ADD,
  6407. (uint8_t *)&slv1_add, 1);
  6408. if (ret == 0)
  6409. {
  6410. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLV1_SUBADD,
  6411. &(val->slv_subadd), 1);
  6412. if (ret == 0)
  6413. {
  6414. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE1_CONFIG,
  6415. (uint8_t *)&slave1_config, 1);
  6416. slave1_config.slave1_numop = val->slv_len;
  6417. if (ret == 0)
  6418. {
  6419. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLAVE1_CONFIG,
  6420. (uint8_t *)&slave1_config, 1);
  6421. if (ret == 0)
  6422. {
  6423. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6424. }
  6425. }
  6426. }
  6427. }
  6428. }
  6429. return ret;
  6430. }
  6431. /**
  6432. * @brief Configure slave 2 for perform a read.[get]
  6433. *
  6434. * @param ctx Read / write interface definitions
  6435. * @param val Structure that contain:
  6436. * - uint8_t slv_add; 8 bit i2c device address
  6437. * - uint8_t slv_subadd; 8 bit register device address
  6438. * - uint8_t slv_len; num of bit to read
  6439. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6440. *
  6441. */
  6442. int32_t lsm6ds3tr_c_sh_slv2_cfg_read(stmdev_ctx_t *ctx,
  6443. lsm6ds3tr_c_sh_cfg_read_t *val)
  6444. {
  6445. lsm6ds3tr_c_slv2_add_t slv2_add;
  6446. lsm6ds3tr_c_slave2_config_t slave2_config;
  6447. int32_t ret;
  6448. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6449. if (ret == 0)
  6450. {
  6451. slv2_add.slave2_add = val->slv_add;
  6452. slv2_add.r_2 = 1;
  6453. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLV2_ADD,
  6454. (uint8_t *)&slv2_add, 1);
  6455. if (ret == 0)
  6456. {
  6457. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLV2_SUBADD,
  6458. &(val->slv_subadd), 1);
  6459. if (ret == 0)
  6460. {
  6461. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE2_CONFIG,
  6462. (uint8_t *)&slave2_config, 1);
  6463. if (ret == 0)
  6464. {
  6465. slave2_config.slave2_numop = val->slv_len;
  6466. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLAVE2_CONFIG,
  6467. (uint8_t *)&slave2_config, 1);
  6468. if (ret == 0)
  6469. {
  6470. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6471. }
  6472. }
  6473. }
  6474. }
  6475. }
  6476. return ret;
  6477. }
  6478. /**
  6479. * @brief Configure slave 3 for perform a read.[get]
  6480. *
  6481. * @param ctx Read / write interface definitions
  6482. * @param val Structure that contain:
  6483. * - uint8_t slv_add; 8 bit i2c device address
  6484. * - uint8_t slv_subadd; 8 bit register device address
  6485. * - uint8_t slv_len; num of bit to read
  6486. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6487. *
  6488. */
  6489. int32_t lsm6ds3tr_c_sh_slv3_cfg_read(stmdev_ctx_t *ctx,
  6490. lsm6ds3tr_c_sh_cfg_read_t *val)
  6491. {
  6492. lsm6ds3tr_c_slave3_config_t slave3_config;
  6493. lsm6ds3tr_c_slv3_add_t slv3_add;
  6494. int32_t ret;
  6495. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6496. if (ret == 0)
  6497. {
  6498. slv3_add.slave3_add = val->slv_add;
  6499. slv3_add.r_3 = 1;
  6500. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLV3_ADD,
  6501. (uint8_t *)&slv3_add, 1);
  6502. if (ret == 0)
  6503. {
  6504. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLV3_SUBADD,
  6505. (uint8_t *) & (val->slv_subadd), 1);
  6506. if (ret == 0)
  6507. {
  6508. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE3_CONFIG,
  6509. (uint8_t *)&slave3_config, 1);
  6510. if (ret == 0)
  6511. {
  6512. slave3_config.slave3_numop = val->slv_len;
  6513. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLAVE3_CONFIG,
  6514. (uint8_t *)&slave3_config, 1);
  6515. if (ret == 0)
  6516. {
  6517. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6518. }
  6519. }
  6520. }
  6521. }
  6522. }
  6523. return ret;
  6524. }
  6525. /**
  6526. * @brief Decimation of read operation on Slave 0 starting from the
  6527. * sensor hub trigger.[set]
  6528. *
  6529. * @param ctx Read / write interface definitions
  6530. * @param val Change the values of slave0_rate in reg SLAVE0_CONFIG
  6531. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6532. *
  6533. */
  6534. int32_t lsm6ds3tr_c_sh_slave_0_dec_set(stmdev_ctx_t *ctx,
  6535. lsm6ds3tr_c_slave0_rate_t val)
  6536. {
  6537. lsm6ds3tr_c_slave0_config_t slave0_config;
  6538. int32_t ret;
  6539. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6540. if (ret == 0)
  6541. {
  6542. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE0_CONFIG,
  6543. (uint8_t *)&slave0_config, 1);
  6544. if (ret == 0)
  6545. {
  6546. slave0_config.slave0_rate = (uint8_t) val;
  6547. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLAVE0_CONFIG,
  6548. (uint8_t *)&slave0_config, 1);
  6549. if (ret == 0)
  6550. {
  6551. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6552. }
  6553. }
  6554. }
  6555. return ret;
  6556. }
  6557. /**
  6558. * @brief Decimation of read operation on Slave 0 starting from the
  6559. * sensor hub trigger.[get]
  6560. *
  6561. * @param ctx Read / write interface definitions
  6562. * @param val Get the values of slave0_rate in reg SLAVE0_CONFIG
  6563. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6564. *
  6565. */
  6566. int32_t lsm6ds3tr_c_sh_slave_0_dec_get(stmdev_ctx_t *ctx,
  6567. lsm6ds3tr_c_slave0_rate_t *val)
  6568. {
  6569. lsm6ds3tr_c_slave0_config_t slave0_config;
  6570. int32_t ret;
  6571. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6572. if (ret == 0)
  6573. {
  6574. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE0_CONFIG,
  6575. (uint8_t *)&slave0_config, 1);
  6576. if (ret == 0)
  6577. {
  6578. switch (slave0_config.slave0_rate)
  6579. {
  6580. case LSM6DS3TR_C_SL0_NO_DEC:
  6581. *val = LSM6DS3TR_C_SL0_NO_DEC;
  6582. break;
  6583. case LSM6DS3TR_C_SL0_DEC_2:
  6584. *val = LSM6DS3TR_C_SL0_DEC_2;
  6585. break;
  6586. case LSM6DS3TR_C_SL0_DEC_4:
  6587. *val = LSM6DS3TR_C_SL0_DEC_4;
  6588. break;
  6589. case LSM6DS3TR_C_SL0_DEC_8:
  6590. *val = LSM6DS3TR_C_SL0_DEC_8;
  6591. break;
  6592. default:
  6593. *val = LSM6DS3TR_C_SL0_DEC_ND;
  6594. break;
  6595. }
  6596. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6597. }
  6598. }
  6599. return ret;
  6600. }
  6601. /**
  6602. * @brief Slave 0 write operation is performed only at the first sensor
  6603. * hub cycle.
  6604. * This is effective if the Aux_sens_on[1:0] field in
  6605. * SLAVE0_CONFIG(04h) is set to a value other than 00.[set]
  6606. *
  6607. * @param ctx Read / write interface definitions
  6608. * @param val Change the values of write_once in reg SLAVE1_CONFIG
  6609. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6610. *
  6611. */
  6612. int32_t lsm6ds3tr_c_sh_write_mode_set(stmdev_ctx_t *ctx,
  6613. lsm6ds3tr_c_write_once_t val)
  6614. {
  6615. lsm6ds3tr_c_slave1_config_t slave1_config;
  6616. int32_t ret;
  6617. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6618. if (ret == 0)
  6619. {
  6620. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE1_CONFIG,
  6621. (uint8_t *)&slave1_config, 1);
  6622. slave1_config.write_once = (uint8_t) val;
  6623. if (ret == 0)
  6624. {
  6625. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLAVE1_CONFIG,
  6626. (uint8_t *)&slave1_config, 1);
  6627. if (ret == 0)
  6628. {
  6629. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6630. }
  6631. }
  6632. }
  6633. return ret;
  6634. }
  6635. /**
  6636. * @brief Slave 0 write operation is performed only at the first sensor
  6637. * hub cycle.
  6638. * This is effective if the Aux_sens_on[1:0] field in
  6639. * SLAVE0_CONFIG(04h) is set to a value other than 00.[get]
  6640. *
  6641. * @param ctx Read / write interface definitions
  6642. * @param val Get the values of write_once in reg SLAVE1_CONFIG
  6643. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6644. *
  6645. */
  6646. int32_t lsm6ds3tr_c_sh_write_mode_get(stmdev_ctx_t *ctx,
  6647. lsm6ds3tr_c_write_once_t *val)
  6648. {
  6649. lsm6ds3tr_c_slave1_config_t slave1_config;
  6650. int32_t ret;
  6651. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6652. if (ret == 0)
  6653. {
  6654. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE1_CONFIG,
  6655. (uint8_t *)&slave1_config, 1);
  6656. if (ret == 0)
  6657. {
  6658. switch (slave1_config.write_once)
  6659. {
  6660. case LSM6DS3TR_C_EACH_SH_CYCLE:
  6661. *val = LSM6DS3TR_C_EACH_SH_CYCLE;
  6662. break;
  6663. case LSM6DS3TR_C_ONLY_FIRST_CYCLE:
  6664. *val = LSM6DS3TR_C_ONLY_FIRST_CYCLE;
  6665. break;
  6666. default:
  6667. *val = LSM6DS3TR_C_SH_WR_MODE_ND;
  6668. break;
  6669. }
  6670. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6671. }
  6672. }
  6673. return ret;
  6674. }
  6675. /**
  6676. * @brief Decimation of read operation on Slave 1 starting from the
  6677. * sensor hub trigger.[set]
  6678. *
  6679. * @param ctx Read / write interface definitions
  6680. * @param val Change the values of slave1_rate in reg SLAVE1_CONFIG
  6681. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6682. *
  6683. */
  6684. int32_t lsm6ds3tr_c_sh_slave_1_dec_set(stmdev_ctx_t *ctx,
  6685. lsm6ds3tr_c_slave1_rate_t val)
  6686. {
  6687. lsm6ds3tr_c_slave1_config_t slave1_config;
  6688. int32_t ret;
  6689. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6690. if (ret == 0)
  6691. {
  6692. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE1_CONFIG,
  6693. (uint8_t *)&slave1_config, 1);
  6694. if (ret == 0)
  6695. {
  6696. slave1_config.slave1_rate = (uint8_t) val;
  6697. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLAVE1_CONFIG,
  6698. (uint8_t *)&slave1_config, 1);
  6699. if (ret == 0)
  6700. {
  6701. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6702. }
  6703. }
  6704. }
  6705. return ret;
  6706. }
  6707. /**
  6708. * @brief Decimation of read operation on Slave 1 starting from the
  6709. * sensor hub trigger.[get]
  6710. *
  6711. * @param ctx Read / write interface definitions reg SLAVE1_CONFIG
  6712. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6713. *
  6714. */
  6715. int32_t lsm6ds3tr_c_sh_slave_1_dec_get(stmdev_ctx_t *ctx,
  6716. lsm6ds3tr_c_slave1_rate_t *val)
  6717. {
  6718. lsm6ds3tr_c_slave1_config_t slave1_config;
  6719. int32_t ret;
  6720. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6721. if (ret == 0)
  6722. {
  6723. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE1_CONFIG,
  6724. (uint8_t *)&slave1_config, 1);
  6725. if (ret == 0)
  6726. {
  6727. switch (slave1_config.slave1_rate)
  6728. {
  6729. case LSM6DS3TR_C_SL1_NO_DEC:
  6730. *val = LSM6DS3TR_C_SL1_NO_DEC;
  6731. break;
  6732. case LSM6DS3TR_C_SL1_DEC_2:
  6733. *val = LSM6DS3TR_C_SL1_DEC_2;
  6734. break;
  6735. case LSM6DS3TR_C_SL1_DEC_4:
  6736. *val = LSM6DS3TR_C_SL1_DEC_4;
  6737. break;
  6738. case LSM6DS3TR_C_SL1_DEC_8:
  6739. *val = LSM6DS3TR_C_SL1_DEC_8;
  6740. break;
  6741. default:
  6742. *val = LSM6DS3TR_C_SL1_DEC_ND;
  6743. break;
  6744. }
  6745. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6746. }
  6747. }
  6748. return ret;
  6749. }
  6750. /**
  6751. * @brief Decimation of read operation on Slave 2 starting from the
  6752. * sensor hub trigger.[set]
  6753. *
  6754. * @param ctx Read / write interface definitions
  6755. * @param val Change the values of slave2_rate in reg SLAVE2_CONFIG
  6756. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6757. *
  6758. */
  6759. int32_t lsm6ds3tr_c_sh_slave_2_dec_set(stmdev_ctx_t *ctx,
  6760. lsm6ds3tr_c_slave2_rate_t val)
  6761. {
  6762. lsm6ds3tr_c_slave2_config_t slave2_config;
  6763. int32_t ret;
  6764. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6765. if (ret == 0)
  6766. {
  6767. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE2_CONFIG,
  6768. (uint8_t *)&slave2_config, 1);
  6769. if (ret == 0)
  6770. {
  6771. slave2_config.slave2_rate = (uint8_t) val;
  6772. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLAVE2_CONFIG,
  6773. (uint8_t *)&slave2_config, 1);
  6774. if (ret == 0)
  6775. {
  6776. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6777. }
  6778. }
  6779. }
  6780. return ret;
  6781. }
  6782. /**
  6783. * @brief Decimation of read operation on Slave 2 starting from the
  6784. * sensor hub trigger.[get]
  6785. *
  6786. * @param ctx Read / write interface definitions
  6787. * @param val Get the values of slave2_rate in reg SLAVE2_CONFIG
  6788. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6789. *
  6790. */
  6791. int32_t lsm6ds3tr_c_sh_slave_2_dec_get(stmdev_ctx_t *ctx,
  6792. lsm6ds3tr_c_slave2_rate_t *val)
  6793. {
  6794. lsm6ds3tr_c_slave2_config_t slave2_config;
  6795. int32_t ret;
  6796. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6797. if (ret == 0)
  6798. {
  6799. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE2_CONFIG,
  6800. (uint8_t *)&slave2_config, 1);
  6801. if (ret == 0)
  6802. {
  6803. switch (slave2_config.slave2_rate)
  6804. {
  6805. case LSM6DS3TR_C_SL2_NO_DEC:
  6806. *val = LSM6DS3TR_C_SL2_NO_DEC;
  6807. break;
  6808. case LSM6DS3TR_C_SL2_DEC_2:
  6809. *val = LSM6DS3TR_C_SL2_DEC_2;
  6810. break;
  6811. case LSM6DS3TR_C_SL2_DEC_4:
  6812. *val = LSM6DS3TR_C_SL2_DEC_4;
  6813. break;
  6814. case LSM6DS3TR_C_SL2_DEC_8:
  6815. *val = LSM6DS3TR_C_SL2_DEC_8;
  6816. break;
  6817. default:
  6818. *val = LSM6DS3TR_C_SL2_DEC_ND;
  6819. break;
  6820. }
  6821. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6822. }
  6823. }
  6824. return ret;
  6825. }
  6826. /**
  6827. * @brief Decimation of read operation on Slave 3 starting from the
  6828. * sensor hub trigger.[set]
  6829. *
  6830. * @param ctx Read / write interface definitions
  6831. * @param val Change the values of slave3_rate in reg SLAVE3_CONFIG
  6832. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6833. *
  6834. */
  6835. int32_t lsm6ds3tr_c_sh_slave_3_dec_set(stmdev_ctx_t *ctx,
  6836. lsm6ds3tr_c_slave3_rate_t val)
  6837. {
  6838. lsm6ds3tr_c_slave3_config_t slave3_config;
  6839. int32_t ret;
  6840. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6841. if (ret == 0)
  6842. {
  6843. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE3_CONFIG,
  6844. (uint8_t *)&slave3_config, 1);
  6845. slave3_config.slave3_rate = (uint8_t)val;
  6846. if (ret == 0)
  6847. {
  6848. ret = lsm6ds3tr_c_write_reg(ctx, LSM6DS3TR_C_SLAVE3_CONFIG,
  6849. (uint8_t *)&slave3_config, 1);
  6850. if (ret == 0)
  6851. {
  6852. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6853. }
  6854. }
  6855. }
  6856. return ret;
  6857. }
  6858. /**
  6859. * @brief Decimation of read operation on Slave 3 starting from the
  6860. * sensor hub trigger.[get]
  6861. *
  6862. * @param ctx Read / write interface definitions
  6863. * @param val Get the values of slave3_rate in reg SLAVE3_CONFIG.
  6864. * @retval Interface status (MANDATORY: return 0 -> no Error).
  6865. *
  6866. */
  6867. int32_t lsm6ds3tr_c_sh_slave_3_dec_get(stmdev_ctx_t *ctx,
  6868. lsm6ds3tr_c_slave3_rate_t *val)
  6869. {
  6870. lsm6ds3tr_c_slave3_config_t slave3_config;
  6871. int32_t ret;
  6872. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_BANK_A);
  6873. if (ret == 0)
  6874. {
  6875. ret = lsm6ds3tr_c_read_reg(ctx, LSM6DS3TR_C_SLAVE3_CONFIG,
  6876. (uint8_t *)&slave3_config, 1);
  6877. if (ret == 0)
  6878. {
  6879. switch (slave3_config.slave3_rate)
  6880. {
  6881. case LSM6DS3TR_C_SL3_NO_DEC:
  6882. *val = LSM6DS3TR_C_SL3_NO_DEC;
  6883. break;
  6884. case LSM6DS3TR_C_SL3_DEC_2:
  6885. *val = LSM6DS3TR_C_SL3_DEC_2;
  6886. break;
  6887. case LSM6DS3TR_C_SL3_DEC_4:
  6888. *val = LSM6DS3TR_C_SL3_DEC_4;
  6889. break;
  6890. case LSM6DS3TR_C_SL3_DEC_8:
  6891. *val = LSM6DS3TR_C_SL3_DEC_8;
  6892. break;
  6893. default:
  6894. *val = LSM6DS3TR_C_SL3_DEC_ND;
  6895. break;
  6896. }
  6897. ret = lsm6ds3tr_c_mem_bank_set(ctx, LSM6DS3TR_C_USER_BANK);
  6898. }
  6899. }
  6900. return ret;
  6901. }
  6902. /**
  6903. * @}
  6904. *
  6905. */
  6906. /**
  6907. * @}
  6908. *
  6909. */
  6910. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/